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.xml.QName; 36 37 import org.w3c.dom.Node ; 38 39 import java.lang.reflect.Field ; 40 import java.lang.reflect.InvocationTargetException ; 41 import java.util.Collection ; 42 43 public class CollectionField extends JaxbProperty { 44 private final TypeStrategy _typeMarshal; 45 private final Field _field; 46 47 public CollectionField(TypeStrategy typeMarshal, 48 Field field) 49 { 50 _typeMarshal = typeMarshal; 51 52 _field = field; 53 54 field.setAccessible(true); 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 = _typeMarshal.configure(builder, node, bean); 89 90 Collection list = (Collection ) _field.get(bean); 91 92 if (list != null) 93 list.add(value); 94 } catch (RuntimeException e) { 95 throw e; 96 } catch (InvocationTargetException e) { 97 throw builder.error(e.getCause(), node); 98 } catch (Exception e) { 99 throw builder.error(e, node); 100 } 101 } 102 } 103 | Popular Tags |