1 29 30 package com.caucho.config.jaxb; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.NodeBuilder; 34 import com.caucho.config.TypeStrategy; 35 import com.caucho.config.TypeStrategyFactory; 36 import com.caucho.xml.QName; 37 38 import org.w3c.dom.Node ; 39 40 import java.lang.reflect.InvocationTargetException ; 41 import java.lang.reflect.Method ; 42 43 public class BeanProperty extends JaxbProperty { 44 private final Class _type; 45 private final Method _method; 46 private TypeStrategy _typeStrategy; 47 48 public BeanProperty(Method method, Class type) 49 { 50 _type = type; 51 _method = method; 52 } 53 54 62 public void configureAttribute(NodeBuilder builder, 63 Object bean, 64 QName name, 65 String value) 66 throws ConfigException 67 { 68 } 69 70 78 public void configureElement(NodeBuilder builder, 79 Object bean, 80 QName name, 81 Node node) 82 throws ConfigException 83 { 84 try { 85 Object value = _type.newInstance(); 86 87 if (_typeStrategy == null) 88 _typeStrategy = TypeStrategyFactory.getTypeStrategy(_type); 89 90 _typeStrategy.configureBean(builder, value, node); 91 92 _method.invoke(bean, value); 93 } catch (RuntimeException e) { 94 throw e; 95 } catch (InvocationTargetException e) { 96 throw builder.error(e.getCause(), node); 97 } catch (Exception e) { 98 throw builder.error(e, node); 99 } 100 } 101 } 102 | Popular Tags |