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
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 /**
26 * Digester Rule to process config elements.
27 * @since 0.7
28 * @author Brian Pugh
29 */
30 public class ConfigRule extends RuleSupport {
31 /** Logger. */
32 private static final Log log = LogFactory.getLog(ConfigRule.class);
33
34 /** Base constructor. */
35 public ConfigRule() {
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 * Process the end of this element.
64 */
65 public void end() {
66 Object top = getDigester().pop();
67 }
68
69
70 }