KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > ConstString


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * Class representing a class specification in the constant pool
31  */

32
33 /*
34    ConstString strictly speaking is not a ConstantValue in the
35    Java VM sense. However, the compiler generates ConstantValue attributes
36    which refer to ConstString entries. This occurs for initialized static
37    final String fields. I've changed ConstString to be a ConstValue for
38    now as a simplification.
39 */

40
41 public class ConstString extends ConstValue {
42   /* The tag associated with ConstClass entries */
43   public static final int MyTag = CONSTANTString;
44
45   /* The name of the class being referred to */
46   private ConstUtf8 stringValue;
47
48   /* The index of name of the class being referred to
49    * - used while reading from a class file */

50   private int stringValueIndex;
51
52   /* public accessors */
53
54   /**
55    * Return the tag for this constant
56    */

57   public int tag () { return MyTag; }
58
59   /**
60    * Return the utf8 string calue
61    */

62   public ConstUtf8 value() {
63     return stringValue;
64   }
65
66   /**
67    * Return the descriptor string for the constant type.
68    */

69   public String JavaDoc descriptor() {
70       return "Ljava/lang/String;";//NOI18N
71
}
72
73   /**
74    * A printable representation
75    */

76   public String JavaDoc toString () {
77       return "CONSTANTString(" + indexAsString() + "): " + //NOI18N
78
"string(" + stringValue.asString() + ")";//NOI18N
79
}
80
81   /* package local methods */
82
83   ConstString (ConstUtf8 s) {
84     stringValue = s;
85   }
86
87   ConstString (int sIndex) {
88     stringValueIndex = sIndex;
89   }
90
91   void formatData (DataOutputStream b) throws IOException {
92     b.writeShort (stringValue.getIndex());
93   }
94   static ConstString read (DataInputStream input) throws IOException {
95     return new ConstString (input.readUnsignedShort());
96   }
97   void resolve (ConstantPool p) {
98     stringValue = (ConstUtf8) p.constantAt(stringValueIndex);
99   }
100 }
101
102
103
Popular Tags