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.InvocationTargetException ; 40 import java.lang.reflect.Method ; 41 import java.util.Collection ; 42 43 public class CollectionProperty extends JaxbProperty { 44 private final TypeStrategy _typeMarshal; 45 private final Method _getter; 46 47 public CollectionProperty(TypeStrategy typeMarshal, 48 Method getter) 49 { 50 _typeMarshal = typeMarshal; 51 52 _getter = getter; 53 } 54 55 63 public void configureAttribute(NodeBuilder builder, 64 Object bean, 65 QName name, 66 String value) 67 throws ConfigException 68 { 69 } 70 71 79 public void configureElement(NodeBuilder builder, 80 Object bean, 81 QName name, 82 Node node) 83 throws ConfigException 84 { 85 try { 86 Object value = _typeMarshal.configure(builder, node, bean); 87 88 Collection list = (Collection ) _getter.invoke(bean); 89 90 if (list != null) 91 list.add(value); 92 } catch (RuntimeException e) { 93 throw e; 94 } catch (InvocationTargetException e) { 95 throw builder.error(e.getCause(), node); 96 } catch (Exception e) { 97 throw builder.error(e, node); 98 } 99 } 100 } 101 | Popular Tags |