1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
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 // Rule interface
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 }