OSDN Git Service

initial version (daily commit), not work yet
[stigmata/stigmata-plugins.git] / wsp / src / main / java / jp / sourceforge / stigmata / birthmarks / wsp / OpcodeManager.java
1 package jp.sourceforge.stigmata.birthmarks.wsp;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.BufferedReader;
8 import java.io.IOException;
9 import java.io.InputStreamReader;
10 import java.net.URL;
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import jp.sourceforge.talisman.csvio.CsvLine;
15 import jp.sourceforge.talisman.csvio.CsvParser;
16
17 /** 
18  * 
19  * @author Haruaki Tamada
20  * @version $Revision$
21  */
22 public class OpcodeManager{
23     private static final Map<Integer, Opcode> OPCODE_MAP = new HashMap<Integer, Opcode>();
24     private static OpcodeManager manager = new OpcodeManager();
25
26     static{
27         try{
28             URL location = StackPatternBasedBirthmarkExtractor.class.getResource("/META-INF/bytecode.def");
29             BufferedReader in = new BufferedReader(new InputStreamReader(location.openStream()));
30             CsvParser parser = new CsvParser(in);
31             while(parser.hasNext()){
32                 CsvLine line = parser.next();
33                 String[] values = line.getValues();
34                 if(values.length == 5){
35                     Opcode def = new Opcode(
36                         Integer.parseInt(values[0]), values[1],
37                         Integer.parseInt(values[2]),
38                         Integer.parseInt(values[3]), values[4]
39                     );
40                     OPCODE_MAP.put(def.getOpcode(), def);
41                 }
42             }
43         } catch(IOException e){
44             throw new InternalError(e.getMessage());
45         }
46     }
47
48     /**
49      * private constructor for singleton pattern.
50      */
51     private OpcodeManager(){
52     }
53
54     public static OpcodeManager getInstance(){
55         return manager;
56     }
57
58     public Opcode getOpcode(int opcode){
59         return OPCODE_MAP.get(opcode);
60     }
61 }