KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > depend > constantpool > ClassCPInfo


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
19
20 import java.io.DataInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 /**
24  * The constant pool entry which stores class information.
25  *
26  */

27 public class ClassCPInfo extends ConstantPoolEntry {
28
29     /**
30      * The class' name. This will be only valid if the entry has been
31      * resolved against the constant pool.
32      */

33     private String JavaDoc className;
34
35     /**
36      * The index into the constant pool where this class' name is stored. If
37      * the class name is changed, this entry is invalid until this entry is
38      * connected to a constant pool.
39      */

40     private int index;
41
42     /**
43      * Constructor. Sets the tag value for this entry to type Class
44      */

45     public ClassCPInfo() {
46         super(CONSTANT_CLASS, 1);
47     }
48
49     /**
50      * Read the entry from a stream.
51      *
52      * @param cpStream the stream containing the constant pool entry to be
53      * read.
54      * @exception IOException thrown if there is a problem reading the entry
55      * from the stream.
56      */

57     public void read(DataInputStream JavaDoc cpStream) throws IOException JavaDoc {
58         index = cpStream.readUnsignedShort();
59         className = "unresolved";
60     }
61
62     /**
63      * Generate a string readable version of this entry
64      *
65      * @return string representation of this constant pool entry
66      */

67     public String JavaDoc toString() {
68         return "Class Constant Pool Entry for " + className + "[" + index + "]";
69     }
70
71     /**
72      * Resolve this class info against the given constant pool.
73      *
74      * @param constantPool the constant pool with which to resolve the
75      * class.
76      */

77     public void resolve(ConstantPool constantPool) {
78         className = ((Utf8CPInfo) constantPool.getEntry(index)).getValue();
79
80         super.resolve(constantPool);
81     }
82
83     /**
84      * Get the class name of this entry.
85      *
86      * @return the class' name.
87      */

88     public String JavaDoc getClassName() {
89         return className;
90     }
91
92 }
93
94
Popular Tags