Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ManagedPropertyRule |
|
| 2.6;2.6 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.shale.tiger.managed.rules; | |
19 | ||
20 | import org.apache.commons.digester.Rule; | |
21 | import org.apache.shale.tiger.managed.config.ManagedBeanConfig; | |
22 | import org.apache.shale.tiger.managed.config.ManagedPropertyConfig; | |
23 | import org.xml.sax.Attributes; | |
24 | ||
25 | /** | |
26 | * <p>Digester rule for processing a <code><managed-property></code> | |
27 | * element.</p> | |
28 | */ | |
29 | public class ManagedPropertyRule extends Rule { | |
30 | ||
31 | /** Creates a new instance of ManagedPropertyRule. */ | |
32 | 21 | public ManagedPropertyRule() { |
33 | 21 | } |
34 | ||
35 | /** <p>Fully qualified class name of our configuration element bean.</p> */ | |
36 | private static final String CLASS_NAME = | |
37 | "org.apache.shale.tiger.managed.config.ManagedPropertyConfig"; | |
38 | ||
39 | /** | |
40 | * <p>Create a new {@link ManagedPropertyConfig} and push it on to the | |
41 | * Digester stack.</p> | |
42 | * | |
43 | * @param namespace Namespace URI of the matching element | |
44 | * @param name Local name of the matching element | |
45 | * @param attributes Attribute list of the matching element | |
46 | * | |
47 | * @exception Exception if a parsing error occurs | |
48 | */ | |
49 | public void begin(String namespace, String name, | |
50 | Attributes attributes) throws Exception { | |
51 | ||
52 | 174 | Class clazz = digester.getClassLoader().loadClass(CLASS_NAME); |
53 | 174 | digester.push(clazz.newInstance()); |
54 | ||
55 | 174 | } |
56 | ||
57 | ||
58 | /** | |
59 | * <p>No body processing for this element.</p> | |
60 | * | |
61 | * @param namespace Namespace URI of the matching element | |
62 | * @param name Local name of the matching element | |
63 | * | |
64 | * @throws Exception if a parsing error occurs | |
65 | */ | |
66 | public void body(String namespace, String name) throws Exception { | |
67 | } | |
68 | ||
69 | ||
70 | /** | |
71 | * <p>Pop the {@link ManagedPropertyConfig} instance from the stack, | |
72 | * and either add it or merge it with parent information.</p> | |
73 | * | |
74 | * @param namespace Namespace URI of the matching element | |
75 | * @param name Local name of the matching element | |
76 | * | |
77 | * @exception IllegalStateException if the popped object is not | |
78 | * of the correct type | |
79 | * @exception Exception if any other error occurs | |
80 | */ | |
81 | public void end(String namespace, String name) throws Exception { | |
82 | ||
83 | 174 | ManagedPropertyConfig config = (ManagedPropertyConfig) digester.pop(); |
84 | 174 | ManagedBeanConfig parent = (ManagedBeanConfig) digester.peek(); |
85 | 174 | ManagedPropertyConfig previous = parent.getProperty(config.getName()); |
86 | 174 | if (previous == null) { |
87 | 174 | parent.addProperty(config); |
88 | 174 | } else { |
89 | merge(config, previous); | |
90 | } | |
91 | ||
92 | 174 | } |
93 | ||
94 | ||
95 | /** | |
96 | * <p>Merge properties from <code>config</code> into | |
97 | * <code>previous</code>.</p> | |
98 | * | |
99 | * @param config Newly constructed bean | |
100 | * @param previous Previous bean to merge into | |
101 | */ | |
102 | static void merge(ManagedPropertyConfig config, ManagedPropertyConfig previous) { | |
103 | ||
104 | 97 | if (config.getType() != null) { |
105 | 97 | previous.setType(config.getType()); |
106 | } | |
107 | 97 | if (config.getValue() != null) { |
108 | 97 | previous.setValue(config.getValue()); |
109 | } | |
110 | 97 | if (config.isNullValue()) { |
111 | previous.setNullValue(true); | |
112 | } | |
113 | 97 | if (config.getListEntries() != null) { |
114 | if (previous.getListEntries() != null) { | |
115 | ListEntriesRule.merge(config.getListEntries(), previous.getListEntries()); | |
116 | } else { | |
117 | previous.setListEntries(config.getListEntries()); | |
118 | } | |
119 | } | |
120 | 97 | if (config.getMapEntries() != null) { |
121 | if (previous.getMapEntries() != null) { | |
122 | MapEntriesRule.merge(config.getMapEntries(), previous.getMapEntries()); | |
123 | } else { | |
124 | previous.setMapEntries(config.getMapEntries()); | |
125 | } | |
126 | } | |
127 | ||
128 | 97 | } |
129 | ||
130 | ||
131 | } |