Hi Siegfried, Siegfried Goeschl wrote:
please send me the patch regarding the TurbineYaafiService ... or what was wrong with the implementation?
Here we go. I implemented AvalonComponentService and changed the return types, parameter types and exception types to comply with that. Then I shifted the logger creation into the configuration creation. The logger uses "avalon" now as category which is the value of AVALON_LOG_CATEGORY as defined in the interface.
I hope everything I did is ok with you. I look forward to your comments. Bye, Thomas.
Index: /yaafi/contrib/TurbineYaafiComponentService.java =================================================================== --- /yaafi/contrib/TurbineYaafiComponentService.java (revision 388478) +++ /yaafi/contrib/TurbineYaafiComponentService.java (working copy) @@ -22,7 +22,10 @@ import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.component.Component; +import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.logger.Log4JLogger; +import org.apache.avalon.framework.service.ServiceException; import org.apache.commons.configuration.Configuration; import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; import org.apache.fulcrum.yaafi.framework.factory.ServiceContainerConfiguration; @@ -31,28 +34,30 @@ import org.apache.turbine.Turbine; import org.apache.turbine.services.InitializationException; import org.apache.turbine.services.TurbineBaseService; +import org.apache.turbine.services.avaloncomponent.AvalonComponentService; import org.apache.turbine.services.servlet.TurbineServlet; /** * An implementation of Turbine service initializing the YAAFI container * * @author <a href="mailto:[EMAIL PROTECTED]">Siegfried Goeschl</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Thomas Vandahl</a> */ public class TurbineYaafiComponentService extends TurbineBaseService - implements YaafiComponentService, Initializable, Disposable + implements AvalonComponentService, Initializable, Disposable { - /** property to lookup the container configuration file */ - public final String CONTAINER_CONFIGURATION_KEY = "containerConfiguration"; + /** property to lookup the container configuration file */ + public final String CONTAINER_CONFIGURATION_KEY = "containerConfiguration"; - /** the default value for the container configuration file */ - public final String CONTAINER_CONFIGURATION_VALUE = "/WEB-INF/conf/containerConfiguration.xml"; + /** the default value for the container configuration file */ + public final String CONTAINER_CONFIGURATION_VALUE = "/WEB-INF/conf/containerConfiguration.xml"; /** property to lookup the properties file */ - public final String COMPONENT_PARAMETERS_KEY = "parameters"; + public final String COMPONENT_PARAMETERS_KEY = "parameters"; - /** the default value for the parameter file */ - public final String COMPONENT_PARAMETERS_VALUE = "/WEB-INF/conf/parameters.properties"; + /** the default value for the parameter file */ + public final String COMPONENT_PARAMETERS_VALUE = "/WEB-INF/conf/parameters.properties"; /** YAFFI container */ private ServiceContainer container; @@ -75,7 +80,7 @@ * * @throws InitializationException Something went wrong in the init stage */ - public void init( Object data ) + public void init() throws InitializationException { try @@ -134,22 +139,15 @@ this.logger.info( "Using the following home : " + home.getAbsolutePath() ); // create the configuration for YAAFI - - ServiceContainerConfiguration config = this.createServiceContainerConfiguration(conf); - - config.setLogger( this.createAvalonLogger( "yaafi" ) ); - config.setApplicationRootDir( home ); + ServiceContainerConfiguration config = this.createServiceContainerConfiguration(conf, home.getAbsolutePath()); try { - this.container = ServiceContainerFactory.create( - config - ); + this.container = ServiceContainerFactory.create(config); } catch (Throwable t) { - String msg = "Initializing YAAFI failed"; - this.logger.error(msg,t); + this.logger.error("Initializing YAAFI failed", t); } } @@ -172,90 +170,98 @@ * @return an instance of the named component * @throws Exception generic exception */ - public Object lookup(String path) throws Exception + public Component lookup(String path) throws ComponentException { - return this.container.lookup(path); + try + { + return (Component)this.container.lookup(path); + } + catch (ServiceException e) + { + throw new ComponentException(e.getKey(), e.getMessage(), e); + } } /** * Releases the component * - * @param source. The path to the handler for this component For example, if the object is a - * java.sql.Connection object sourced from the "/turbine-merlin/datasource" - * component, the call would be :- release("/turbine-merlin/datasource", conn); * @param component the component to release */ - public void release(Object component) + public void release(Component component) { this.container.release( component ); } - + /** * Create a ServiceContainerConfiguration based on the Turbine configuration - * + * * @param conf the Turbine configuration + * @param appRoot the absolute path to the application root directory * @return the YAAFI configuration * @throws IOException creating the YAAFI configuration failed */ - protected ServiceContainerConfiguration createServiceContainerConfiguration( Configuration conf ) - throws IOException + protected ServiceContainerConfiguration createServiceContainerConfiguration( Configuration conf, String appRoot ) + throws IOException { ServiceContainerConfiguration result = new ServiceContainerConfiguration(); + result.setLogger( this.createAvalonLogger(AVALON_LOG_CATEGORY)); + result.setApplicationRootDir(appRoot); + // are we using a "containerConfiguration.xml" ?! - + if( conf.containsKey(CONTAINER_CONFIGURATION_KEY) ) { - // determine the container configuration file - - String containerConfiguration = conf.getString( - CONTAINER_CONFIGURATION_KEY - ); - - result.loadContainerConfiguration(containerConfiguration); - } - else if( conf.containsKey(COMPONENT_ROLE_KEY) ) - { - // determine the location of the role configuraton file - - String roleConfigurationFileName = conf.getString( - COMPONENT_ROLE_KEY, - COMPONENT_ROLE_VALUE - ); - - // determine the location of component configuration file - - String componentConfigurationFileName = conf.getString( - COMPONENT_CONFIG_KEY, - COMPONENT_CONFIG_VALUE - ); - - // determine the location of parameters file - - String parametersFileName = conf.getString( - COMPONENT_PARAMETERS_KEY, - COMPONENT_PARAMETERS_VALUE - ); - - result.setComponentRolesLocation( roleConfigurationFileName ); - result.setComponentConfigurationLocation( componentConfigurationFileName ); - result.setParametersLocation( parametersFileName ); - } - else + // determine the container configuration file + + String containerConfiguration = conf.getString( + CONTAINER_CONFIGURATION_KEY + ); + + result.loadContainerConfiguration(containerConfiguration); + } + else if( conf.containsKey(COMPONENT_ROLE_KEY) ) { - // determine the container configuration file - - String containerConfiguration = conf.getString( - CONTAINER_CONFIGURATION_KEY, - CONTAINER_CONFIGURATION_VALUE - ); - - result.loadContainerConfiguration(containerConfiguration); - } - + // determine the location of the role configuraton file + + String roleConfigurationFileName = conf.getString( + COMPONENT_ROLE_KEY, + COMPONENT_ROLE_VALUE + ); + + // determine the location of component configuration file + + String componentConfigurationFileName = conf.getString( + COMPONENT_CONFIG_KEY, + COMPONENT_CONFIG_VALUE + ); + + // determine the location of parameters file + + String parametersFileName = conf.getString( + COMPONENT_PARAMETERS_KEY, + COMPONENT_PARAMETERS_VALUE + ); + + result.setComponentRolesLocation( roleConfigurationFileName ); + result.setComponentConfigurationLocation( componentConfigurationFileName ); + result.setParametersLocation( parametersFileName ); + } + else + { + // determine the container configuration file + + String containerConfiguration = conf.getString( + CONTAINER_CONFIGURATION_KEY, + CONTAINER_CONFIGURATION_VALUE + ); + + result.loadContainerConfiguration(containerConfiguration); + } + return result; } - + /** * Create the Avalon logger to be passed to YAAFI * @param name the name of the logger @@ -263,6 +269,6 @@ */ protected org.apache.avalon.framework.logger.Logger createAvalonLogger( String name ) { - return new Log4JLogger( Logger.getLogger( name ) ); + return new Log4JLogger( Logger.getLogger( name ) ); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]