donaldp 02/05/18 19:00:43
Added: src/java/org/apache/avalon/phoenix/components/application
ListenerAccessor.java
Log:
Add in basic accessor for listener
component types.
Revision Changes Path
1.1
jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ListenerAccessor.java
Index: ListenerAccessor.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.phoenix.components.application;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.phoenix.components.lifecycle.ResourceAccessor;
import org.apache.avalon.phoenix.interfaces.ApplicationContext;
import org.apache.avalon.phoenix.metadata.BlockListenerMetaData;
/**
* The accessor used to access resources for a particular
* Block or Listener.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/05/19 02:00:43 $
*/
public class ListenerAccessor
extends AbstractLogEnabled
implements ResourceAccessor
{
private static final Resources REZ =
ResourceManager.getPackageResources( AppLifecycleHelper.class );
/**
* Context in which Blocks/Listeners operate.
*/
protected final ApplicationContext m_context;
public ListenerAccessor( final ApplicationContext context )
{
if( null == context )
{
throw new NullPointerException( "context" );
}
m_context = context;
}
/**
* Create Block for specified entry.
*
* @param entry the entry
* @return a new object
* @throws Exception
*/
public Object createObject( final Object entry )
throws Exception
{
final BlockListenerMetaData metaData = null;
final ClassLoader classLoader = m_context.getClassLoader();
final Class clazz =
classLoader.loadClass( metaData.getClassname() );
return clazz.newInstance();
}
/**
* Retrieve Logger for specified listener.
*
* @param entry the entry representing listener
* @return the new Logger object
* @throws Exception if an error occurs
*/
public Logger createLogger( final Object entry )
throws Exception
{
final BlockListenerMetaData metaData = (BlockListenerMetaData)entry;
final String name = metaData.getName();
return new LogKitLogger( m_context.getLogger( name ) );
}
public Context createContext( Object entry )
throws Exception
{
throw new UnsupportedOperationException();
}
public ComponentManager createComponentManager( final Object entry )
throws Exception
{
throw new UnsupportedOperationException();
}
public ServiceManager createServiceManager( final Object entry )
throws Exception
{
throw new UnsupportedOperationException();
}
/**
* Retrieve a configuration for specified component.
* If the configuration is missing then a exception
* is raised with an appropraite error message.
*
* @param entry the entry
* @return the Configuration object
* @throws ConfigurationException if an error occurs
*/
public Configuration createConfiguration( final Object entry )
throws Exception
{
final BlockListenerMetaData metaData = (BlockListenerMetaData)entry;
final String name = metaData.getName();
try
{
return m_context.getConfiguration( name );
}
catch( final ConfigurationException ce )
{
//Note that this shouldn't ever happen once we
//create a Config validator
final String message =
REZ.getString( "missing-listener-configuration",
name );
throw new ConfigurationException( message, ce );
}
}
public Parameters createParameters( final Object entry )
throws Exception
{
final Configuration configuration = createConfiguration( entry );
final Parameters parameters =
Parameters.fromConfiguration( configuration );
parameters.makeReadOnly();
return parameters;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>