CVS: plexus-container-new/src/java/org/apache/plexus/lifecycle LifecycleHandlerFactory.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/lifecycle
In directory eng.werken.com:/tmp/cvs-serv18922

Added Files:
	LifecycleHandlerFactory.java 
Log Message:
o A factory which takes a configuration for a lifecycle handler and creates
  the appropriate lifecycle handler.


--- NEW FILE: LifecycleHandlerFactory.java ---
package org.apache.plexus.lifecycle;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.plexus.lifecycle.phase.Phase;

public class LifecycleHandlerFactory
{
    public static LifecycleHandler create( Configuration configuration, ClassLoader classLoader )
        throws Exception
    {
        Class c;

        c = classLoader.loadClass( configuration.getChild( "implementation" ).getValue() );
        LifecycleHandler lh = (LifecycleHandler) c.newInstance();

        Configuration[] a = configuration.getChild( "start-segment" ).getChildren( "phase" );
        for ( int i = 0; i < a.length; i++ )
        {
            c = classLoader.loadClass( a[i].getAttribute( "implementation" ) );
            lh.addBeginSegmentPhase( (Phase) c.newInstance()  );
        }

        Configuration[] b = configuration.getChild( "end-segment" ).getChildren( "phase" );
        for ( int i = 0; i < b.length; i++ )
        {
            c = classLoader.loadClass( b[i].getAttribute( "implementation" ) );
            lh.addEndSegmentPhase( (Phase) c.newInstance()  );
        }
        return lh;
    }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.