OSDN Git Service

remove Revision tag
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / birthmarks / ASMBirthmarkExtractor.java
1 package jp.sourceforge.stigmata.birthmarks;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.IOException;
8 import java.io.InputStream;
9
10 import jp.sourceforge.stigmata.Birthmark;
11 import jp.sourceforge.stigmata.BirthmarkContext;
12 import jp.sourceforge.stigmata.BirthmarkExtractionFailedException;
13 import jp.sourceforge.stigmata.spi.BirthmarkSpi;
14
15 import org.objectweb.asm.ClassReader;
16 import org.objectweb.asm.ClassWriter;
17
18 /**
19  * Abstract birthmark extractor using ASM.
20  *
21  * @author Haruaki TAMADA
22  */
23 public abstract class ASMBirthmarkExtractor extends AbstractBirthmarkExtractor{
24     public ASMBirthmarkExtractor(BirthmarkSpi spi){
25         super(spi);
26     }
27
28     @SuppressWarnings("deprecation")
29     public ASMBirthmarkExtractor(){
30         super();
31     }
32
33     public abstract BirthmarkExtractVisitor
34         createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context);
35
36     @Override
37     public Birthmark extract(Birthmark birthmark, InputStream in,
38             BirthmarkContext context) throws BirthmarkExtractionFailedException{
39         BirthmarkExtractionFailedException bee = new BirthmarkExtractionFailedException();
40
41         try{
42             ClassReader reader = new ClassReader(in);
43             ClassWriter writer = new ClassWriter(0);
44             BirthmarkExtractVisitor visitor = createExtractVisitor(writer, birthmark, context);
45             reader.accept(visitor, 0);
46
47             if(!visitor.isSuccess()){
48                 bee.addCauses(visitor.getCauses());
49             }
50
51             return visitor.getBirthmark();
52         } catch(IOException e){
53             bee.addCause(e);
54             throw bee;
55         }
56     }
57 }