01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.catalina.startup;
19:
20: import org.xml.sax.Attributes;
21:
22: import org.apache.tomcat.util.IntrospectionUtils;
23: import org.apache.tomcat.util.digester.Rule;
24: import java.util.HashMap;
25:
26: /**
27: * Rule that uses the introspection utils to set properties.
28: *
29: * @author Remy Maucherat
30: * @author Filip Hanik
31: */
32: public class SetAllPropertiesRule extends Rule {
33:
34: // ----------------------------------------------------------- Constructors
35: public SetAllPropertiesRule() {
36: }
37:
38: public SetAllPropertiesRule(String[] exclude) {
39: for (int i = 0; i < exclude.length; i++)
40: if (exclude[i] != null)
41: this .excludes.put(exclude[i], exclude[i]);
42: }
43:
44: // ----------------------------------------------------- Instance Variables
45: protected HashMap<String, String> excludes = new HashMap<String, String>();
46:
47: // --------------------------------------------------------- Public Methods
48:
49: /**
50: * Handle the beginning of an XML element.
51: *
52: * @param attributes The attributes of this element
53: *
54: * @exception Exception if a processing error occurs
55: */
56: public void begin(String namespace, String nameX,
57: Attributes attributes) throws Exception {
58:
59: for (int i = 0; i < attributes.getLength(); i++) {
60: String name = attributes.getLocalName(i);
61: if ("".equals(name)) {
62: name = attributes.getQName(i);
63: }
64: String value = attributes.getValue(i);
65: if (!excludes.containsKey(name))
66: IntrospectionUtils.setProperty(digester.peek(), name,
67: value);
68: }
69:
70: }
71:
72: }
|