crafterm 2002/07/15 09:18:38
Modified:
fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended
ExtendedContainer.java
fortress/src/java/org/apache/excalibur/fortress/handler
ComponentFactory.java
fortress/src/java/org/apache/excalibur/fortress/lifecycle
LifecycleExtensionManager.java
fortress/src/java/org/apache/excalibur/fortress/lookup
FortressServiceManager.java
FortressServiceSelector.java
Log:
Refactored management of lifecycle extension lists.
Merged handling of access, release, creation and destruction extensions into
one list rather than 4, and updated ComponentFactory/Manager classes
accordingly.
Added simple API to modify the extension list, rather than returning the
internal List object.
Updated 'extended' example to reflect changes.
Revision Changes Path
1.3 +1 -1
jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.java
Index: ExtendedContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/examples/src/java/org/apache/excalibur/fortress/examples/extended/ExtendedContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExtendedContainer.java 12 Jul 2002 12:53:44 -0000 1.2
+++ ExtendedContainer.java 15 Jul 2002 16:18:37 -0000 1.3
@@ -19,7 +19,7 @@
{
super.initialize();
- m_extManager.getAccessLifecycleExtensions().add(new Extensions());
+ m_extManager.addExtension( new Extensions() );
}
public void doLookups()
1.17 +3 -3
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java
Index: ComponentFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentFactory.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ComponentFactory.java 12 Jul 2002 12:53:44 -0000 1.16
+++ ComponentFactory.java 15 Jul 2002 16:18:38 -0000 1.17
@@ -133,7 +133,7 @@
ContainerUtil.parameterize( component, parameters );
}
- m_extManager.executeCreationExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
ContainerUtil.initialize( component );
ContainerUtil.start( component );
@@ -164,7 +164,7 @@
{
ContainerUtil.shutdown( component );
- m_extManager.executeDestructionExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
if( m_dispose.isActive() )
{
1.2 +73 -56
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/LifecycleExtensionManager.java
Index: LifecycleExtensionManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lifecycle/LifecycleExtensionManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LifecycleExtensionManager.java 9 Jul 2002 13:32:36 -0000 1.1
+++ LifecycleExtensionManager.java 15 Jul 2002 16:18:38 -0000 1.2
@@ -7,24 +7,30 @@
*/
package org.apache.excalibur.fortress.lifecycle;
-import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.context.Context;
/**
- * <code>LifecycleExtensionManager</code> class. This class manages lists
+ * <code>LifecycleExtensionManager</code> class. This class manages a list
* of extensions objects that are executed on components during the various
* stages of their lifecycles.
*
* <p>
- * It provides 4 methods for adding extension objects to the system,
- * and 4 methods for executing them on a particular component object. The
+ * It provides methods for adding extension objects to the system,
+ * and a method for executing them on a particular component object. The
* current context is also passed in to the extension objects to facilitate
* the communication of any global values.
* </p>
*
+ * <p>
+ * Extensions are stored internally in a list. This guarentees that the
+ * order in which they are executed matches the order in which they are
+ * inserted.
+ * </p>
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Revision$ $Date$
*/
@@ -32,107 +38,118 @@
extends AbstractLifecycleExtensionManager
{
// extensions objects
- private final List m_accessExtensions = new ArrayList();
- private final List m_releaseExtensions = new ArrayList();
- private final List m_creationExtensions = new ArrayList();
- private final List m_destructionExtensions = new ArrayList();
+ private final List m_extensions = new ArrayList();
/**
- * <code>executeAccessExtensions</code> method, executes all <i>access</i>
- * level extensions on the given component.
+ * <code>executeExtensions</code> method, executes all extensions on the
+ * given component.
*
* @param component a <code>Component</code> instance
* @param context a <code>Context</code> instance
* @exception Exception if an error occurs
*/
- public void executeAccessExtensions( Object component, Context context )
+ public void executeExtensions( Object component, Context context )
throws Exception
{
- executeExtensions( m_accessExtensions.toArray(), component, context, ACCESS
);
+ executeExtensions( m_extensions.toArray(), component, context, ACCESS );
}
+ // The following methods define operations that modify the internal list
+ // of extensions. I've refrained from returning the List directly, via a
+ // getExtensions() method for the following reasons:
+ //
+ // 1. Returning List breaks encapsulation, implicitly exposing all of List's
+ // current and future operations to the client
+ // 2. List operates with type Object, not LifecycleExtension which means we need
+ // more error handling code if we make it possible for the user to add
instances
+ // of any type to the extension lists.
+ // 3. Wrapping add/remove methods allow us to add optimizations to improve
performance
+ // (eg. to convert the List to an array upon each add/remove, and not upon
each
+ // execute operation)
+ // 4. The book 'Refactoring' says we shouldn't do it :-)
+ //
+ // I'm open to suggestions though if there's any better ideas ?
+
/**
- * <code>executeReleaseExtensions</code> method, executes all <i>release</i>
- * level extensions on the given component.
+ * Adds an extension to the manager
*
- * @param component a <code>Component</code> instance
- * @param context a <code>Context</code> instance
- * @exception Exception if an error occurs
+ * @param extension a <code>LifecycleExtension</code> instance
*/
- public void executeReleaseExtensions( Object component, Context context )
- throws Exception
+ public void addExtension( LifecycleExtension extension )
{
- executeExtensions( m_releaseExtensions.toArray(), component, context,
RELEASE );
+ m_extensions.add( extension );
}
/**
- * <code>executeCreationExtensions</code> method, executes all <i>creation</i>
- * level extensions on the given component.
+ * Inserts an extension at a given index in the manager
*
- * @param component a <code>Component</code> instance
- * @param context a <code>Context</code> instance
- * @exception Exception if an error occurs
+ * @param position an <code>int</code> index value
+ * @param extension a <code>LifecycleExtension</code> instance
*/
- public void executeCreationExtensions( Object component, Context context )
- throws Exception
+ public void insertExtension( int position, LifecycleExtension extension )
{
- executeExtensions( m_creationExtensions.toArray(), component, context,
CREATION );
+ m_extensions.add( position, extension );
}
/**
- * <code>executeDestructionExtensions</code> method, executes all
<i>destruction</i>
- * level extensions on the given component.
+ * Removes a particular extension from the manager
*
- * @param component a <code>Component</code> instance
- * @param context a <code>Context</code> instance
- * @exception Exception if an error occurs
+ * @param position an <code>int</code> index value
+ * @return a <code>LifecycleExtension</code> instance
*/
- public void executeDestructionExtensions( Object component, Context context )
- throws Exception
+ public LifecycleExtension removeExtension( int position )
{
- executeExtensions( m_destructionExtensions.toArray(), component, context,
DESTRUCTION );
+ return (LifecycleExtension) m_extensions.remove( position );
}
- // REVISIT: The methods below breaks encapsulation, but I think most of List's
- // operations are useful, any better ways to do this ?
-
/**
- * Obtains the access level lifecycle extension this manager manages.
+ * Obtain an iterator.
*
- * @return a <code>List</code> of extensions
+ * @return an <code>Iterator</code> instance
*/
- public List getAccessLifecycleExtensions()
+ public Iterator extensionsIterator()
{
- return m_accessExtensions;
+ return m_extensions.iterator();
}
/**
- * Obtains the release level lifecycle extensions this manager manages.
+ * Find out the total number of extensions registered with this manager
*
- * @return a <code>List</code> of extensions
+ * @return an <code>int</code> value
*/
- public List getReleaseLifecycleExtensions()
+ public int extensionsCount()
{
- return m_releaseExtensions;
+ return m_extensions.size();
}
/**
- * Obtains the creation level lifecycle extensions this manager manages.
+ * Obtain the particular extension at the given index
*
- * @return a <code>List</code> of extensions
+ * @param index an <code>int</code> index value
+ * @return a <code>LifecycleExtension</code> instance
*/
- public List getCreationLifecycleExtensions()
+ public LifecycleExtension getExtension( int index )
{
- return m_creationExtensions;
+ return (LifecycleExtension) m_extensions.get( index );
}
/**
- * Obtains the destruction level lifecycle extensions this manager manages.
+ * Check whether the given extension is already registered
+ * with this manager
*
- * @return a <code>List</code> of extensions
+ * @param extension a <code>LifecycleExtension</code> instance
+ * @return index of given extension, -1 if non-existing.
+ */
+ public int indexOfExtension( LifecycleExtension extension )
+ {
+ return m_extensions.indexOf( extension );
+ }
+
+ /**
+ * Clears all extensions registered with this manager
*/
- public List getDestructionLifecycleExtensions()
+ public void clearExtensions()
{
- return m_destructionExtensions;
+ m_extensions.clear();
}
}
1.5 +3 -3
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceManager.java
Index: FortressServiceManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FortressServiceManager.java 9 Jul 2002 13:32:36 -0000 1.4
+++ FortressServiceManager.java 15 Jul 2002 16:18:38 -0000 1.5
@@ -119,7 +119,7 @@
component = handler.get();
- m_extManager.executeAccessExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
}
catch( ServiceException ce )
{
@@ -153,7 +153,7 @@
try
{
- m_extManager.executeReleaseExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
}
catch ( Exception e )
{
1.4 +3 -3
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java
Index: FortressServiceSelector.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/lookup/FortressServiceSelector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FortressServiceSelector.java 9 Jul 2002 13:32:36 -0000 1.3
+++ FortressServiceSelector.java 15 Jul 2002 16:18:38 -0000 1.4
@@ -66,7 +66,7 @@
component = handler.get();
- m_extManager.executeAccessExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
}
catch( ServiceException ce )
{
@@ -93,7 +93,7 @@
try
{
- m_extManager.executeReleaseExtensions( component, m_context );
+ m_extManager.executeExtensions( component, m_context );
}
catch ( Exception e )
{
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>