KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > yworks > yguard > obf > classfile > ElementValueInfo


1 /*
2  * ElementValueInfo.java
3  *
4  * Created on April 20, 2005, 4:19 PM
5  */

6
7 package com.yworks.yguard.obf.classfile;
8
9 import com.yworks.yguard.ParseException;
10 import java.io.DataInput JavaDoc;
11 import java.io.DataOutput JavaDoc;
12 import java.io.IOException JavaDoc;
13
14 public class ElementValueInfo
15 {
16   protected int u1Tag;
17   protected int u2cpIndex;
18   
19   protected int u2typeNameIndex;
20   protected int u2constNameIndex;
21   protected AnnotationInfo nestedAnnotation;
22   protected ElementValueInfo[] arrayValues;
23   
24   private ElementValueInfo()
25   {}
26   
27   public static ElementValueInfo create(DataInput JavaDoc din) throws IOException JavaDoc
28   {
29     ElementValueInfo evp = new ElementValueInfo();
30     evp.read(din);
31     return evp;
32   }
33   
34   protected void read(DataInput JavaDoc din) throws java.io.IOException JavaDoc
35   {
36     u1Tag = din.readUnsignedByte();
37     switch (u1Tag)
38     {
39       case 'B':
40       case 'C':
41       case 'D':
42       case 'F':
43       case 'I':
44       case 'J':
45       case 'S':
46       case 'Z':
47       case 's':
48         u2cpIndex = din.readUnsignedShort();
49         break;
50       case 'e':
51         u2typeNameIndex = din.readUnsignedShort();
52         u2constNameIndex = din.readUnsignedShort();
53         break;
54       case 'c':
55         u2cpIndex = din.readUnsignedShort();
56         break;
57       case '@':
58         nestedAnnotation = AnnotationInfo.create(din);
59         break;
60       case '[':
61         int count = din.readUnsignedShort();
62         arrayValues = new ElementValueInfo[count];
63         for (int i = 0; i < count; i++)
64         {
65           arrayValues[i] = ElementValueInfo.create(din);
66         }
67         break;
68       default:
69         throw new ParseException("Unkown tag type in ElementValuePair: " + u1Tag);
70     }
71   }
72
73   protected void markUtf8RefsInInfo(ConstantPool pool) {
74     switch (u1Tag)
75     {
76       case 'B':
77       case 'C':
78       case 'D':
79       case 'F':
80       case 'I':
81       case 'J':
82       case 'S':
83       case 'Z':
84       case 's':
85         pool.getCpEntry(u2cpIndex).incRefCount();
86         break;
87       case 'e':
88         pool.getCpEntry(u2typeNameIndex).incRefCount();
89         pool.getCpEntry(u2constNameIndex).incRefCount();
90         break;
91       case 'c':
92         pool.getCpEntry(u2cpIndex).incRefCount();
93         break;
94       case '@':
95         nestedAnnotation.markUtf8RefsInInfo(pool);
96         break;
97       case '[':
98         for (int i = 0; i < arrayValues.length; i++)
99         {
100           arrayValues[i].markUtf8RefsInInfo(pool);
101         }
102         break;
103     }
104   }
105   
106   /** Export the representation to a DataOutput stream. */
107   public void write(DataOutput JavaDoc dout) throws java.io.IOException JavaDoc
108   {
109     dout.writeByte(u1Tag);
110     switch (u1Tag)
111     {
112       case 'B':
113       case 'C':
114       case 'D':
115       case 'F':
116       case 'I':
117       case 'J':
118       case 'S':
119       case 'Z':
120       case 's':
121         dout.writeShort(u2cpIndex);
122         break;
123       case 'e':
124         dout.writeShort(u2typeNameIndex);
125         dout.writeShort(u2constNameIndex);
126         break;
127       case 'c':
128         dout.writeShort(u2cpIndex);
129         break;
130       case '@':
131         nestedAnnotation.write(dout);
132         break;
133       case '[':
134         int count = arrayValues.length;
135         dout.writeShort(count);
136         for (int i = 0; i < count; i++)
137         {
138           arrayValues[i].write(dout);
139         }
140         break;
141     }
142   }
143 }
144
Popular Tags