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.treeprocessor;
18:
19: import org.apache.avalon.framework.component.Component;
20: import org.apache.avalon.framework.component.ComponentException;
21: import org.apache.avalon.framework.component.ComponentSelector;
22: import org.apache.avalon.framework.thread.ThreadSafe;
23:
24: /**
25: *
26: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
27: * @version CVS $Id: SimpleSelectorProcessingNode.java 433543 2006-08-22 06:22:54Z crossley $
28: */
29:
30: public abstract class SimpleSelectorProcessingNode extends
31: SimpleParentProcessingNode {
32:
33: /** The node component name (e.g. action name, selector name, etc) */
34: protected String componentName;
35:
36: /** Selector where to get components from */
37: protected ComponentSelector selector;
38:
39: public SimpleSelectorProcessingNode(String componentName) {
40: this .componentName = componentName;
41: }
42:
43: public void setSelector(ComponentSelector selector)
44: throws ComponentException {
45: this .selector = selector;
46: }
47:
48: /**
49: * Tests if the component designated by this node using the selector and component name
50: * is <code>ThreadSafe</code>, and return it if true.
51: * <p>
52: * Note : this method must be called <i>after</i> <code>setSelector()</code>.
53: */
54: protected Component getThreadSafeComponent()
55: throws ComponentException {
56: return getThreadSafeComponent(this .componentName);
57: }
58:
59: /**
60: * Tests if the component designated by this node using the selector and component name
61: * is <code>ThreadSafe</code>, and return it if true.
62: * <p>
63: * Note : this method must be called <i>after</i> <code>setSelector()</code>.
64: */
65: protected Component getThreadSafeComponent(String name)
66: throws ComponentException {
67: Component component = this .selector.select(name);
68: if (component instanceof ThreadSafe) {
69: return component;
70: } else {
71: this.selector.release(component);
72: return null;
73: }
74: }
75: }
|