View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  package org.apache.commons.betwixt.digester;
17  
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      // Rule interface
37      //-------------------------------------------------------------------------
38      /***
39       * Process the beginning of this element.
40       *
41       * @param attributes The attribute list of this element
42       * @throws org.xml.sax.SAXException if the primitiveTypes attribute contains an invalid value
43       */
44      public void begin(Attributes attributes) throws SAXException {
45          String value = attributes.getValue("primitiveTypes");
46          if (value != null) {
47              if (value.equalsIgnoreCase("element")) {
48                  	getXMLInfoDigester().setAttributesForPrimitives(false);
49              
50              } else if (value.equalsIgnoreCase("attribute")) {
51                  getXMLInfoDigester().setAttributesForPrimitives(true);
52              } else {
53                  throw new SAXException(
54                          "Invalid value inside element <betwixt-config> for attribute 'primitiveTypes'."
55                          + " Value should be 'element' or 'attribute'");
56              }
57          }
58          MultiMappingBeanInfoDigester digester = (MultiMappingBeanInfoDigester) getDigester();
59          getDigester().push(digester.getBeanInfoMap());
60      }
61      /***
62       * Process the end of this element.
63       */
64      public void end() {
65          Object top = getDigester().pop();
66      }
67  
68  
69  }