1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import org.w3c.dom.Element ; 33 34 import nextapp.echo2.app.componentxml.ComponentIntrospector; 35 import nextapp.echo2.app.componentxml.InvalidPropertyException; 36 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 37 38 42 public class IntegerPeer 43 implements PropertyXmlPeer { 44 45 49 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 50 throws InvalidPropertyException { 51 String stringValue = propertyElement.getAttribute("value"); 52 try { 53 return new Integer (stringValue); 54 } catch (NumberFormatException ex) { 55 return introspectConstantValue(classLoader, objectClass, stringValue); 56 } 57 } 58 59 67 public Integer introspectConstantValue(ClassLoader classLoader, Class objectClass, String value) 68 throws InvalidPropertyException { 69 try { 70 ComponentIntrospector ci = ComponentIntrospector.forName(objectClass.getName(), classLoader); 71 if (value.startsWith(objectClass.getName())) { 72 value = value.substring(objectClass.getName().length() + 1); 74 } 75 Object constantValue = ci.getConstantValue(value); 76 if (constantValue instanceof Integer ) { 77 return (Integer ) constantValue; 78 } else { 79 return null; 80 } 81 } catch (ClassNotFoundException ex) { 82 throw new InvalidPropertyException("Object class not found.", ex); 84 } 85 } 86 } 87 | Popular Tags |