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.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21: import org.xml.sax.Attributes;
22: import org.xml.sax.SAXException;
23:
24: /**
25: * Digester Rule to process config elements.
26: * @since 0.7
27: * @author Brian Pugh
28: */
29: public class ConfigRule extends RuleSupport {
30: /** Logger. */
31: private static final Log log = LogFactory.getLog(ConfigRule.class);
32:
33: /** Base constructor. */
34: public ConfigRule() {
35: }
36:
37: // Rule interface
38: //-------------------------------------------------------------------------
39: /**
40: * Process the beginning of this element.
41: *
42: * @param attributes The attribute list of this element
43: * @throws org.xml.sax.SAXException if the primitiveTypes attribute contains an invalid value
44: */
45: public void begin(Attributes attributes) throws SAXException {
46: String value = attributes.getValue("primitiveTypes");
47: if (value != null) {
48: if (value.equalsIgnoreCase("element")) {
49: getXMLInfoDigester().setAttributesForPrimitives(false);
50:
51: } else if (value.equalsIgnoreCase("attribute")) {
52: getXMLInfoDigester().setAttributesForPrimitives(true);
53: } else {
54: throw new SAXException(
55: "Invalid value inside element <betwixt-config> for attribute 'primitiveTypes'."
56: + " Value should be 'element' or 'attribute'");
57: }
58: }
59: MultiMappingBeanInfoDigester digester = (MultiMappingBeanInfoDigester) getDigester();
60: getDigester().push(digester.getBeanInfoMap());
61: }
62:
63: /**
64: * Process the end of this element.
65: */
66: public void end() {
67: Object top = getDigester().pop();
68: }
69:
70: }
|