1 /
14
15 package attr;
16
17 import java.io.*;
18 import util.*;
19 import jconst.*;
20
21
22
36 public final class attrFactory {
37 static dataRead dataIn = new dataRead();
38
39 private attrFactory() {}
40
41 private static void skip_data(int len, DataInputStream dStream ) {
47 int junk;
48
49 for (int i = 0; i < len; i++) {
50 junk = dataIn.readU1( dStream );
51 }
52 }
54
55
64 public static attrInfo allocAttr( DataInputStream dStream,
65 constPool constPoolSec ) {
66 int name_index;
67 int length;
68 constBase obj;
69 constUtf8 name;
70 attrInfo retObj = null;
71
72 name_index = dataIn.readU2( dStream );
73 length = dataIn.readU4( dStream );
74
75 obj = constPoolSec.constPoolElem( name_index );
76 if (obj != null && obj instanceof constUtf8) {
77 String nameStr;
78
79 name = (constUtf8)obj;
80 nameStr = name.getString();
81
82 if (nameStr.compareTo( "SourceFile" ) == 0) {
83 retObj = new srcFileAttr( nameStr, length, dStream, constPoolSec );
84 } else if (nameStr.compareTo( "ConstantValue" ) == 0) {
85 retObj = new constValueAttr( nameStr, length, dStream, constPoolSec );
86 } else if (nameStr.compareTo( "Code" ) == 0) {
87 retObj = new codeAttr( nameStr, length, dStream, constPoolSec );
88 }
89 else if (nameStr.compareTo( "Exceptions" ) == 0) {
90 retObj = new exceptAttr( nameStr, length, dStream, constPoolSec );
91 }
92 else if (nameStr.compareTo( "InnerClasses" ) == 0) {
93 }
94 else if (nameStr.compareTo( "LineNumberTable" ) == 0) {
95 retObj = new lineNumTabAttr( nameStr, length, dStream );
96 }
97 else if (nameStr.compareTo( "LocalVariableTable" ) == 0) {
98 retObj = new localVarTabAttr( nameStr, length, dStream, constPoolSec );
99 }
100 else if (nameStr.compareTo( "Synthetic" ) == 0) {
101 retObj = new synthAttr( nameStr, length );
102 }
103 else if (nameStr.compareTo( "Deprecated" ) == 0) {
104 retObj = new deprecAttr( nameStr, length );
105 }
106 else {
107 skip_data( length, dStream );
109 }
110 }
111 else {
112 errorMessage.errorPrint("allocAttr: bad name index");
113 }
114
115 return retObj;
116 }
118 }