Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
InfoRule |
|
| 2.3333333333333335;2.333 |
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; |
|
22 | import org.xml.sax.SAXException; |
|
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: 155402 $ |
|
28 | */ |
|
29 | 429 | public class InfoRule extends RuleSupport { |
30 | ||
31 | /** Logger */ |
|
32 | 429 | private static final Log log = LogFactory.getLog( InfoRule.class ); |
33 | /** <code>XMLBeanInfo</code> being created */ |
|
34 | private XMLBeanInfo xmlBeanInfo; |
|
35 | ||
36 | /** Base constructor */ |
|
37 | 1209 | public InfoRule() { |
38 | 1209 | } |
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 name, String namespace, Attributes attributes) throws SAXException { |
|
50 | 2067 | Class beanClass = getBeanClass(); |
51 | ||
52 | 2067 | xmlBeanInfo = new XMLBeanInfo( beanClass ); |
53 | ||
54 | 2067 | String value = attributes.getValue( "primitiveTypes" ); |
55 | 2067 | if ( value != null ) { |
56 | 780 | if ( value.equalsIgnoreCase( "element" ) ) { |
57 | 533 | getXMLInfoDigester().setAttributesForPrimitives( false ); |
58 | ||
59 | 247 | } else if ( value.equalsIgnoreCase( "attribute" ) ) { |
60 | 247 | getXMLInfoDigester().setAttributesForPrimitives( true ); |
61 | ||
62 | } else { |
|
63 | 0 | throw new SAXException( |
64 | 0 | "Invalid value inside element <info> for attribute 'primitiveTypes'." |
65 | + " Value should be 'element' or 'attribute'" ); |
|
66 | } |
|
67 | } |
|
68 | ||
69 | 2067 | getDigester().push(xmlBeanInfo); |
70 | 2067 | } |
71 | ||
72 | ||
73 | /** |
|
74 | * Process the end of this element. |
|
75 | */ |
|
76 | public void end(String name, String namespace) { |
|
77 | 2054 | Object top = getDigester().pop(); |
78 | 2054 | } |
79 | } |