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 javax.xml.bind.annotation.adapters.XmlAdapter; 40 import java.lang.reflect.InvocationTargetException ; 41 import java.lang.reflect.Method ; 42 43 public class AdapterProperty extends JaxbProperty { 44 private final TypeStrategy _typeMarshal; 45 private final XmlAdapter _adapter; 46 private final Method _setter; 47 48 public AdapterProperty(Method setter, 49 TypeStrategy typeMarshal, 50 XmlAdapter adapter) 51 { 52 _typeMarshal = typeMarshal; 53 _adapter = adapter; 54 55 _setter = setter; 56 57 setter.setAccessible(true); 58 } 59 60 68 public void configureAttribute(NodeBuilder builder, 69 Object bean, 70 QName name, 71 String value) 72 throws ConfigException 73 { 74 } 75 76 84 public void configureElement(NodeBuilder builder, 85 Object bean, 86 QName name, 87 Node node) 88 throws ConfigException 89 { 90 try { 91 Object value = _typeMarshal.configure(builder, node, bean); 92 93 Object bound = _adapter.unmarshal(value); 94 95 _setter.invoke(bean, bound); 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 |