KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > javaguard > classfile > ConstantValueAttrInfo


1 /**
2  * JavaGuard -- an obfuscation package for Java classfiles.
3  *
4  * Copyright (c) 1999 Mark Welsh (markw@retrologic.com)
5  * Copyright (c) 2002 Thorsten Heit (theit@gmx.de)
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * The author may be contacted at theit@gmx.de.
22  *
23  *
24  * $Id: ConstantValueAttrInfo.java,v 1.2 2002/05/08 11:53:42 glurk Exp $
25  */

26 package net.sf.javaguard.classfile;
27
28 import java.io.*;
29
30
31 /** Representation of an attribute.
32  *
33  * @author <a HREF="mailto:theit@gmx.de">Thorsten Heit</a>
34  * @author <a HREF="mailto:markw@retrologic.com">Mark Welsh</a>
35  */

36 public class ConstantValueAttrInfo extends AttrInfo {
37   /** Holds the constant value index. */
38   private int constantValueIndex;
39   
40   
41   
42   
43   /** Default constructor that creates a ConstantValueAttrInfo object.
44    * @param cf the class file the object belongs to
45    * @param attrNameIndex index into the constant pool
46    * @param attrLength the length of the additional info data in the class file
47    */

48   protected ConstantValueAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) {
49     super(cf, attrNameIndex, attrLength);
50   }
51   
52   
53   
54   
55   /** Return the string name of the attribute.
56    * @return string name of the attribute
57    */

58   protected String JavaDoc getAttrName() {
59     return ATTR_ConstantValue;
60   }
61   
62   
63   
64   
65   /** Sets the constant value index.
66    * @param index the constant value index
67    * @see #getConstantValueIndex
68    */

69   protected void setConstantValueIndex(int index) {
70     this.constantValueIndex = index;
71   }
72   
73   
74   /** Returns the constant value index.
75    * @return constant value index
76    * @see #setConstantValueIndex
77    */

78   protected int getConstantValueIndex() {
79     return constantValueIndex;
80   }
81   
82   
83   
84   
85   /** Read the data following the header.
86    * @param din the input stream
87    * @throws IOException if an I/O error occurs
88    */

89   protected void readInfo(DataInput din)
90   throws IOException {
91     setConstantValueIndex(din.readUnsignedShort());
92   }
93   
94   
95   /** Export data following the header to a DataOutput stream. Should be
96    * overwritten in subclasses.
97    * @param dout the output stream
98    * @throws IOException if an I/O error occurs
99    */

100   public void writeInfo(DataOutput dout)
101   throws IOException {
102     dout.writeShort(getConstantValueIndex());
103   }
104   
105   
106   
107   
108   /** Dump the content of the entry to the specified file (used for debugging).
109    * @param pw the print writer
110    * @param cf the class file the element belongs to
111    */

112   public void dump(PrintWriter pw, ClassFile cf) {
113     pw.println(getAttrName());
114     pw.print("constant value index: ");
115     pw.println(getConstantValueIndex());
116   }
117 }
118
Popular Tags