KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > bytecode > annotation > ClassMemberValue


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 2004 Bill Burke. All Rights Reserved.
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. Alternatively, the contents of this file may be used under
8  * the terms of the GNU Lesser General Public License Version 2.1 or later.
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */

15
16 package javassist.bytecode.annotation;
17
18 import javassist.bytecode.ConstPool;
19 import javassist.bytecode.Descriptor;
20 import java.io.IOException JavaDoc;
21
22 /**
23  * String constant value.
24  *
25  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
26  * @author Shigeru Chiba
27  */

28 public class ClassMemberValue extends MemberValue {
29     int valueIndex;
30
31     /**
32      * Constructs a string constant value. The initial value is specified
33      * by the constant pool entry at the given index.
34      *
35      * @param index the index of a CONSTANT_Utf8_info structure.
36      */

37     public ClassMemberValue(int index, ConstPool cp) {
38         super('c', cp);
39         this.valueIndex = index;
40     }
41
42     /**
43      * Constructs a string constant value.
44      *
45      * @param className the initial value.
46      */

47     public ClassMemberValue(String JavaDoc className, ConstPool cp) {
48         super('c', cp);
49         setValue(className);
50     }
51
52     /**
53      * Constructs a string constant value.
54      * The initial value is java.lang.Class.
55      */

56     public ClassMemberValue(ConstPool cp) {
57         super('c', cp);
58         setValue("java.lang.Class");
59     }
60
61     /**
62      * Obtains the value of the member.
63      *
64      * @return fully-qualified class name.
65      */

66     public String JavaDoc getValue() {
67         String JavaDoc v = cp.getUtf8Info(valueIndex);
68         return Descriptor.toClassName(v);
69     }
70
71     /**
72      * Sets the value of the member.
73      *
74      * @param newClassName fully-qualified class name.
75      */

76     public void setValue(String JavaDoc newClassName) {
77         String JavaDoc setTo = Descriptor.of(newClassName);
78         valueIndex = cp.addUtf8Info(setTo);
79     }
80
81     /**
82      * Obtains the string representation of this object.
83      */

84     public String JavaDoc toString() {
85         return "<" + getValue() + " class>";
86     }
87
88     void write(AnnotationsWriter writer) throws IOException JavaDoc {
89         writer.classInfoIndex(valueIndex);
90     }
91
92     /**
93      * Accepts a visitor.
94      */

95     public void accept(MemberValueVisitor visitor) {
96         visitor.visitClassMemberValue(this);
97     }
98 }
99
Popular Tags