1 28 29 package com.caucho.config; 30 31 import com.caucho.util.L10N; 32 import com.caucho.xml.QName; 33 34 import org.w3c.dom.Node ; 35 36 import java.lang.reflect.Method ; 37 38 public class CreateAttributeStrategy extends AttributeStrategy { 39 static final L10N L = new L10N(CreateAttributeStrategy.class); 40 41 private Method _createMethod; 42 private Method _setterMethod; 43 44 public CreateAttributeStrategy(Method createMethod, Method setter) 45 { 46 _createMethod = createMethod; 47 _setterMethod = setter; 48 } 49 50 53 public Method getCreateMethod() 54 { 55 return _createMethod; 56 } 57 58 67 68 public void configure(NodeBuilder builder, 69 Object bean, 70 QName name, 71 Node node) 72 throws Exception 73 { 74 Object child = builder.createResinType(node); 76 77 if (child == null) 78 child = _createMethod.invoke(bean); 79 80 TypeStrategy childStrategy; 81 82 childStrategy = TypeStrategyFactory.getTypeStrategy(child.getClass()); 83 84 child = builder.configureImpl(childStrategy, child, node); 85 86 setChild(bean, name, child); 87 } 88 89 92 public Object create(Object parent) 93 throws Exception 94 { 95 return _createMethod.invoke(parent, new Object [0]); 96 } 97 98 101 public void setChild(Object bean, QName name, Object child) 102 throws Exception 103 { 104 if (_setterMethod != null) { 105 try { 106 _setterMethod.invoke(bean, new Object [] { child }); 107 } catch (IllegalArgumentException e) { 108 throw new IllegalArgumentException (_setterMethod.getName() + ": " + e); 109 } 110 } 111 } 112 } 113 | Popular Tags |