You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by ha...@apache.org on 2004/07/03 00:50:42 UTC
svn commit: rev 22493 - in excalibur/branches/fortress-experiments: container-api/src/java/org/apache/avalon/fortress container-impl/src/java/org/apache/avalon/fortress/impl container-impl/src/java/org/apache/avalon/fortress/impl/handler
Author: hammett
Date: Fri Jul 2 15:50:41 2004
New Revision: 22493
Added:
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java (contents, props changed)
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java (contents, props changed)
Modified:
excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/Container.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentHandler.java
Log:
Initial work on events for Fortress.
Modified: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/Container.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/Container.java (original)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/Container.java Fri Jul 2 15:50:41 2004
@@ -33,7 +33,7 @@
* Container's internals, we currently feel that we have insufficient use case
* information to determine the generic form of the container internals.</p>
*
- * @author <a href="mailto:dev@avalon.apache.org">The Avalon Team</a>
+ * @author <a href="mailto:dev@excalibur.apache.org">The Excalibur Team</a>
* @version CVS $Revision: 1.10 $ $Date: 2004/02/28 15:16:24 $
* @see ContainerConstants for the contract surrounding the Container context
* @see <a href="http://avalon.apache.org/framework/guide-cop-in-avalon.html">COP In Avalon</a>
@@ -75,5 +75,12 @@
* @return true if a reference to the role exists.
*/
boolean has( String key, Object hint );
+
+ /**
+ * Pending
+ *
+ * @return
+ */
+ EventManager getEventManager();
}
Added: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/ContainerListener.java Fri Jul 2 15:50:41 2004
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.fortress;
+
+/**
+ * Pending
+ *
+ */
+public interface ContainerListener
+{
+ /**
+ * Pending
+ *
+ * @param entry
+ * @param instance
+ * @return
+ */
+ Object componentCreated( MetaInfoEntry entry, Object instance );
+
+ /**
+ * Pending
+ *
+ * @param entry
+ * @param instance
+ */
+ void componentDestroyed( MetaInfoEntry entry, Object instance );
+}
Added: excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java
==============================================================================
--- (empty file)
+++ excalibur/branches/fortress-experiments/container-api/src/java/org/apache/avalon/fortress/EventManager.java Fri Jul 2 15:50:41 2004
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.avalon.fortress;
+
+/**
+ * Pending
+ *
+ */
+public interface EventManager
+{
+ void addListener( ContainerListener listener );
+
+ void removeListener( ContainerListener listener );
+
+ /**
+ * Pending
+ *
+ * @param newInstance
+ * @return
+ */
+ Object fireComponentCreated(Object newInstance);
+
+ /**
+ * Pending
+ *
+ * @param newInstance
+ */
+ void fireComponentDestroyed(Object newInstance);
+
+
+}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java Fri Jul 2 15:50:41 2004
@@ -336,7 +336,7 @@
* @return the component handler
* @throws Exception if unable to provide a componenthandler
*/
- private ComponentHandler getComponentHandler( final MetaInfoEntry metaEntry,
+ protected ComponentHandler getComponentHandler( final MetaInfoEntry metaEntry,
final ComponentHandlerMetaData metaData )
throws Exception
{
@@ -348,7 +348,7 @@
try
{
final ObjectFactory factory =
- createObjectFactory( classname, configuration );
+ createObjectFactory( classname, configuration, metaEntry );
// create the appropriate handler instance
final ComponentHandler targetHandler =
@@ -420,7 +420,8 @@
* @throws ClassNotFoundException if the specified class does not exist
*/
protected ObjectFactory createObjectFactory( final String classname,
- final Configuration configuration )
+ final Configuration configuration,
+ final MetaInfoEntry metaEntry )
throws Exception
{
if ( m_componentContext == null )
@@ -436,7 +437,8 @@
final ComponentFactory componentFactory =
new ComponentFactory( clazz, configuration,
m_serviceManager, m_componentContext,
- m_loggerManager, m_extManager );
+ m_loggerManager, m_extManager, metaEntry, this );
+
return getProxyManager().getWrappedObjectFactory( componentFactory );
}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java Fri Jul 2 15:50:41 2004
@@ -91,35 +91,7 @@
throws ConfigurationException
{
interpretProxy( config.getAttribute("proxy-type", "discover") );
-
- final Configuration[] elements = config.getChildren();
- for ( int i = 0; i < elements.length; i++ )
- {
- final Configuration element = elements[i];
- final String hint = element.getAttribute( "id", null );
- if ( null == hint )
- {
- // Only components with an id attribute are treated as components.
- getLogger().debug( "Ignoring configuration for component, " + element.getName()
- + ", because the id attribute is missing." );
- }
- else
- {
- final String classname = getClassname( element );
- final int activation = getActivation( element );
- final ComponentHandlerMetaData metaData =
- new ComponentHandlerMetaData( hint, classname, element, activation );
-
- try
- {
- addComponent( metaData );
- }
- catch ( Exception e )
- {
- throw new ConfigurationException( "Could not add component", e );
- }
- }
- }
+ addComponents( config );
}
/**
@@ -149,13 +121,54 @@
}
}
+ /**
+ * Iterates throught nodes, which represent components, adding the
+ * component/configuration data to container.
+ *
+ * @param config Configuration representing the content in xconf file
+ * @throws ConfigurationException
+ */
+ protected void addComponents(final Configuration config) throws ConfigurationException
+ {
+ final Configuration[] elements = config.getChildren();
+
+ for ( int i = 0; i < elements.length; i++ )
+ {
+ final Configuration element = elements[i];
+ final String hint = element.getAttribute( "id", null );
+
+ if ( null == hint )
+ {
+ // Only components with an id attribute are treated as components.
+ getLogger().debug( "Ignoring configuration for component, " + element.getName()
+ + ", because the id attribute is missing." );
+ }
+ else
+ {
+ final String classname = getClassname( element );
+ final int activation = getActivation( element );
+ final ComponentHandlerMetaData metaData =
+ new ComponentHandlerMetaData( hint, classname, element, activation );
+
+ try
+ {
+ addComponent( metaData );
+ }
+ catch ( Exception e )
+ {
+ throw new ConfigurationException( "Could not add component", e );
+ }
+ }
+ }
+ }
+
/**
* Retrieve the classname for component configuration.
*
* @param config the component configuration
* @return the class name
*/
- private String getClassname( final Configuration config )
+ protected String getClassname( final Configuration config )
throws ConfigurationException
{
final String className;
@@ -202,7 +215,7 @@
* @throws ConfigurationException if the handler specifies an unknown
* activation policy
*/
- private int getActivation( final Configuration component )
+ protected int getActivation( final Configuration component )
throws ConfigurationException
{
final String activation = component.getAttribute( "activation", "background" );
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/DefaultECMContainer.java Fri Jul 2 15:50:41 2004
@@ -86,7 +86,7 @@
* @param config the component configuration
* @return the class name
*/
- private String getClassname( final Configuration config )
+ protected String getClassname( final Configuration config )
throws ConfigurationException {
final String className;
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java Fri Jul 2 15:50:41 2004
@@ -21,6 +21,8 @@
import java.lang.reflect.Method;
import org.apache.avalon.excalibur.logger.LoggerManager;
+import org.apache.avalon.fortress.Container;
+import org.apache.avalon.fortress.MetaInfoEntry;
import org.apache.avalon.fortress.util.LifecycleExtensionManager;
import org.apache.avalon.framework.CascadingException;
import org.apache.avalon.framework.component.Composable;
@@ -53,9 +55,7 @@
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision: 1.31 $ $Date: 2004/04/13 13:17:54 $
*/
-public final class ComponentFactory
- extends AbstractLogEnabledInstrumentable
- implements ObjectFactory
+public final class ComponentFactory extends AbstractLogEnabledInstrumentable implements ObjectFactory
{
private final CounterInstrument m_newInstance;
private final CounterInstrument m_dispose;
@@ -89,6 +89,14 @@
*/
private final Logger m_componentLogger;
+ /** The container
+ */
+ private final Container m_container;
+
+ /** Component info - used only for raising events
+ */
+ private final MetaInfoEntry m_metaEntry;
+
/**
* The class info for creating the component
*/
@@ -106,44 +114,48 @@
* @param context the <code>Context</code> to pass to <code>Contexutalizable</code>s.
* @param loggerManager the loggerManager manager instance.
*/
- public ComponentFactory( final Class componentClass,
- final Configuration configuration,
- final ServiceManager serviceManager,
- final Context context,
- final LoggerManager loggerManager,
- final LifecycleExtensionManager extManager )
+ public ComponentFactory(
+ final Class componentClass,
+ final Configuration configuration,
+ final ServiceManager serviceManager,
+ final Context context,
+ final LoggerManager loggerManager,
+ final LifecycleExtensionManager extManager,
+ final MetaInfoEntry metaEntry,
+ final Container container)
{
m_componentClass = componentClass;
m_configuration = configuration;
m_serviceManager = serviceManager;
- m_context = new DefaultContext( context );
- final String name = configuration.getAttribute( "id", componentClass.getName() );
- ( (DefaultContext) m_context ).put( "component.name", name );
- ( (DefaultContext) m_context ).put( "component.logger", configuration.getAttribute( "logger", name ) );
+ m_context = new DefaultContext(context);
+ m_metaEntry = metaEntry;
+ m_container = container;
+ final String name = configuration.getAttribute("id", componentClass.getName());
+ ((DefaultContext) m_context).put("component.name", name);
+ ((DefaultContext) m_context).put("component.logger", configuration.getAttribute("logger", name));
// Take each configuration attribute, and make a context entry of form "component.<attribName>"
String[] attribNames = configuration.getAttributeNames();
- for ( int index = 0; index < attribNames.length; index++ )
+ for (int index = 0; index < attribNames.length; index++)
{
String oneName = attribNames[index];
- ( (DefaultContext) m_context ).put( "component." + oneName, configuration.getAttribute( oneName, "" ) );
+ ((DefaultContext) m_context).put("component." + oneName, configuration.getAttribute(oneName, ""));
}
- ( (DefaultContext) m_context ).put( "component.configuration", configuration );
- ( (DefaultContext) m_context ).makeReadOnly();
+ ((DefaultContext) m_context).put("component.configuration", configuration);
+ ((DefaultContext) m_context).makeReadOnly();
m_loggerManager = loggerManager;
m_extManager = extManager;
- enableLogging( m_loggerManager.getLoggerForCategory( "system.factory" ) );
+ enableLogging(m_loggerManager.getLoggerForCategory("system.factory"));
m_componentLogger = aquireLogger();
- m_newInstance = new CounterInstrument( "creates" );
- m_dispose = new CounterInstrument( "destroys" );
+ m_newInstance = new CounterInstrument("creates");
+ m_dispose = new CounterInstrument("destroys");
- setInstrumentableName( "factory" );
-
- addInstrument( m_newInstance );
- addInstrument( m_dispose );
+ setInstrumentableName("factory");
+ addInstrument(m_newInstance);
+ addInstrument(m_dispose);
}
/**
@@ -154,8 +166,7 @@
*
* @return the new instance
*/
- public Object newInstance()
- throws Exception
+ public Object newInstance() throws Exception
{
final Object component;
@@ -163,12 +174,10 @@
{
component = this.createComponent();
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
- final String message =
- "ComponentFactory creating new instance of " +
- m_componentClass.getName() + ".";
- getLogger().debug( message );
+ final String message = "ComponentFactory creating new instance of " + m_componentClass.getName() + ".";
+ getLogger().debug(message);
}
this.enabledComponentLogging(component);
@@ -179,13 +188,13 @@
this.configureComponent(component);
- m_extManager.executeCreationExtensions( component, m_context );
+ m_extManager.executeCreationExtensions(component, m_context);
- ContainerUtil.initialize( component );
+ ContainerUtil.initialize(component);
- ContainerUtil.start( component );
+ ContainerUtil.start(component);
- if ( m_newInstance.isActive() )
+ if (m_newInstance.isActive())
{
m_newInstance.increment();
}
@@ -204,20 +213,20 @@
try
{
- final String name = (String) m_context.get( "component.logger" );
- if ( getLogger().isDebugEnabled() )
+ final String name = (String) m_context.get("component.logger");
+ if (getLogger().isDebugEnabled())
{
final String message = "logger name is " + name;
- getLogger().debug( message );
+ getLogger().debug(message);
}
- logger = m_loggerManager.getLoggerForCategory( name );
+ logger = m_loggerManager.getLoggerForCategory(name);
}
- catch ( ContextException ce )
+ catch (ContextException ce)
{
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
final String message = "no logger name available, using standard name";
- getLogger().debug( message );
+ getLogger().debug(message);
}
logger = m_loggerManager.getDefaultLogger();
}
@@ -238,51 +247,56 @@
* @param component the component to dispose of
* @exception Exception if a disposal error occurs
*/
- public final void dispose( final Object component )
- throws Exception
+ public final void dispose(final Object component) throws Exception
{
- if ( getLogger().isDebugEnabled() )
+ if (getLogger().isDebugEnabled())
{
- final String message = "ComponentFactory decommissioning instance of " +
- getCreatedClass().getName() + ".";
- getLogger().debug( message );
+ final String message = "ComponentFactory decommissioning instance of " + getCreatedClass().getName() + ".";
+ getLogger().debug(message);
}
- if ( getCreatedClass().equals( component.getClass() ) )
+ if (getCreatedClass().equals(component.getClass()))
{
- ContainerUtil.shutdown( component );
+ ContainerUtil.shutdown(component);
- m_extManager.executeDestructionExtensions( component, m_context );
+ raiseComponentDestroyedEvent( component );
+ m_extManager.executeDestructionExtensions(component, m_context);
- if ( m_dispose.isActive() )
+ if (m_dispose.isActive())
{
m_dispose.increment();
}
}
else
{
- final String message = "The object given to be disposed does " +
- "not come from this ObjectFactory";
- throw new IllegalArgumentException( message );
+ final String message = "The object given to be disposed does " + "not come from this ObjectFactory";
+ throw new IllegalArgumentException(message);
}
}
/**
- * Create a new component
+ * Create a new component and fires the
+ * associated event
*/
protected Object createComponent() throws Exception
{
- if ( !m_useDynamicCreation )
+ Object newInstance = null;
+
+ if (!m_useDynamicCreation)
{
- return m_componentClass.newInstance();
+ newInstance = m_componentClass.newInstance();
}
-
- if ( m_classinfo == null )
+ else
{
- m_classinfo = new ClassInfo();
+ if (m_classinfo == null)
+ {
+ m_classinfo = new ClassInfo();
+ }
+
+ newInstance = m_classinfo.m_constructor.newInstance( m_classinfo.m_constructorArguments );
}
- return m_classinfo.m_constructor.newInstance(m_classinfo.m_constructorArguments);
+ return raiseComponentCreatedEvent( newInstance );
}
/**
@@ -290,20 +304,20 @@
*/
protected void enabledComponentLogging(Object component) throws Exception
{
- ContainerUtil.enableLogging( component, m_componentLogger );
+ ContainerUtil.enableLogging(component, m_componentLogger);
- if ( component instanceof Loggable )
+ if (component instanceof Loggable)
{
- final org.apache.log.Logger logkitLogger =
- LogKit2AvalonLoggerAdapter.createLogger( m_componentLogger );
- ( (Loggable) component ).setLogger( logkitLogger );
+ final org.apache.log.Logger logkitLogger = LogKit2AvalonLoggerAdapter.createLogger(m_componentLogger);
+ ((Loggable) component).setLogger(logkitLogger);
}
- if ( m_useDynamicCreation )
+ if (m_useDynamicCreation)
{
- if ( m_classinfo.m_setLoggerMethod != null ) {
- m_classinfo.m_setLoggerMethod.invoke( component, new Object[] {m_componentLogger});
+ if (m_classinfo.m_setLoggerMethod != null)
+ {
+ m_classinfo.m_setLoggerMethod.invoke(component, new Object[] { m_componentLogger });
}
}
}
@@ -313,20 +327,23 @@
*/
protected void contextualizeComponent(Object component) throws Exception
{
- ContainerUtil.contextualize( component, m_context );
- if ( !(component instanceof Contextualizable ) )
+ ContainerUtil.contextualize(component, m_context);
+ if (!(component instanceof Contextualizable))
{
try
{
MethodUtils.invokeMethod(component, "setContext", m_context);
}
- catch (Exception ignore) {}
+ catch (Exception ignore)
+ {
+ }
}
- if ( m_useDynamicCreation )
+ if (m_useDynamicCreation)
{
- if ( m_classinfo.m_setContextMethod != null ) {
- m_classinfo.m_setContextMethod.invoke( component, new Object[] {m_context});
+ if (m_classinfo.m_setContextMethod != null)
+ {
+ m_classinfo.m_setContextMethod.invoke(component, new Object[] { m_context });
}
}
}
@@ -336,16 +353,17 @@
*/
protected void serviceComponent(Object component) throws Exception
{
- if ( component instanceof Composable )
+ if (component instanceof Composable)
{
- ContainerUtil.compose( component, new WrapperComponentManager( m_serviceManager ) );
+ ContainerUtil.compose(component, new WrapperComponentManager(m_serviceManager));
}
- ContainerUtil.service( component, m_serviceManager );
+ ContainerUtil.service(component, m_serviceManager);
- if ( m_useDynamicCreation )
+ if (m_useDynamicCreation)
{
- if ( m_classinfo.m_setServiceManagerMethod != null ) {
- m_classinfo.m_setServiceManagerMethod.invoke( component, new Object[] {m_serviceManager});
+ if (m_classinfo.m_setServiceManagerMethod != null)
+ {
+ m_classinfo.m_setServiceManagerMethod.invoke(component, new Object[] { m_serviceManager });
}
}
}
@@ -355,42 +373,47 @@
*/
protected void configureComponent(Object component) throws Exception
{
- ContainerUtil.configure( component, m_configuration );
+ ContainerUtil.configure(component, m_configuration);
- if ( component instanceof Parameterizable )
+ if (component instanceof Parameterizable)
{
- ContainerUtil.parameterize( component, Parameters.fromConfiguration( m_configuration ) );
+ ContainerUtil.parameterize(component, Parameters.fromConfiguration(m_configuration));
}
- if ( m_useDynamicCreation )
+ if (m_useDynamicCreation)
{
- if ( m_classinfo.m_setParametersMethod!= null ) {
- m_classinfo.m_setParametersMethod.invoke( component, new Object[] {Parameters.fromConfiguration( m_configuration )});
+ if (m_classinfo.m_setParametersMethod != null)
+ {
+ m_classinfo.m_setParametersMethod.invoke(
+ component,
+ new Object[] { Parameters.fromConfiguration(m_configuration)});
}
- if ( m_classinfo.m_setConfigurationMethod != null ) {
- m_classinfo.m_setConfigurationMethod.invoke( component, new Object[] {m_configuration});
+ if (m_classinfo.m_setConfigurationMethod != null)
+ {
+ m_classinfo.m_setConfigurationMethod.invoke(component, new Object[] { m_configuration });
}
// if the component has a configuration, but does not implement the
// interfaces, try to set the parameters using reflection
- if ( m_classinfo.m_dynamicConfiguration )
+ if (m_classinfo.m_dynamicConfiguration)
{
- if ( m_configuration != null && m_configuration.getChildren().length > 0)
+ if (m_configuration != null && m_configuration.getChildren().length > 0)
{
- final Parameters p = Parameters.fromConfiguration( m_configuration );
+ final Parameters p = Parameters.fromConfiguration(m_configuration);
String[] names = p.getNames();
- for( int i = 0; i < names.length; i++ )
+ for (int i = 0; i < names.length; i++)
{
try
{
- BeanUtils.setProperty( component, names[i], p.getParameter(names[i]));
+ BeanUtils.setProperty(component, names[i], p.getParameter(names[i]));
}
catch (Exception ignore)
{
- if ( this.getLogger() != null && this.getLogger().isWarnEnabled() )
+ if (this.getLogger() != null && this.getLogger().isWarnEnabled())
{
- this.getLogger().warn("Error while trying to configure " + component
- + " with parameter: " + names[i], ignore);
+ this.getLogger().warn(
+ "Error while trying to configure " + component + " with parameter: " + names[i],
+ ignore);
}
}
}
@@ -399,35 +422,45 @@
}
}
+ protected Object raiseComponentCreatedEvent( final Object newInstance )
+ {
+ return m_container.getEventManager().fireComponentCreated( newInstance );
+ }
+
+ protected void raiseComponentDestroyedEvent( final Object newInstance )
+ {
+ m_container.getEventManager().fireComponentDestroyed( newInstance );
+ }
+
/**
* This class collects all information about the components class:
* - the constructor to use
* - the parameters to pass into the constructor
* - Additional infos about implemented methods
*/
- protected class ClassInfo {
-
+ protected class ClassInfo
+ {
public Constructor m_constructor;
- public Object[] m_constructorArguments;
- public Method m_setLoggerMethod;
- public Method m_setConfigurationMethod;
- public Method m_setParametersMethod;
- public Method m_setContextMethod;
- public boolean m_dynamicConfiguration = false;
- public Method m_setServiceManagerMethod;
+ public Object[] m_constructorArguments;
+ public Method m_setLoggerMethod;
+ public Method m_setConfigurationMethod;
+ public Method m_setParametersMethod;
+ public Method m_setContextMethod;
+ public boolean m_dynamicConfiguration = false;
+ public Method m_setServiceManagerMethod;
/** Constructor */
- public ClassInfo()
- throws Exception {
+ public ClassInfo() throws Exception
+ {
// let's see which constructors are available
Constructor[] constructors = m_componentClass.getConstructors();
- if( constructors.length < 1 )
+ if (constructors.length < 1)
{
throw new Exception("Class " + m_componentClass + " does not have a public constructor.");
}
- if( constructors.length > 1 )
+ if (constructors.length > 1)
{
// if we have more than one constructor, we first search for
// an empty argument constructor
@@ -435,9 +468,9 @@
// we find
try
{
- m_constructor = m_componentClass.getConstructor( new Class[0] );
+ m_constructor = m_componentClass.getConstructor(new Class[0]);
}
- catch( NoSuchMethodException e )
+ catch (NoSuchMethodException e)
{
// we ignore the exception and take the first one
m_constructor = constructors[0];
@@ -450,43 +483,43 @@
// now test the parameters for the constructor
final Class[] classes = m_constructor.getParameterTypes();
- m_constructorArguments = new Object[ classes.length ];
- for( int i=0; i<classes.length; i++ )
+ m_constructorArguments = new Object[classes.length];
+ for (int i = 0; i < classes.length; i++)
{
final Class current = classes[i];
- if( Logger.class.isAssignableFrom( current ) )
+ if (Logger.class.isAssignableFrom(current))
{
- if ( m_componentLogger == null )
+ if (m_componentLogger == null)
{
throw new IllegalArgumentException("Logger is null.");
}
m_constructorArguments[i] = m_componentLogger;
}
- else if( Context.class.isAssignableFrom( current ) )
+ else if (Context.class.isAssignableFrom(current))
{
- if ( m_context == null )
+ if (m_context == null)
{
throw new IllegalArgumentException("Context is null.");
}
m_constructorArguments[i] = m_context;
}
- else if( Configuration.class.isAssignableFrom( current ) )
+ else if (Configuration.class.isAssignableFrom(current))
{
- if ( m_configuration == null )
+ if (m_configuration == null)
{
throw new IllegalArgumentException("Configuration is null.");
}
m_constructorArguments[i] = m_configuration;
}
- else if( Parameters.class.isAssignableFrom( current ) )
+ else if (Parameters.class.isAssignableFrom(current))
{
- if ( m_configuration == null )
+ if (m_configuration == null)
{
throw new IllegalArgumentException("Configuration is null.");
}
- m_constructorArguments[i] = Parameters.fromConfiguration( m_configuration );
+ m_constructorArguments[i] = Parameters.fromConfiguration(m_configuration);
}
- else if( ServiceManager.class.isAssignableFrom( current ) )
+ else if (ServiceManager.class.isAssignableFrom(current))
{
m_constructorArguments[i] = m_serviceManager;
}
@@ -503,37 +536,39 @@
}
catch (Exception e)
{
- throw new ServiceException("ComponentFactory",
- "Unknown parameter type for constructor of component: " + current, e);
+ throw new ServiceException(
+ "ComponentFactory",
+ "Unknown parameter type for constructor of component: " + current,
+ e);
}
}
}
// now test for some setter methods
- if ( !Loggable.class.isAssignableFrom( m_componentClass)
- && !LogEnabled.class.isAssignableFrom(m_componentClass))
+ if (!Loggable.class.isAssignableFrom(m_componentClass)
+ && !LogEnabled.class.isAssignableFrom(m_componentClass))
{
m_setLoggerMethod = this.getMethod("setLogger", Logger.class);
}
- if ( !Contextualizable.class.isAssignableFrom( m_componentClass))
+ if (!Contextualizable.class.isAssignableFrom(m_componentClass))
{
m_setContextMethod = this.getMethod("setContext", Context.class);
}
- if ( !Parameterizable.class.isAssignableFrom( m_componentClass)
- && !Configurable.class.isAssignableFrom(m_componentClass))
+ if (!Parameterizable.class.isAssignableFrom(m_componentClass)
+ && !Configurable.class.isAssignableFrom(m_componentClass))
{
m_setConfigurationMethod = this.getMethod("setConfiguration", Configuration.class);
m_setParametersMethod = this.getMethod("setParameters", Parameters.class);
- if ( m_setConfigurationMethod == null && m_setParametersMethod == null )
+ if (m_setConfigurationMethod == null && m_setParametersMethod == null)
{
m_dynamicConfiguration = true;
}
}
- if ( !Composable.class.isAssignableFrom(m_componentClass)
- && !Serviceable.class.isAssignableFrom(m_componentClass))
+ if (!Composable.class.isAssignableFrom(m_componentClass)
+ && !Serviceable.class.isAssignableFrom(m_componentClass))
{
m_setServiceManagerMethod = this.getMethod("setServiceManager", ServiceManager.class);
}
@@ -546,9 +581,11 @@
{
try
{
- return m_componentClass.getMethod(name, new Class[] {clazz});
+ return m_componentClass.getMethod(name, new Class[] { clazz });
+ }
+ catch (NoSuchMethodException ignore)
+ {
}
- catch (NoSuchMethodException ignore) {}
return null;
}
}
Modified: excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentHandler.java
==============================================================================
--- excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentHandler.java (original)
+++ excalibur/branches/fortress-experiments/container-impl/src/java/org/apache/avalon/fortress/impl/handler/ComponentHandler.java Fri Jul 2 15:50:41 2004
@@ -22,7 +22,7 @@
* The desire for a ComponentHandler is to manage the instances of a
* Component.
*
- * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @author <a href="mailto:dev@excalibur.apache.org">Excalibur Development Team</a>
* @version CVS $Revision: 1.8 $ $Date: 2004/02/28 15:16:25 $
* @since 4.0
*/
@@ -42,8 +42,7 @@
*
* @exception Exception if unable to prepare handler
*/
- void prepareHandler()
- throws Exception;
+ void prepareHandler() throws Exception;
/**
* Gets the current reference to a Component according to the policy of
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org