KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > annotation > compiler > MemberValuePopulate


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.annotation.compiler;
23
24 import javassist.bytecode.annotation.AnnotationMemberValue;
25 import javassist.bytecode.annotation.ArrayMemberValue;
26 import javassist.bytecode.annotation.BooleanMemberValue;
27 import javassist.bytecode.annotation.ByteMemberValue;
28 import javassist.bytecode.annotation.CharMemberValue;
29 import javassist.bytecode.annotation.ClassMemberValue;
30 import javassist.bytecode.annotation.DoubleMemberValue;
31 import javassist.bytecode.annotation.EnumMemberValue;
32 import javassist.bytecode.annotation.FloatMemberValue;
33 import javassist.bytecode.annotation.IntegerMemberValue;
34 import javassist.bytecode.annotation.LongMemberValue;
35 import javassist.bytecode.annotation.MemberValueVisitor;
36 import javassist.bytecode.annotation.ShortMemberValue;
37 import javassist.bytecode.annotation.StringMemberValue;
38
39 /**
40  * Comment
41  *
42  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
43  * @version $Revision: 37406 $
44  */

45 public class MemberValuePopulate implements MemberValueVisitor
46 {
47    private String JavaDoc value;
48
49    public MemberValuePopulate(String JavaDoc value)
50    {
51       this.value = value;
52    }
53
54    public void visitAnnotationMemberValue(AnnotationMemberValue annotationMemberValue)
55    {
56       throw new RuntimeException JavaDoc("NOT IMPLEMENTED");
57    }
58
59    public void visitArrayMemberValue(ArrayMemberValue arrayMemberValue)
60    {
61       throw new RuntimeException JavaDoc("NOT IMPLEMENTED");
62    }
63
64    public void visitBooleanMemberValue(BooleanMemberValue booleanMemberValue)
65    {
66       Boolean JavaDoc bool = new Boolean JavaDoc(value);
67       booleanMemberValue.setValue(bool.booleanValue());
68    }
69
70    public void visitByteMemberValue(ByteMemberValue byteMemberValue)
71    {
72       byteMemberValue.setValue(Byte.parseByte(value));
73    }
74
75    public void visitCharMemberValue(CharMemberValue charMemberValue)
76    {
77       charMemberValue.setValue(value.charAt(0));
78    }
79
80    public void visitDoubleMemberValue(DoubleMemberValue doubleMemberValue)
81    {
82       doubleMemberValue.setValue(Double.parseDouble(value));
83    }
84
85    public void visitEnumMemberValue(EnumMemberValue enumMemberValue)
86    {
87       int index = value.lastIndexOf('.');
88       if (index == -1) throw new RuntimeException JavaDoc("Enum must be fully qualified: " + value);
89       String JavaDoc className = value.substring(0, index);
90       String JavaDoc en = value.substring(index + 1);
91       enumMemberValue.setType(className);
92       enumMemberValue.setValue(en);
93    }
94
95    public void visitFloatMemberValue(FloatMemberValue floatMemberValue)
96    {
97       floatMemberValue.setValue(Float.parseFloat(value));
98    }
99
100    public void visitIntegerMemberValue(IntegerMemberValue integerMemberValue)
101    {
102       integerMemberValue.setValue(Integer.parseInt(value));
103    }
104
105    public void visitLongMemberValue(LongMemberValue longMemberValue)
106    {
107       longMemberValue.setValue(Long.parseLong(value));
108    }
109
110    public void visitShortMemberValue(ShortMemberValue shortMemberValue)
111    {
112       shortMemberValue.setValue(Short.parseShort(value));
113    }
114
115    public void visitStringMemberValue(StringMemberValue stringMemberValue)
116    {
117       stringMemberValue.setValue(value);
118    }
119
120    public void visitClassMemberValue(ClassMemberValue classMemberValue)
121    {
122       if (value.endsWith(".class"))
123       {
124          value = value.substring(0, value.indexOf(".class"));
125       }
126       classMemberValue.setValue(value);
127    }
128 }
129
Popular Tags