1 55 package org.apache.avalon.framework.component; 56 57 import org.apache.avalon.framework.service.ServiceManager; 58 import org.apache.avalon.framework.service.ServiceException; 59 import org.apache.avalon.framework.service.ServiceSelector; 60 61 69 public class WrapperComponentManager 70 implements ComponentManager 71 { 72 75 private final ServiceManager m_manager; 76 77 88 public WrapperComponentManager( final ServiceManager manager ) 89 { 90 if( null == manager ) 91 { 92 throw new NullPointerException ( "manager" ); 93 } 94 95 m_manager = manager; 96 } 97 98 105 public Component lookup( final String key ) 106 throws ComponentException 107 { 108 try 109 { 110 final Object object = m_manager.lookup( key ); 111 if( object instanceof ServiceSelector ) 112 { 113 return new WrapperComponentSelector( key, (ServiceSelector)object ); 114 } 115 else if( object instanceof Component ) 116 { 117 return (Component)object; 118 } 119 } 120 catch( final ServiceException se ) 121 { 122 throw new ComponentException( se.getKey(), se.getMessage(), se.getCause() ); 123 } 124 125 final String message = "Role does not implement the Component " 126 + "interface and thus can not be accessed via ComponentManager"; 127 throw new ComponentException( key, message ); 128 } 129 130 136 public boolean hasComponent( final String key ) 137 { 138 return m_manager.hasService( key ); 139 } 140 141 150 public void release( final Component component ) 151 { 152 if( component instanceof WrapperComponentSelector ) 153 { 154 m_manager. 155 release( ( (WrapperComponentSelector)component ).getWrappedSelector() ); 156 } 157 else 158 { 159 m_manager.release( component ); 160 } 161 } 162 } 163 | Popular Tags |