1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.betwixt.digester;
18
19 import org.apache.commons.betwixt.XMLBeanInfo;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.xml.sax.Attributes;
23 import org.xml.sax.SAXException;
24
25 /*** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p>
26 *
27 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28 * @version $Revision: 438373 $
29 */
30 public class InfoRule extends RuleSupport {
31
32 /*** Logger */
33 private static final Log log = LogFactory.getLog( InfoRule.class );
34 /*** <code>XMLBeanInfo</code> being created */
35 private XMLBeanInfo xmlBeanInfo;
36
37 /*** Base constructor */
38 public InfoRule() {
39 }
40
41
42
43
44 /***
45 * Process the beginning of this element.
46 *
47 * @param attributes The attribute list of this element
48 * @throws SAXException if the primitiveTypes attribute contains an invalid value
49 */
50 public void begin(String name, String namespace, Attributes attributes) throws SAXException {
51 Class beanClass = getBeanClass();
52
53 xmlBeanInfo = new XMLBeanInfo( beanClass );
54
55 String value = attributes.getValue( "primitiveTypes" );
56 if ( value != null ) {
57 if ( value.equalsIgnoreCase( "element" ) ) {
58 getXMLInfoDigester().setAttributesForPrimitives( false );
59
60 } else if ( value.equalsIgnoreCase( "attribute" ) ) {
61 getXMLInfoDigester().setAttributesForPrimitives( true );
62
63 } else {
64 throw new SAXException(
65 "Invalid value inside element <info> for attribute 'primitiveTypes'."
66 + " Value should be 'element' or 'attribute'" );
67 }
68 }
69
70 getDigester().push(xmlBeanInfo);
71 }
72
73
74 /***
75 * Process the end of this element.
76 */
77 public void end(String name, String namespace) {
78 Object top = getDigester().pop();
79 }
80 }