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