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 import org.apache.commons.betwixt.XMLBeanInfo; 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 /** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p> 026 * 027 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 028 * @version $Revision: 438373 $ 029 */ 030 public class InfoRule extends RuleSupport { 031 032 /** Logger */ 033 private static final Log log = LogFactory.getLog( InfoRule.class ); 034 /** <code>XMLBeanInfo</code> being created */ 035 private XMLBeanInfo xmlBeanInfo; 036 037 /** Base constructor */ 038 public InfoRule() { 039 } 040 041 // Rule interface 042 //------------------------------------------------------------------------- 043 044 /** 045 * Process the beginning of this element. 046 * 047 * @param attributes The attribute list of this element 048 * @throws SAXException if the primitiveTypes attribute contains an invalid value 049 */ 050 public void begin(String name, String namespace, Attributes attributes) throws SAXException { 051 Class beanClass = getBeanClass(); 052 053 xmlBeanInfo = new XMLBeanInfo( beanClass ); 054 055 String value = attributes.getValue( "primitiveTypes" ); 056 if ( value != null ) { 057 if ( value.equalsIgnoreCase( "element" ) ) { 058 getXMLInfoDigester().setAttributesForPrimitives( false ); 059 060 } else if ( value.equalsIgnoreCase( "attribute" ) ) { 061 getXMLInfoDigester().setAttributesForPrimitives( true ); 062 063 } else { 064 throw new SAXException( 065 "Invalid value inside element <info> for attribute 'primitiveTypes'." 066 + " Value should be 'element' or 'attribute'" ); 067 } 068 } 069 070 getDigester().push(xmlBeanInfo); 071 } 072 073 074 /** 075 * Process the end of this element. 076 */ 077 public void end(String name, String namespace) { 078 Object top = getDigester().pop(); 079 } 080 }