1 55 56 package org.apache.avalon.framework.component; 57 58 import org.apache.avalon.framework.service.ServiceSelector; 59 import org.apache.avalon.framework.service.ServiceException; 60 61 69 public class WrapperComponentSelector 70 implements ComponentSelector 71 { 72 75 private final ServiceSelector m_selector; 76 77 80 private final String m_key; 81 82 88 public WrapperComponentSelector( final String key, 89 final ServiceSelector selector ) 90 { 91 if( null == key ) 92 { 93 throw new NullPointerException ( "key" ); 94 } 95 if( null == selector ) 96 { 97 throw new NullPointerException ( "selector" ); 98 } 99 100 m_key = key + "/"; 101 m_selector = selector; 102 } 103 104 111 public Component select( final Object policy ) 112 throws ComponentException 113 { 114 try 115 { 116 final Object object = m_selector.select( policy ); 117 if( object instanceof Component ) 118 { 119 return (Component)object; 120 } 121 } 122 catch( final ServiceException se ) 123 { 124 throw new ComponentException( m_key + policy, se.getMessage(), se ); 125 } 126 127 final String message = "Role does not implement the Component " 128 + "interface and thus can not be accessed via ComponentSelector"; 129 throw new ComponentException( m_key + policy, message ); 130 } 131 132 138 public boolean hasComponent( final Object policy ) 139 { 140 return m_selector.isSelectable( policy ); 141 } 142 143 152 public void release( final Component object ) 153 { 154 m_selector.release( object ); 155 } 156 157 164 ServiceSelector getWrappedSelector() 165 { 166 return m_selector; 167 } 168 } 169 | Popular Tags |