KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > source > impl > AbstractConfigurableSourceDescriptor


1 /*
2  * Copyright 1999-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.cocoon.components.source.impl;
17
18 import org.apache.cocoon.components.source.SourceDescriptor;
19 import org.apache.cocoon.components.source.helpers.SourceProperty;
20 import org.apache.excalibur.source.Source;
21 import org.apache.excalibur.source.SourceException;
22
23 /**
24  * Abstract base class SourceDescriptors that want to
25  * configure the set of properties they handle beforehand.
26  *
27  * <p>
28  * Knowing which properties an inspector handles beforehand
29  * greatly improves property management performance.
30  * </p>
31  *
32  * @author <a HREF="mailto:unico@apache.org">Unico Hommes</a>
33  */

34 public abstract class AbstractConfigurableSourceDescriptor
35 extends AbstractConfigurableSourceInspector implements SourceDescriptor {
36
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, String JavaDoc namespace, String JavaDoc name)
46         throws SourceException {
47         
48         if (handlesProperty(namespace,name)) {
49             if (getLogger().isDebugEnabled()) {
50                 getLogger().debug("Removing property " + namespace + "#"
51                     + name + " from source " + source.getURI());
52             }
53             doRemoveSourceProperty(source,namespace,name);
54         }
55     }
56
57     /**
58      * Checks if this SourceDescriptor is configured to handle the
59      * given property and if so forwards the call to
60      * <code>doSetSourceProperty()</code>.
61      */

62     public final void setSourceProperty(Source source, SourceProperty property)
63         throws SourceException {
64         
65         if (handlesProperty(property.getNamespace(),property.getName())) {
66             if (getLogger().isDebugEnabled()) {
67                 getLogger().debug("Setting property " + property.getNamespace() + "#"
68                     + property.getName() + " on source " + source.getURI());
69             }
70             doSetSourceProperty(source,property);
71         }
72     }
73
74     // ---------------------------------------------------- abstract methods
75

76     /**
77      * Do the actual work of removing the given property from the provided Source.
78      */

79     protected abstract void doRemoveSourceProperty(Source source, String JavaDoc namespace,String JavaDoc name)
80         throws SourceException;
81
82     /**
83      * Do the actual work of setting the provided SourceProperty on the given Source.
84      */

85     protected abstract void doSetSourceProperty(Source source, SourceProperty property)
86         throws SourceException;
87
88 }
89
Popular Tags