1 55 package org.apache.avalon.framework.service; 56 57 import org.apache.avalon.framework.component.Component; 58 import org.apache.avalon.framework.component.ComponentException; 59 import org.apache.avalon.framework.component.ComponentManager; 60 import org.apache.avalon.framework.component.ComponentSelector; 61 62 70 public class WrapperServiceManager 71 implements ServiceManager 72 { 73 76 private final ComponentManager m_componentManager; 77 78 83 public WrapperServiceManager( final ComponentManager componentManager ) 84 { 85 if( null == componentManager ) 86 { 87 throw new NullPointerException ( "componentManager" ); 88 } 89 90 m_componentManager = componentManager; 91 } 92 93 101 public Object lookup( final String key ) 102 throws ServiceException 103 { 104 try 105 { 106 final Object service = m_componentManager.lookup( key ); 107 if( service instanceof ComponentSelector ) 108 { 109 return new WrapperServiceSelector( key, (ComponentSelector)service ); 110 } 111 else 112 { 113 return service; 114 } 115 } 116 catch( final ComponentException ce ) 117 { 118 throw new ServiceException( key, ce.getMessage(), ce ); 119 } 120 } 121 122 128 public boolean hasService( final String key ) 129 { 130 return m_componentManager.hasComponent( key ); 131 } 132 133 138 public void release( final Object service ) 139 { 140 if ( service instanceof WrapperServiceSelector ) 141 { 142 m_componentManager. 143 release( ((WrapperServiceSelector)service).getWrappedSelector() ); 144 } 145 else 146 { 147 m_componentManager.release( (Component)service ); 148 } 149 } 150 } 151 | Popular Tags |