KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > classfile > ConstantPoolEntry


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

21
22 package org.apache.derby.iapi.services.classfile;
23
24 import org.apache.derby.iapi.services.classfile.VMDescriptor;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import java.io.IOException JavaDoc;
29
30 /** Constant Pool class - pages 92-99 */
31 public abstract class ConstantPoolEntry /*implements PoolEntry*/
32 {
33     
34     protected int tag; // u1 (page 83)
35
protected boolean doubleSlot; // Some entries take up two slots! (see footnote page 98)
36

37     /* Index within Vector */
38     protected int index;
39
40     protected ConstantPoolEntry(int tag) {
41         this.tag = tag;
42     }
43
44     int getIndex() {
45         if (SanityManager.DEBUG) {
46             if (index <= 0)
47             {
48                 SanityManager.THROWASSERT("index is expected to be > 0, is " + index);
49             }
50         }
51         return index;
52     }
53
54     void setIndex(int index) {
55         this.index = index;
56     }
57
58     boolean doubleSlot() {
59         return doubleSlot;
60     }
61
62     /**
63         Return the key used to key this object in a hashtable
64     */

65     Object JavaDoc getKey() {
66         return this;
67     }
68
69     /**
70         Return an estimate of the size of the constant pool entry.
71     */

72     abstract int classFileSize();
73
74     void put(ClassFormatOutput out) throws IOException JavaDoc {
75         out.putU1(tag);
76     }
77
78     /*
79     ** Public API methods
80     */

81
82     /**
83         Return the tag or type of the entry. Will be equal to one of the
84         constants above, e.g. CONSTANT_Class.
85     */

86     final int getTag() {
87         return tag;
88     }
89
90     /**
91         Get the first index in a index type pool entry.
92         This call is valid when getTag() returns one of
93         <UL>
94         <LI> CONSTANT_Class
95         <LI> CONSTANT_Fieldref
96         <LI> CONSTANT_Methodref
97         <LI> CONSTANT_InterfaceMethodref
98         <LI> CONSTANT_String
99         <LI> CONSTANT_NameAndType
100         </UL>
101     */

102     int getI1() { return 0; }
103
104     /**
105         Get the second index in a index type pool entry.
106         This call is valid when getTag() returns one of
107         <UL>
108         <LI> CONSTANT_Fieldref
109         <LI> CONSTANT_Methodref
110         <LI> CONSTANT_InterfaceMethodref
111         <LI> CONSTANT_NameAndType
112         </UL>
113     */

114     int getI2() { return 0; };
115 }
116
117
Popular Tags