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