1 | /*
|
---|
2 | * Copyright 2000-2002,2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.depend.constantpool;
|
---|
18 |
|
---|
19 | import java.io.DataInputStream;
|
---|
20 | import java.io.IOException;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The constant pool entry which stores class information.
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class ClassCPInfo extends ConstantPoolEntry {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * The class' name. This will be only valid if the entry has been
|
---|
30 | * resolved against the constant pool.
|
---|
31 | */
|
---|
32 | private String className;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * The index into the constant pool where this class' name is stored. If
|
---|
36 | * the class name is changed, this entry is invalid until this entry is
|
---|
37 | * connected to a constant pool.
|
---|
38 | */
|
---|
39 | private int index;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Constructor. Sets the tag value for this entry to type Class
|
---|
43 | */
|
---|
44 | public ClassCPInfo() {
|
---|
45 | super(CONSTANT_CLASS, 1);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Read the entry from a stream.
|
---|
50 | *
|
---|
51 | * @param cpStream the stream containing the constant pool entry to be
|
---|
52 | * read.
|
---|
53 | * @exception IOException thrown if there is a problem reading the entry
|
---|
54 | * from the stream.
|
---|
55 | */
|
---|
56 | public void read(DataInputStream cpStream) throws IOException {
|
---|
57 | index = cpStream.readUnsignedShort();
|
---|
58 | className = "unresolved";
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Generate a string readable version of this entry
|
---|
63 | *
|
---|
64 | * @return string representation of this constant pool entry
|
---|
65 | */
|
---|
66 | public String toString() {
|
---|
67 | return "Class Constant Pool Entry for " + className + "[" + index + "]";
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Resolve this class info against the given constant pool.
|
---|
72 | *
|
---|
73 | * @param constantPool the constant pool with which to resolve the
|
---|
74 | * class.
|
---|
75 | */
|
---|
76 | public void resolve(ConstantPool constantPool) {
|
---|
77 | className = ((Utf8CPInfo) constantPool.getEntry(index)).getValue();
|
---|
78 |
|
---|
79 | super.resolve(constantPool);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Get the class name of this entry.
|
---|
84 | *
|
---|
85 | * @return the class' name.
|
---|
86 | */
|
---|
87 | public String getClassName() {
|
---|
88 | return className;
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|