1 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 45 public class MemberValuePopulate implements MemberValueVisitor 46 { 47 private String value; 48 49 public MemberValuePopulate(String value) 50 { 51 this.value = value; 52 } 53 54 public void visitAnnotationMemberValue(AnnotationMemberValue annotationMemberValue) 55 { 56 throw new RuntimeException ("NOT IMPLEMENTED"); 57 } 58 59 public void visitArrayMemberValue(ArrayMemberValue arrayMemberValue) 60 { 61 throw new RuntimeException ("NOT IMPLEMENTED"); 62 } 63 64 public void visitBooleanMemberValue(BooleanMemberValue booleanMemberValue) 65 { 66 Boolean bool = new Boolean (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 ("Enum must be fully qualified: " + value); 89 String className = value.substring(0, index); 90 String 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 |