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: package org.apache.cocoon.components;
18:
19: import org.apache.avalon.framework.configuration.DefaultConfiguration;
20: import org.apache.avalon.framework.configuration.NamespacedSAXConfigurationHandler;
21: import org.apache.avalon.framework.logger.Logger;
22: import org.apache.cocoon.util.Settings;
23: import org.apache.cocoon.util.location.LocatedRuntimeException;
24:
25: /**
26: * Property Aware SAX Configuration Handler.
27: * This component extends the {@link org.apache.avalon.framework.configuration.SAXConfigurationHandler}
28: * by creating configurations that can contain placeholders for System Properties.
29: *
30: * @version SVN $Id: $
31: */
32: public class PropertyAwareNamespacedSAXConfigurationHandler extends
33: NamespacedSAXConfigurationHandler {
34:
35: private Settings settings;
36: private Logger logger;
37:
38: public PropertyAwareNamespacedSAXConfigurationHandler(
39: Settings settings, Logger logger) {
40: super ();
41: this .settings = settings;
42: this .logger = logger;
43: }
44:
45: /**
46: * Create a new <code>PropertyAwareConfiguration</code> with the specified
47: * local name and location.
48: *
49: * @param localName a <code>String</code> value
50: * @param location a <code>String</code> value
51: * @return a <code>DefaultConfiguration</code> value
52: */
53: protected DefaultConfiguration createConfiguration(
54: final String localName, final String location) {
55: return new PropertyAwareConfiguration(localName, location,
56: this .settings, this .logger);
57: }
58:
59: /**
60: * Create a new <code>PropertyAwareConfiguration</code> with the specified
61: * local name and location.
62: *
63: * @param localName a <code>String</code> value
64: * @param location a <code>String</code> value
65: * @return a <code>DefaultConfiguration</code> value
66: */
67: protected DefaultConfiguration createConfiguration(
68: final String localName, final String namespaceURI,
69: final String location) {
70: DefaultConfiguration config = super .createConfiguration(
71: localName, namespaceURI, location);
72: try {
73: return new PropertyAwareConfiguration(config,
74: this .settings, this .logger);
75: } catch (Exception e) {
76: // This will never happen as the DefaultConfiguration constructor will always create a
77: // proper object from which to create the PropertyAwareConfiguration
78: // But if it somehow does, just throw a generic runtime exception
79: throw new LocatedRuntimeException("", e);
80: }
81: }
82: }
|