1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import java.lang.reflect.InvocationTargetException ; 33 import java.lang.reflect.Method ; 34 import java.util.Iterator ; 35 36 import nextapp.echo2.app.LayoutData; 37 import nextapp.echo2.app.Style; 38 import nextapp.echo2.app.componentxml.ComponentIntrospector; 39 import nextapp.echo2.app.componentxml.ComponentXmlException; 40 import nextapp.echo2.app.componentxml.InvalidPropertyException; 41 import nextapp.echo2.app.componentxml.PropertyLoader; 42 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 43 import nextapp.echo2.app.util.DomUtil; 44 45 import org.w3c.dom.Element ; 46 47 56 public class LayoutDataPeer 57 implements PropertyXmlPeer { 58 59 63 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 64 throws InvalidPropertyException { 65 try { 66 Element layoutDataElement = DomUtil.getChildElementByTagName(propertyElement, "layout-data"); 67 String type = layoutDataElement.getAttribute("type"); 68 69 PropertyLoader propertyLoader = PropertyLoader.forClassLoader(classLoader); 71 Element propertiesElement = DomUtil.getChildElementByTagName(layoutDataElement, "properties"); 72 Style propertyStyle = propertyLoader.createStyle(propertiesElement, type); 73 74 Class propertyClass = Class.forName(type, true, classLoader); 76 LayoutData layoutData = (LayoutData) propertyClass.newInstance(); 77 78 ComponentIntrospector ci = ComponentIntrospector.forName(type, classLoader); 80 81 Iterator it = propertyStyle.getPropertyNames(); 83 while (it.hasNext()) { 84 String propertyName = (String ) it.next(); 85 Method writeMethod = ci.getWriteMethod(propertyName); 86 writeMethod.invoke(layoutData, new Object []{propertyStyle.getProperty(propertyName)}); 87 } 88 89 return layoutData; 90 } catch (ClassNotFoundException ex) { 91 throw new InvalidPropertyException("Unable to process properties.", ex); 92 } catch (ComponentXmlException ex) { 93 throw new InvalidPropertyException("Unable to process properties.", ex); 94 } catch (InstantiationException ex) { 95 throw new InvalidPropertyException("Unable to process properties.", ex); 96 } catch (IllegalAccessException ex) { 97 throw new InvalidPropertyException("Unable to process properties.", ex); 98 } catch (IllegalArgumentException ex) { 99 throw new InvalidPropertyException("Unable to process properties.", ex); 100 } catch (InvocationTargetException ex) { 101 throw new InvalidPropertyException("Unable to process properties.", ex); 102 } 103 } 104 } 105 | Popular Tags |