OSDN Git Service

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