OSDN Git Service

Spiという名前をすべてServiceに変更した.
[stigmata/stigmata-core.git] / src / main / java / jp / sourceforge / stigmata / BirthmarkEngine.java
index 9f5ab1f..2e01d89 100644 (file)
@@ -14,7 +14,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
 
-import jp.sourceforge.stigmata.birthmarks.extractors.BirthmarkExtractorFactory;
 import jp.sourceforge.stigmata.digger.ClassFileArchive;
 import jp.sourceforge.stigmata.digger.ClassFileEntry;
 import jp.sourceforge.stigmata.digger.ClasspathContext;
@@ -48,14 +47,12 @@ public class BirthmarkEngine{
     private WarningMessages warnings;
     private OperationType latestOperationType;
     private OperationType targetType;
-    private BirthmarkExtractorFactory factory;
 
     /**
      * constructor.
      */
     public BirthmarkEngine(BirthmarkEnvironment env){
         this.environment = env;
-        factory = new BirthmarkExtractorFactory(env);
     }
 
     /**
@@ -352,18 +349,15 @@ public class BirthmarkEngine{
 
                     byte[] data = inputStreamToByteArray(entry.getLocation().openStream());
                     for(String birthmarkType: context.getBirthmarkTypes()){
-                        try{
-                            BirthmarkExtractor extractor = factory.getExtractor(birthmarkType);
-                            if(extractor.isAcceptable(ExtractionUnit.PACKAGE)){
-                                Birthmark b = bs.getBirthmark(extractor.getProvider().getType());
-                                if(b == null){
-                                    b = extractor.createBirthmark();
-                                    bs.addBirthmark(b);
-                                }
-                                extractor.extract(b, new ByteArrayInputStream(data), er.getContext());
+                        BirthmarkService service = getEnvironment().getService(birthmarkType);
+                        BirthmarkExtractor extractor = service.getExtractor();
+                        if(extractor.isAcceptable(ExtractionUnit.PACKAGE)){
+                            Birthmark b = bs.getBirthmark(extractor.getProvider().getType());
+                            if(b == null){
+                                b = extractor.createBirthmark();
+                                bs.addBirthmark(b);
                             }
-                        } catch(ExtractorNotFoundException e){
-                            warnings.addMessage(e, birthmarkType);
+                            extractor.extract(b, new ByteArrayInputStream(data), er.getContext());
                         }
                     }
                 } catch(IOException e){
@@ -400,14 +394,11 @@ public class BirthmarkEngine{
                     byte[] data = inputStreamToByteArray(entry.getLocation().openStream());
 
                     for(String birthmarkType: context.getBirthmarkTypes()){
-                        try{
-                            BirthmarkExtractor extractor = factory.getExtractor(birthmarkType);
-                            if(extractor.isAcceptable(ExtractionUnit.CLASS)){
-                                Birthmark b = extractor.extract(new ByteArrayInputStream(data), er.getContext());
-                                birthmarkset.addBirthmark(b);
-                            }
-                        } catch(ExtractorNotFoundException e){
-                            warnings.addMessage(e, birthmarkType);
+                        BirthmarkService service = getEnvironment().getService(birthmarkType);
+                        BirthmarkExtractor extractor = service.getExtractor();
+                        if(extractor.isAcceptable(ExtractionUnit.CLASS)){
+                            Birthmark b = extractor.extract(new ByteArrayInputStream(data), er.getContext());
+                            birthmarkset.addBirthmark(b);
                         }
                     }
                     er.addBirthmarkSet(et, birthmarkset);
@@ -428,19 +419,16 @@ public class BirthmarkEngine{
                 try{
                     byte[] data = inputStreamToByteArray(entry.getLocation().openStream());
                     for(String birthmarkType: context.getBirthmarkTypes()){
-                        try{
-                            BirthmarkExtractor extractor = factory.getExtractor(birthmarkType);
-                            if(extractor.isAcceptable(ExtractionUnit.ARCHIVE)){
-                                Birthmark b = birthmarkset.getBirthmark(birthmarkType);
-                                if(b == null){
-                                    b = extractor.createBirthmark();
-                                    birthmarkset.addBirthmark(b);
-                                }
-                                extractor.extract(b, new ByteArrayInputStream(data), er.getContext());
+                        BirthmarkService service = getEnvironment().getService(birthmarkType);
+                        BirthmarkExtractor extractor = service.getExtractor();
+                        if(extractor.isAcceptable(ExtractionUnit.ARCHIVE)){
+                            Birthmark b = birthmarkset.getBirthmark(birthmarkType);
+                            if(b == null){
+                                b = extractor.createBirthmark();
+                                birthmarkset.addBirthmark(b);
                             }
-                        } catch(ExtractorNotFoundException e){
-                            warnings.addMessage(e, birthmarkType);
-                        } 
+                            extractor.extract(b, new ByteArrayInputStream(data), er.getContext());
+                        }
                     }
                 } catch(IOException e){
                     warnings.addMessage(e, entry.getClassName());