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.xml.QName; 35 36 import org.w3c.dom.Node ; 37 38 import java.lang.reflect.InvocationTargetException ; 39 import java.lang.reflect.Method ; 40 41 public class BooleanProperty extends JaxbProperty { 42 private final Method _method; 43 44 public BooleanProperty(Method method) 45 { 46 _method = method; 47 } 48 49 57 public void configureAttribute(NodeBuilder builder, 58 Object bean, 59 QName name, 60 String value) 61 throws ConfigException 62 { 63 } 64 65 73 public void configureElement(NodeBuilder builder, 74 Object bean, 75 QName name, 76 Node node) 77 throws ConfigException 78 { 79 String textValue = node.getTextContent().trim(); 80 81 Boolean value; 82 83 if (textValue.indexOf("${") >= 0) 84 value = builder.evalBoolean(textValue) ? Boolean.TRUE : Boolean.FALSE; 85 else if (textValue.equals("true") || textValue.equals("1")) 86 value = Boolean.TRUE; 87 else 88 value = Boolean.FALSE; 89 90 try { 91 _method.invoke(bean, value); 92 } catch (IllegalAccessException e) { 93 throw builder.error(e, node); 94 } catch (InvocationTargetException e) { 95 throw builder.error(e.getCause(), node); 96 } 97 } 98 } 99 | Popular Tags |