1 28 29 package com.caucho.config; 30 31 import com.caucho.util.L10N; 32 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 36 import java.lang.reflect.Method ; 37 38 41 public class NodePropertyStrategy extends AttributeStrategy { 42 static final L10N L = new L10N(NodePropertyStrategy.class); 43 44 private final Method _setter; 45 private String _name; 46 47 public NodePropertyStrategy(Method setter) 48 throws BeanBuilderException 49 { 50 _setter = setter; 51 } 52 53 public Method getMethod() 54 { 55 return _setter; 56 } 57 58 74 75 public void setChild(Object bean, Object value) 76 throws BeanBuilderException 77 { 78 try { 79 Node node = (Node ) value; 80 81 if (node == null) { 82 _setter.invoke(bean, new Object [] { null }); 83 return; 84 } 85 86 for (Node child = node.getFirstChild(); 87 child != null; 88 child = child.getNextSibling()) { 89 if (child instanceof Element ) { 90 _setter.invoke(bean, new Object [] { child }); 91 return; 92 } 93 } 94 95 _setter.invoke(bean, new Object [] { node.getFirstChild() }); 96 } catch (Exception e) { 97 throw new BeanBuilderException(e); 98 } 99 } 100 101 private void setNull(Object bean) 102 throws Exception 103 { 104 _setter.invoke(bean, new Object [] { null }); 105 } 106 } 107 | Popular Tags |