KickJava   Java API By Example, From Geeks To Geeks.

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


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 reference in the constant pool
31  */

32
33 public class ConstClass extends ConstBasic {
34   /* The tag associated with ConstClass entries */
35   public static final int MyTag = CONSTANTClass;
36
37   /* The name of the class being referred to */
38   private ConstUtf8 theClassName;
39
40   /* The index of name of the class being referred to
41    * - used while reading from a class file */

42   private int theClassNameIndex;
43
44   /* public accessors */
45
46   /**
47    * Return the tag for this constant
48    */

49   public int tag () { return MyTag; }
50
51   /**
52    * Return the class name
53    */

54   public ConstUtf8 className() {
55     return theClassName;
56   }
57
58   /**
59    * Return the class name in simple string form
60    */

61   public String JavaDoc asString() {
62     return theClassName.asString();
63   }
64
65   /**
66    * A printable representation
67    */

68   public String JavaDoc toString () {
69       return "CONSTANTClass(" + indexAsString() + "): " + //NOI18N
70
"className(" + theClassName.toString() + ")";//NOI18N
71
}
72
73   /**
74    * Change the class reference (not to be done lightly)
75    */

76   public void changeClass(ConstUtf8 newName) {
77     theClassName = newName;
78     theClassNameIndex = newName.getIndex();
79   }
80
81   /* package local methods */
82
83   /**
84    * Construct a ConstClass
85    */

86   public ConstClass (ConstUtf8 cname) {
87     theClassName = cname;
88   }
89
90   ConstClass (int cname) {
91     theClassNameIndex = cname;
92   }
93
94   void formatData (DataOutputStream b) throws IOException {
95     b.writeShort(theClassName.getIndex());
96   }
97
98   static ConstClass read (DataInputStream input) throws IOException {
99     return new ConstClass (input.readUnsignedShort());
100   }
101
102   void resolve (ConstantPool p) {
103     theClassName = (ConstUtf8) p.constantAt(theClassNameIndex);
104   }
105 }
106
107
Popular Tags