KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > digester > InfoRule


1 /*
2  * Copyright 2001-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 import org.apache.commons.betwixt.XMLBeanInfo;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 /** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p>
25   *
26   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
27   * @version $Revision: 1.9 $
28   */

29 public class InfoRule extends RuleSupport {
30
31     /** Logger */
32     private static final Log log = LogFactory.getLog( InfoRule.class );
33     /** <code>XMLBeanInfo</code> being created */
34     private XMLBeanInfo xmlBeanInfo;
35     
36     /** Base constructor */
37     public InfoRule() {
38     }
39     
40     // Rule interface
41
//-------------------------------------------------------------------------
42

43     /**
44      * Process the beginning of this element.
45      *
46      * @param attributes The attribute list of this element
47      * @throws SAXException if the primitiveTypes attribute contains an invalid value
48      */

49     public void begin(String JavaDoc name, String JavaDoc namespace, Attributes JavaDoc attributes) throws SAXException JavaDoc {
50         Class JavaDoc beanClass = getBeanClass();
51         
52         xmlBeanInfo = new XMLBeanInfo( beanClass );
53         
54         String JavaDoc value = attributes.getValue( "primitiveTypes" );
55         if ( value != null ) {
56             if ( value.equalsIgnoreCase( "element" ) ) {
57                 getXMLInfoDigester().setAttributesForPrimitives( false );
58                 
59             } else if ( value.equalsIgnoreCase( "attribute" ) ) {
60                 getXMLInfoDigester().setAttributesForPrimitives( true );
61                 
62             } else {
63                 throw new SAXException JavaDoc(
64                     "Invalid value inside element <info> for attribute 'primitiveTypes'."
65                     + " Value should be 'element' or 'attribute'" );
66             }
67         }
68         
69         getDigester().push(xmlBeanInfo);
70     }
71
72
73     /**
74      * Process the end of this element.
75      */

76     public void end(String JavaDoc name, String JavaDoc namespace) {
77         Object JavaDoc top = getDigester().pop();
78     }
79 }
80
Popular Tags