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.source.impl;
18:
19: import org.apache.cocoon.components.source.SourceDescriptor;
20: import org.apache.cocoon.components.source.helpers.SourceProperty;
21: import org.apache.excalibur.source.Source;
22: import org.apache.excalibur.source.SourceException;
23:
24: /**
25: * Abstract base class SourceDescriptors that want to
26: * configure the set of properties they handle beforehand.
27: *
28: * <p>
29: * Knowing which properties an inspector handles beforehand
30: * greatly improves property management performance.
31: * </p>
32: *
33: * @author <a href="mailto:unico@apache.org">Unico Hommes</a>
34: */
35: public abstract class AbstractConfigurableSourceDescriptor extends
36: AbstractConfigurableSourceInspector implements SourceDescriptor {
37:
38: // ---------------------------------------------------- SourceDescriptor methods
39:
40: /**
41: * Checks if this SourceDescriptor is configured to handle the
42: * given property and if so forwards the call to
43: * <code>doRemoveSourceProperty()</code>.
44: */
45: public final void removeSourceProperty(Source source,
46: String namespace, String name) throws SourceException {
47:
48: if (handlesProperty(namespace, name)) {
49: if (getLogger().isDebugEnabled()) {
50: getLogger().debug(
51: "Removing property " + namespace + "#" + name
52: + " from source " + source.getURI());
53: }
54: doRemoveSourceProperty(source, namespace, name);
55: }
56: }
57:
58: /**
59: * Checks if this SourceDescriptor is configured to handle the
60: * given property and if so forwards the call to
61: * <code>doSetSourceProperty()</code>.
62: */
63: public final void setSourceProperty(Source source,
64: SourceProperty property) throws SourceException {
65:
66: if (handlesProperty(property.getNamespace(), property.getName())) {
67: if (getLogger().isDebugEnabled()) {
68: getLogger().debug(
69: "Setting property " + property.getNamespace()
70: + "#" + property.getName()
71: + " on source " + source.getURI());
72: }
73: doSetSourceProperty(source, property);
74: }
75: }
76:
77: // ---------------------------------------------------- abstract methods
78:
79: /**
80: * Do the actual work of removing the given property from the provided Source.
81: */
82: protected abstract void doRemoveSourceProperty(Source source,
83: String namespace, String name) throws SourceException;
84:
85: /**
86: * Do the actual work of setting the provided SourceProperty on the given Source.
87: */
88: protected abstract void doSetSourceProperty(Source source,
89: SourceProperty property) throws SourceException;
90:
91: }
|