01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
21: import java.io.IOException;
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 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 cpStream) throws IOException {
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 toString() {
68: return "Class Constant Pool Entry for " + className + "["
69: + index + "]";
70: }
71:
72: /**
73: * Resolve this class info against the given constant pool.
74: *
75: * @param constantPool the constant pool with which to resolve the
76: * class.
77: */
78: public void resolve(ConstantPool constantPool) {
79: className = ((Utf8CPInfo) constantPool.getEntry(index))
80: .getValue();
81:
82: super .resolve(constantPool);
83: }
84:
85: /**
86: * Get the class name of this entry.
87: *
88: * @return the class' name.
89: */
90: public String getClassName() {
91: return className;
92: }
93:
94: }
|