KickJava   Java API By Example, From Geeks To Geeks.

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


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 name and an associated type in the constant pool
31  * of a class file
32  */

33
34 public class ConstNameAndType extends ConstBasic {
35   /* The tag value associated with ConstDouble */
36   public static final int MyTag = CONSTANTNameAndType;
37
38   /* The name of interest */
39   private ConstUtf8 theName;
40
41   /* The index of the name to be resolved
42    * - used during class file reading */

43   private int theNameIndex;
44
45   /* The type signature associated with the name */
46   private ConstUtf8 typeSignature;
47
48   /* The index of the signature to be resolved
49    * - used during class file reading */

50   private int typeSignatureIndex;
51
52   /* public accessors */
53
54   /**
55    * The tag of this constant entry
56    */

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

62   public ConstUtf8 name() {
63     return theName;
64   }
65
66   /**
67    * Return the type signature associated with the name
68    */

69   public ConstUtf8 signature() {
70     return typeSignature;
71   }
72
73   /**
74    * Modify the signature
75    */

76   public void changeSignature(ConstUtf8 newSig) {
77     typeSignature = newSig;
78   }
79
80   /**
81    * A printable representation
82    */

83   public String JavaDoc toString () {
84       return "CONSTANTNameAndType(" + indexAsString() + "): " + //NOI18N
85
"name(" + theName.toString() + ") " +//NOI18N
86
" type(" + typeSignature.toString() + ")";//NOI18N
87
}
88
89   /* package local methods */
90
91   ConstNameAndType (ConstUtf8 n, ConstUtf8 sig) {
92     theName = n; typeSignature = sig;
93   }
94
95   ConstNameAndType (int n, int sig) {
96     theNameIndex = n; typeSignatureIndex = sig;
97   }
98
99   void formatData (DataOutputStream b) throws IOException {
100     b.writeShort(theName.getIndex());
101     b.writeShort(typeSignature.getIndex());
102   }
103
104   static ConstNameAndType read (DataInputStream input) throws IOException {
105     int cname = input.readUnsignedShort();
106     int sig = input.readUnsignedShort();
107
108     return new ConstNameAndType (cname, sig);
109   }
110
111   void resolve (ConstantPool p) {
112     theName = (ConstUtf8) p.constantAt(theNameIndex);
113     typeSignature = (ConstUtf8) p.constantAt(typeSignatureIndex);
114   }
115 }
116
117
118
Popular Tags