1 16 package org.apache.commons.betwixt.digester; 17 18 import java.util.HashSet ; 19 import java.util.Set ; 20 21 import javax.xml.parsers.SAXParser ; 22 23 import org.apache.commons.betwixt.XMLIntrospector; 24 import org.apache.commons.digester.Digester; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.xml.sax.XMLReader ; 28 29 35 public class XMLBeanInfoDigester extends Digester { 36 37 38 private static final Log log = LogFactory.getLog( XMLBeanInfoDigester.class ); 39 40 41 private Class beanClass; 42 43 44 private boolean attributesForPrimitives; 45 46 47 private Set processedPropertyNameSet = new HashSet (); 48 49 50 private XMLIntrospector introspector; 51 52 55 public XMLBeanInfoDigester() { 56 } 57 58 67 public XMLBeanInfoDigester(SAXParser parser) { 68 super(parser); 69 } 70 71 80 public XMLBeanInfoDigester(XMLReader reader) { 81 super(reader); 82 } 83 84 89 public Class getBeanClass() { 90 return beanClass; 91 } 92 93 98 public void setBeanClass(Class beanClass) { 99 this.beanClass = beanClass; 100 } 101 102 103 108 public Set getProcessedPropertyNameSet() { 109 return processedPropertyNameSet; 110 } 111 112 116 public boolean isAttributesForPrimitives() { 117 return attributesForPrimitives; 118 } 119 120 125 public void setAttributesForPrimitives(boolean attributesForPrimitives) { 126 this.attributesForPrimitives = attributesForPrimitives; 127 if ( introspector != null ) { 128 introspector.getConfiguration() 129 .setAttributesForPrimitives( attributesForPrimitives ); 130 } 131 } 132 133 138 public XMLIntrospector getXMLIntrospector() { 139 return introspector; 140 } 141 142 147 public void setXMLIntrospector(XMLIntrospector introspector) { 148 this.introspector = introspector; 149 } 150 151 154 protected void configure() { 155 if (! configured) { 156 configured = true; 157 158 160 addRule( "info", new InfoRule() ); 161 addRule( "*/element", new ElementRule() ); 162 addRule( "*/text", new TextRule() ); 163 addRule( "*/attribute", new AttributeRule() ); 164 addRule( "*/hide", new HideRule() ); 165 addRule( "*/addDefaults", new AddDefaultsRule() ); 166 167 OptionRule optionRule = new OptionRule(); 168 addRule( "*/option", optionRule ); 169 addRule( "*/option/name", optionRule.getNameRule() ); 170 addRule( "*/option/value", optionRule.getValueRule() ); 171 } 172 173 setAttributesForPrimitives(attributesForPrimitives); 175 processedPropertyNameSet.clear(); 176 } 177 178 } 179 | Popular Tags |