KickJava   Java API By Example, From Geeks To Geeks.

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


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  * A FieldRef CP Info
25  *
26  */

27 public class FieldRefCPInfo extends ConstantPoolEntry {
28     /** Name of the field's class */
29     private String JavaDoc fieldClassName;
30     /** name of the field in that class */
31     private String JavaDoc fieldName;
32     /** The type of the field */
33     private String JavaDoc fieldType;
34     /** Index into the constant pool for the class */
35     private int classIndex;
36     /** Index into the constant pool for the name and type entry */
37     private int nameAndTypeIndex;
38
39     /** Constructor. */
40     public FieldRefCPInfo() {
41         super(CONSTANT_FIELDREF, 1);
42     }
43
44     /**
45      * read a constant pool entry from a class stream.
46      *
47      * @param cpStream the DataInputStream which contains the constant pool
48      * entry to be read.
49      * @exception IOException if there is a problem reading the entry from
50      * the stream.
51      */

52     public void read(DataInputStream JavaDoc cpStream) throws IOException JavaDoc {
53         classIndex = cpStream.readUnsignedShort();
54         nameAndTypeIndex = cpStream.readUnsignedShort();
55     }
56
57     /**
58      * Resolve this constant pool entry with respect to its dependents in
59      * the constant pool.
60      *
61      * @param constantPool the constant pool of which this entry is a member
62      * and against which this entry is to be resolved.
63      */

64     public void resolve(ConstantPool constantPool) {
65         ClassCPInfo fieldClass
66             = (ClassCPInfo) constantPool.getEntry(classIndex);
67
68         fieldClass.resolve(constantPool);
69
70         fieldClassName = fieldClass.getClassName();
71
72         NameAndTypeCPInfo nt
73             = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex);
74
75         nt.resolve(constantPool);
76
77         fieldName = nt.getName();
78         fieldType = nt.getType();
79
80         super.resolve(constantPool);
81     }
82
83     /**
84      * Print a readable version of the constant pool entry.
85      *
86      * @return the string representation of this constant pool entry.
87      */

88     public String JavaDoc toString() {
89         String JavaDoc value;
90
91         if (isResolved()) {
92             value = "Field : Class = " + fieldClassName + ", name = "
93                 + fieldName + ", type = " + fieldType;
94         } else {
95             value = "Field : Class index = " + classIndex
96                 + ", name and type index = " + nameAndTypeIndex;
97         }
98
99         return value;
100     }
101
102     /**
103      * Gets the name of the class defining the field
104      *
105      * @return the name of the class defining the field
106      */

107     public String JavaDoc getFieldClassName() {
108         return fieldClassName;
109     }
110
111     /**
112      * Get the name of the field
113      *
114      * @return the field's name
115      */

116     public String JavaDoc getFieldName() {
117         return fieldName;
118     }
119
120     /**
121      * Get the type of the field
122      *
123      * @return the field's type in string format
124      */

125     public String JavaDoc getFieldType() {
126         return fieldType;
127     }
128
129 }
130
131
Popular Tags