KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > classfile > CPName


1 /*
2  * CPName.java
3  *
4  * The contents of this file are subject to the terms of the Common Development
5  * and Distribution License (the License). You may not use this file except in
6  * compliance with the License.
7  *
8  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
9  * or http://www.netbeans.org/cddl.txt.
10  *
11  * When distributing Covered Code, include this CDDL Header Notice in each file
12  * and include the License file at http://www.netbeans.org/cddl.txt.
13  * If applicable, add the following below the CDDL Header, with the fields
14  * enclosed by brackets [] replaced by your own identifying information:
15  * "Portions Copyrighted [year] [name of copyright owner]"
16  *
17  * The Original Software is NetBeans. The Initial Developer of the Original
18  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
19  * Microsystems, Inc. All Rights Reserved.
20  *
21  * Contributor(s): Thomas Ball
22  *
23  * Version: $Revision: 1.2 $
24  */

25
26 package org.netbeans.modules.classfile;
27
28 /**
29  * The base class for all constant pool types which store strings.
30  *
31  * @author Thomas Ball
32  */

33 abstract class CPName extends CPEntry {
34
35     final static int INVALID_INDEX = -1;
36
37     int index;
38     private String JavaDoc name;
39
40     CPName(ConstantPool pool,int index) {
41     super(pool);
42         this.index = index;
43     }
44
45     CPName(ConstantPool pool) {
46     super(pool);
47     index = INVALID_INDEX;
48     }
49
50     public String JavaDoc getName() {
51     if (index == INVALID_INDEX) {
52         return null;
53         }
54         if (name == null) {
55             name = ((CPName)pool.cpEntries[index]).getName();
56         }
57         return name;
58     }
59     
60     public Object JavaDoc getValue() {
61         return getName();
62     }
63
64     void setNameIndex(int index) {
65     this.index = index;
66         name = null;
67     }
68
69     public String JavaDoc toString() {
70     return getClass().getName() + ": name=" +
71         (index == INVALID_INDEX ? "<unresolved>" : //NOI18N
72
((CPName)pool.cpEntries[index]).getName());
73     }
74 }
75
Popular Tags