01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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,
51: Attributes attributes) throws SAXException {
52: Class beanClass = getBeanClass();
53:
54: xmlBeanInfo = new XMLBeanInfo(beanClass);
55:
56: String value = attributes.getValue("primitiveTypes");
57: if (value != null) {
58: if (value.equalsIgnoreCase("element")) {
59: getXMLInfoDigester().setAttributesForPrimitives(false);
60:
61: } else if (value.equalsIgnoreCase("attribute")) {
62: getXMLInfoDigester().setAttributesForPrimitives(true);
63:
64: } else {
65: throw new SAXException(
66: "Invalid value inside element <info> for attribute 'primitiveTypes'."
67: + " Value should be 'element' or 'attribute'");
68: }
69: }
70:
71: getDigester().push(xmlBeanInfo);
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: }
|