1 22 package org.jboss.beans.metadata.plugins; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.reflect.spi.TypeInfo; 26 import org.jboss.beans.metadata.spi.MetaDataVisitor; 27 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 28 29 35 public class StringValueMetaData extends AbstractTypeMetaData 36 { 37 38 private static final Logger log = Logger.getLogger(StringValueMetaData.class); 39 40 43 public StringValueMetaData() 44 { 45 } 46 47 52 public StringValueMetaData(String value) 53 { 54 super(value); 55 } 56 57 62 public void setValue(String value) 63 { 64 super.setValue(value); 65 } 66 67 public void setValue(Object value) 68 { 69 if (value != null && value instanceof String == false) 70 throw new ClassCastException ("value is not a String: " + value); 71 super.setValue(value); 72 } 73 74 public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable 75 { 76 boolean trace = log.isTraceEnabled(); 77 if (trace) 78 log.trace("getValue value=" + value + " type=" + type + " info=" + info); 79 80 TypeInfo typeInfo = getClassInfo(cl); 81 if (typeInfo == null) 82 typeInfo = info; 83 if (typeInfo == null) 84 throw new IllegalArgumentException ("Unable to determine type for value: " + value); 85 86 return typeInfo.convertValue(value); 87 } 88 89 public Class getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable 90 { 91 if (getType() != null) 92 { 93 return getClass(visitor, getType()); 94 } 95 return super.getType(visitor, previous); 96 } 97 98 } 99 | Popular Tags |