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.Field ; 41 import java.lang.reflect.InvocationTargetException ; 42 43 public class BeanField extends JaxbProperty { 44 private final Class _type; 45 private final Field _field; 46 private TypeStrategy _typeStrategy; 47 48 public BeanField(Field field, Class type) 49 { 50 if (type == null) 51 throw new NullPointerException (); 52 53 _type = type; 54 _field = field; 55 } 56 57 65 public void configureAttribute(NodeBuilder builder, 66 Object bean, 67 QName name, 68 String value) 69 throws ConfigException 70 { 71 } 72 73 81 public void configureElement(NodeBuilder builder, 82 Object bean, 83 QName name, 84 Node node) 85 throws ConfigException 86 { 87 try { 88 Object value = _type.newInstance(); 89 90 if (_typeStrategy == null) 91 _typeStrategy = TypeStrategyFactory.getTypeStrategy(_type); 92 93 _typeStrategy.configureBean(builder, value, node); 94 95 _field.set(bean, value); 96 } catch (RuntimeException e) { 97 throw e; 98 } catch (InvocationTargetException e) { 99 throw builder.error(e.getCause(), node); 100 } catch (Exception e) { 101 throw builder.error(e, node); 102 } 103 } 104 } 105 | Popular Tags |