01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 2004 Bill Burke. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
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: package javassist.bytecode.annotation;
16:
17: import javassist.ClassPool;
18: import javassist.bytecode.ConstPool;
19: import java.io.IOException;
20: import java.lang.reflect.Method;
21:
22: /**
23: * Nested annotation.
24: *
25: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
26: * @author Shigeru Chiba
27: */
28: public class AnnotationMemberValue extends MemberValue {
29: Annotation value;
30:
31: /**
32: * Constructs an annotation member. The initial value is not specified.
33: */
34: public AnnotationMemberValue(ConstPool cp) {
35: this (null, cp);
36: }
37:
38: /**
39: * Constructs an annotation member. The initial value is specified by
40: * the first parameter.
41: */
42: public AnnotationMemberValue(Annotation a, ConstPool cp) {
43: super ('@', cp);
44: value = a;
45: }
46:
47: Object getValue(ClassLoader cl, ClassPool cp, Method m)
48: throws ClassNotFoundException {
49: return AnnotationImpl.make(cl, getType(cl), cp, value);
50: }
51:
52: Class getType(ClassLoader cl) throws ClassNotFoundException {
53: if (value == null)
54: throw new ClassNotFoundException("no type specified");
55: else
56: return loadClass(cl, value.getTypeName());
57: }
58:
59: /**
60: * Obtains the value.
61: */
62: public Annotation getValue() {
63: return value;
64: }
65:
66: /**
67: * Sets the value of this member.
68: */
69: public void setValue(Annotation newValue) {
70: value = newValue;
71: }
72:
73: /**
74: * Obtains the string representation of this object.
75: */
76: public String toString() {
77: return value.toString();
78: }
79:
80: /**
81: * Writes the value.
82: */
83: public void write(AnnotationsWriter writer) throws IOException {
84: writer.annotationValue();
85: value.write(writer);
86: }
87:
88: /**
89: * Accepts a visitor.
90: */
91: public void accept(MemberValueVisitor visitor) {
92: visitor.visitAnnotationMemberValue(this);
93: }
94: }
|