CVS: plexus-container/src/java/org/apache/plexus/lifecycle AbstractLifecycleHandler.java,1.5,1.6 LifecycleHandler.java,1.4,1.5 LifecycleHandlerFactory.java,1.5,1.6

Jason van Zyl <[email protected]> Tue, 5 Aug 2003 14:26:26 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container/src/java/org/apache/plexus/lifecycle
In directory hogshead.codehaus.org:/tmp/cvs-serv25662/src/java/org/apache/plexus/lifecycle

Modified Files:
	AbstractLifecycleHandler.java LifecycleHandler.java 
	LifecycleHandlerFactory.java 
Log Message:
o first pass at integrating bert's patch. checking it in so that bert can
  look at some stuff for me.


Index: AbstractLifecycleHandler.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container/src/java/org/apache/plexus/lifecycle/AbstractLifecycleHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- AbstractLifecycleHandler.java	1 May 2003 19:35:36 -0000	1.5
+++ AbstractLifecycleHandler.java	5 Aug 2003 19:26:23 -0000	1.6
@@ -1,8 +1,9 @@
 package org.apache.plexus.lifecycle;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.plexus.lifecycle.phase.Phase;
 import org.apache.plexus.logging.AbstractLogEnabled;
-import org.apache.plexus.service.repository.ComponentManager;
 import org.apache.plexus.service.repository.ComponentHousing;
 
 import java.util.ArrayList;
@@ -20,7 +21,8 @@
     private List suspendSegment;
     private List resumeSegment;
     private List endSegment;
-
+	private Configuration configuration;
+	
     public AbstractLifecycleHandler()
     {
         beginSegment = new ArrayList();
@@ -162,4 +164,21 @@
             phase.execute( housing, this );
         }
     }
+    
+	/**
+	 * @see org.apache.plexus.lifecycle.LifecycleHandler#configure(org.apache.avalon.framework.configuration.Configuration)
+	 */
+	public void configure(Configuration config) throws ConfigurationException
+	{
+		this.configuration = config;
+
+	}
+
+	/**
+	 * @return
+	 */
+	public Configuration getConfiguration()
+	{
+		return configuration;
+	}
 }

Index: LifecycleHandler.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container/src/java/org/apache/plexus/lifecycle/LifecycleHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- LifecycleHandler.java	1 May 2003 19:35:36 -0000	1.4
+++ LifecycleHandler.java	5 Aug 2003 19:26:23 -0000	1.5
@@ -1,11 +1,19 @@
 package org.apache.plexus.lifecycle;
 
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.plexus.lifecycle.phase.Phase;
 import org.apache.plexus.service.repository.ComponentHousing;
 
+
 import java.util.Map;
 
+/**
+ * Takes a component through it's lifecycle.
+ * 
+ * 
+ */
 public interface LifecycleHandler
 {
     /** */
@@ -17,8 +25,12 @@
 
     /** Set lifecycle specifics.
      *
-     *  The lifecycle of a particular service may vary from implementation
-     *  to implementation
+     *  <p>The lifecycle of a particular service may vary from implementation
+     *  to implementation.</p>
+     * 
+     * <p>These entities are made available to the various phases, are are global
+     * to the Lifecycel handler (no component specific stuff in here)</p>
+     * 
      */
     void addEntity( String key, Object entity );
 
@@ -48,4 +60,7 @@
     void addEndSegmentPhase( Phase phase );
 
     void enableLogging( Logger logger );
+    
+    public void configure(Configuration config) throws ConfigurationException;
+    
 }

Index: LifecycleHandlerFactory.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container/src/java/org/apache/plexus/lifecycle/LifecycleHandlerFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- LifecycleHandlerFactory.java	1 May 2003 19:35:36 -0000	1.5
+++ LifecycleHandlerFactory.java	5 Aug 2003 19:26:23 -0000	1.6
@@ -1,6 +1,7 @@
 package org.apache.plexus.lifecycle;
 
 import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.context.Context;
 import org.apache.plexus.factory.AbstractPlexusFactory;
 import org.apache.plexus.lifecycle.phase.Phase;
@@ -10,7 +11,7 @@
 public class LifecycleHandlerFactory
     extends AbstractPlexusFactory
 {
-    public static LifecycleHandler create( Configuration defaultConfiguration,
+   /* public static LifecycleHandler create( Configuration defaultConfiguration,
                                            Configuration configuration,
                                            LoggerManager loggerManager,
                                            ClassLoader classLoader,
@@ -64,5 +65,78 @@
         lh.initialize();
 
         return lh;
-    }
+    }*/
+    
+    /**
+     * Return a new  a LifecycleHandlerHousing, with an instantiated and initialized 
+     * Lifecyclehandler 
+     * 
+     * @param config
+     * @param loggerManager
+     * @param classLoader
+     * @param context
+     * @param componentRepository
+     * @return
+     * @throws Exception
+     */
+	public static LifecycleHandlerHousing createLifecycleHandlerHousing( Configuration config,
+										   LoggerManager loggerManager,
+										   ClassLoader classLoader,
+										   Context context,
+										   ComponentRepository componentRepository )
+		throws Exception
+	{
+		LifecycleHandlerHousing housing = new LifecycleHandlerHousing();
+			
+		String implementation = config.getChild( "implementation" ).getValue( null );
+		if( implementation == null)
+		{
+			throw new ConfigurationException("No lifecycle implementation");
+		}
+		String id = config.getChild("id").getValue(null);
+		if( id == null )
+		{
+			throw new ConfigurationException("No role specified for lifecycle handler");
+		}
+		
+		housing.setImplementation(implementation);
+		housing.setId(id);
+		housing.setConfiguration( config );
+		LifecycleHandler lh = (LifecycleHandler) getInstance( implementation, classLoader );
+
+		// Setup logging for the lifecycle handler. Not used by components
+		lh.enableLogging( loggerManager.getLogger( "lifecycle-handler:" + id ) );
+
+		Configuration[] a = config.getChild( "start-segment" ).getChildren( "phase" );
+		for ( int i = 0; i < a.length; i++ )
+		{
+			lh.addBeginSegmentPhase(
+				(Phase) getInstance( a[i].getAttribute( "implementation" ), classLoader ) );
+		}
+
+		Configuration[] b = config.getChild( "end-segment" ).getChildren( "phase" );
+		for ( int i = 0; i < b.length; i++ )
+		{
+			lh.addEndSegmentPhase(
+				(Phase) getInstance( b[i].getAttribute( "implementation" ), classLoader ) );
+		}
+
+		// Add some standard entities to the lifecycle handler. The lifecycle
+		// handler may wish to use some of these entities to create new types
+		// of entities for its lifecycle phases. For example the AvalonLifecycleHandler
+		// uses the ServiceRepository and adapts it to create an Avalon ServiceManager.
+		// The entities MUST be added before initialization of the lifecyclehandler.
+		lh.addEntity( LifecycleHandler.LOGGER, loggerManager.getRootLogger() );
+		lh.addEntity( LifecycleHandler.CONTEXT, context );
+		lh.addEntity( LifecycleHandler.SERVICE_REPOSITORY, componentRepository );
+
+		// Initialize the lifecycle handler before returning the instance.
+		lh.configure(config.getChild("configuration"));
+		lh.initialize();
+		
+		//wrap the handler in an immutable wrapper. THis is so components can't modify it
+		housing.setHandler(lh);
+		
+		return housing;
+	}
 }