001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    package org.apache.commons.betwixt.digester;
018    
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    import org.xml.sax.Attributes;
023    import org.xml.sax.SAXException;
024    
025    /**
026     * Digester Rule to process config elements.
027     * @since 0.7
028     * @author Brian Pugh
029     */
030    public class ConfigRule extends RuleSupport {
031        /** Logger. */
032        private static final Log log = LogFactory.getLog(ConfigRule.class);
033    
034        /** Base constructor. */
035        public ConfigRule() {
036        }
037        // Rule interface
038        //-------------------------------------------------------------------------
039        /**
040         * Process the beginning of this element.
041         *
042         * @param attributes The attribute list of this element
043         * @throws org.xml.sax.SAXException if the primitiveTypes attribute contains an invalid value
044         */
045        public void begin(Attributes attributes) throws SAXException {
046            String value = attributes.getValue("primitiveTypes");
047            if (value != null) {
048                if (value.equalsIgnoreCase("element")) {
049                            getXMLInfoDigester().setAttributesForPrimitives(false);
050                
051                } else if (value.equalsIgnoreCase("attribute")) {
052                    getXMLInfoDigester().setAttributesForPrimitives(true);
053                } else {
054                    throw new SAXException(
055                            "Invalid value inside element <betwixt-config> for attribute 'primitiveTypes'."
056                            + " Value should be 'element' or 'attribute'");
057                }
058            }
059            MultiMappingBeanInfoDigester digester = (MultiMappingBeanInfoDigester) getDigester();
060            getDigester().push(digester.getBeanInfoMap());
061        }
062        /**
063         * Process the end of this element.
064         */
065        public void end() {
066            Object top = getDigester().pop();
067        }
068    
069    
070    }