You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by do...@apache.org on 2001/02/24 05:00:38 UTC
cvs commit: jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline AbstractLifeCycleStage.java ComponentBuilder.java ComponentManagerBuilder.java CompositionStage.java ConfigurationRepository.java ConfigurationStage.java ContextBuilder.java ContextualizationStage.java CreationStage.java DisposingStage.java InitializationStage.java LifeCyclePipeline.java LifeCycleStage.java LoggerBuilder.java LoggerStage.java OldConfigurationStage.java RunnerStage.java ShutdownPipeline.java StartStage.java StartupPipeline.java StopStage.java
donaldp 01/02/23 20:00:38
Added: src/java/org/apache/avalon/camelot
AbstractCamelotDeployer.java AbstractContainer.java
AbstractDeployer.java AbstractZipDeployer.java
AvalonState.java CamelotUtil.java Container.java
ContainerException.java DefaultFactory.java
DefaultLoader.java DefaultLocator.java
DefaultLocatorRegistry.java DefaultRegistry.java
Deployer.java DeployerUtil.java
DeploymentException.java Entry.java Factory.java
FactoryException.java Info.java Loader.java
Locator.java LocatorRegistry.java MetaInfo.java
Registry.java RegistryException.java State.java
src/java/org/apache/avalon/camelot/pipeline
AbstractLifeCycleStage.java ComponentBuilder.java
ComponentManagerBuilder.java CompositionStage.java
ConfigurationRepository.java
ConfigurationStage.java ContextBuilder.java
ContextualizationStage.java CreationStage.java
DisposingStage.java InitializationStage.java
LifeCyclePipeline.java LifeCycleStage.java
LoggerBuilder.java LoggerStage.java
OldConfigurationStage.java RunnerStage.java
ShutdownPipeline.java StartStage.java
StartupPipeline.java StopStage.java
Log:
Rechecked in avalon
Revision Changes Path
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/AbstractCamelotDeployer.java
Index: AbstractCamelotDeployer.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.ComponentNotFoundException;
import org.apache.avalon.Composer;
/**
* This class deploys resources from camelot based system.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class AbstractCamelotDeployer
extends AbstractDeployer
implements Composer
{
protected boolean m_deployToContainer;
protected boolean m_deployToLocatorRegistry;
protected boolean m_deployToInfoRegistry;
protected LocatorRegistry m_locatorRegistry;
protected Container m_container;
protected Registry m_infoRegistry;
/**
* Retrieve relevent services needed to deploy.
*
* @param componentManager the ComponentManager
* @exception ComponentNotFoundException if an error occurs
* @exception ComponentNotAccessibleException if an error occurs
*/
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
if( m_deployToLocatorRegistry )
{
m_locatorRegistry = (LocatorRegistry)componentManager.
lookup( "org.apache.avalon.camelot.LocatorRegistry" );
}
if( m_deployToInfoRegistry )
{
m_infoRegistry = (Registry)componentManager.
lookup( "org.apache.avalon.camelot.Registry" );
}
if( m_deployToContainer )
{
m_container = (Container)componentManager.
lookup( "org.apache.avalon.camelot.Container" );
}
}
protected void addEntry( final String name, final Entry entry )
throws DeploymentException
{
try { m_container.add( name, entry ); }
catch( final ContainerException ce )
{
throw new DeploymentException( "Error adding component to container", ce );
}
getLogger().debug( "Adding " + m_type + "Entry " + name + " as " + entry );
}
protected void addLocator( final String name, final String classname, final URL url )
throws DeploymentException
{
final DefaultLocator locator = new DefaultLocator( classname, url );
try { m_locatorRegistry.register( name, locator ); }
catch( final RegistryException re )
{
throw new DeploymentException( "Error registering " + name + " due to " + re,
re );
}
getLogger().debug( "Registered " + m_type + " " + name + " as " + classname );
}
protected void addInfo( final String name, final Info info )
throws DeploymentException
{
try { m_infoRegistry.register( name, info ); }
catch( final RegistryException re )
{
throw new DeploymentException( "Error registering " + name + " due to " + re,
re );
}
getLogger().debug( "Registered Info " + m_type + " " + name );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/AbstractContainer.java
Index: AbstractContainer.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 file.
*/
package org.apache.avalon.camelot;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.Component;
/**
* This contains it during execution and may provide certain
* facilities (like a thread per EJB etc).
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class AbstractContainer
extends AbstractLoggable
implements Container
{
protected final HashMap m_entries = new HashMap();
protected Class m_entryClass;
/**
* Add a component instance to container.
*
* @param entry the component entry
*/
public void add( final String name, final Entry entry )
throws ContainerException
{
checkEntry( name, entry );
preAdd( name, entry );
m_entries.put( name, entry );
postAdd( name, entry );
}
/**
* Remove a component instance from container.
*
* @param name the name of component
*/
public void remove( final String name )
throws ContainerException
{
final Entry entry = (Entry)m_entries.get( name );
if( null == entry )
{
throw new ContainerException( "Component named " + name + " not contained" );
}
preRemove( name, entry );
m_entries.remove( name );
postRemove( name, entry );
}
/**
* Retrieve Entry from container
*
* @param name the name of entry
* @return the entry
*/
public Entry getEntry( final String name )
throws ContainerException
{
final Entry entry = (Entry)m_entries.get( name );
if( null == entry )
{
throw new ContainerException( "Name " + name + " not contained" );
}
else
{
return entry;
}
}
/**
* List all names of entries in container.
*
* @return the list of all entries
*/
public Iterator list()
{
return m_entries.keySet().iterator();
}
/**
* This method is called before entry is added to give chance for
* sub-class to veto removal.
*
* @param name the name of entry
* @param entry the entry
* @exception ContainerException to stop removal of entry
*/
protected void preAdd( final String name, final Entry entry )
throws ContainerException
{
}
/**
* This method is called after entry is added to give chance for
* sub-class to do some cleanup.
*
* @param name the name of entry
* @param entry the entry
*/
protected void postAdd( final String name, final Entry entry )
{
}
/**
* This method is called before entry is removed to give chance for
* sub-class to veto removal.
*
* @param name the name of entry
* @param entry the entry
* @exception ContainerException to stop removal of entry
*/
protected void preRemove( final String name, final Entry entry )
throws ContainerException
{
}
/**
* This method is called after entry is removed to give chance for
* sub-class to do some cleanup.
*
* @param name the name of entry
* @param entry the entry
*/
protected void postRemove( final String name, final Entry entry )
{
}
/**
* List all entries in container.
*
* @return the list of all entries
*/
protected Iterator listEntries()
{
return m_entries.values().iterator();
}
protected void checkEntry( final String name, final Entry entry )
throws ContainerException
{
if( null != m_entries.get( name ) )
{
throw new ContainerException( "Can not add component to container because " +
"entry already exists with name " + name );
}
if( !isValidName( name ) )
{
throw new ContainerException( "Can not add component to container because " +
"invalid name " + name );
}
if( !isValidEntry( entry ) )
{
throw new ContainerException( "Can not add component to container because " +
"invalid entry for " + name );
}
if( !m_entryClass.isAssignableFrom( entry.getClass() ) )
{
throw new ContainerException( "Only Entries of type " + m_entryClass.getName() +
" may be placed in container." );
}
}
protected boolean isValidName( final String name )
throws ContainerException
{
return true;
}
protected boolean isValidEntry( final Entry entry )
throws ContainerException
{
return true;
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/AbstractDeployer.java
Index: AbstractDeployer.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 file.
*/
package org.apache.avalon.camelot;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashMap;
import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.Component;
import org.apache.avalon.ComponentNotFoundException;
import org.apache.avalon.util.io.FileUtil;
import org.apache.log.Logger;
/**
* A Deployer is responsible for taking a URL (ie a jar/war/ear) and deploying
* it to a particular "location". "location" means different things for
* different containers. For a servlet container it may mean the place to
* mount servlet (ie /myapp --> /myapp/Cocoon.xml is mapping cocoon servlet to
* /myapp context).
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class AbstractDeployer
extends AbstractLoggable
implements Deployer
{
protected final HashMap m_deployments = new HashMap();
protected boolean m_autoUndeploy;
protected String m_type;
public void deploy( final String location, final URL url )
throws DeploymentException
{
checkDeployment( location, url );
final File file = getFileFor( url );
getLogger().info( "Deploying " + m_type + " file (" + file + ") as " + location );
deployFromFile( location, file );
}
protected void checkDeployment( final String location, final URL url )
throws DeploymentException
{
if( null != m_deployments.get( location ) )
{
throw new DeploymentException( m_type + " already exists at " + location );
}
if( !isValidLocation( location ) )
{
throw new DeploymentException( "Invalid location (" + location +
") for " + m_type );
}
}
public void undeploy( final String location )
throws DeploymentException
{
final Component component = (Component)m_deployments.get( location );
if( null == component )
{
throw new DeploymentException( m_type + " does not exist at " + location );
}
final boolean canUndeploy = canUndeploy( component );
if( !canUndeploy )
{
if( !m_autoUndeploy )
{
//we are midstream but not allowed to automagically undeploy .. therefore
throw new DeploymentException( m_type + " not ready to undeploy at " +
location );
}
else
{
shutdownDeployment( component );
}
}
//if everything has gone successful then remove application
m_deployments.remove( location );
}
protected File getCacheLocationFor( final URL url )
throws DeploymentException
{
throw new DeploymentException( "Unable to deploy non-local resources" );
}
protected File getFileFor( final URL url )
throws DeploymentException
{
File file = null;
if( url.getProtocol().equals( "file" ) )
{
file = new File( url.getFile() );
}
else
{
file = getCacheLocationFor( url );
try { FileUtil.copyURLToFile( url, file ); }
catch( final IOException ioe )
{
throw new DeploymentException( "Failed attempting to copy from " + url +
" to local file cache " + file, ioe );
}
}
file = file.getAbsoluteFile();
if( !file.exists() )
{
throw new DeploymentException( "Could not find application archive at " +
file );
}
if( file.isDirectory() )
{
throw new DeploymentException( "Could not find application archive at " +
file + " as it is a directory." );
}
return file;
}
protected boolean isValidLocation( String location )
{
return true;
}
protected boolean canUndeploy( Component component )
throws DeploymentException
{
return true;
}
protected void shutdownDeployment( Component component )
throws DeploymentException
{
}
protected abstract void deployFromFile( String location, File file )
throws DeploymentException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/AbstractZipDeployer.java
Index: AbstractZipDeployer.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 file.
*/
package org.apache.avalon.camelot;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipFile;
import org.apache.avalon.Composer;
/**
* This class deploys a .zip file into a registry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class AbstractZipDeployer
extends AbstractCamelotDeployer
implements Composer
{
/**
* Deploy a file.
* Eventually this should be cached for performance reasons.
*
* @param location the location
* @param file the file
* @exception DeploymentException if an error occurs
*/
protected void deployFromFile( final String location, final File file )
throws DeploymentException
{
final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
URL url = null;
try
{
try { url = file.toURL(); }
catch( final MalformedURLException mue )
{
throw new DeploymentException( "Unable to form url", mue );
}
loadResources( zipFile, location, url );
}
finally
{
try { zipFile.close(); }
catch( final IOException ioe ) {}
}
}
/**
* Overide this method to provide the actual functionality and
* deploy the resources from a zip file.
*
* @param zipFile the ZipFile
* @param location the location that it was deployed to
* @param url the url of deployment
* @exception DeploymentException if an error occurs
*/
protected abstract void loadResources( ZipFile zipFile, String location, URL url )
throws DeploymentException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/AvalonState.java
Index: AvalonState.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 file.
*/
package org.apache.avalon.camelot;
public final class AvalonState
extends State
{
public final static AvalonState ERROR = new AvalonState( "ERROR", -10 );
public final static AvalonState BASE = new AvalonState( "BASE", 0 );
public final static AvalonState CREATED = new AvalonState( "CREATED", 5 );
public final static AvalonState LOGGED = new AvalonState( "LOGGED", 10 );
public final static AvalonState CONTEXTUALIZED = new AvalonState( "CONTEXTUALIZED", 20 );
public final static AvalonState COMPOSED = new AvalonState( "COMPOSED", 30 );
public final static AvalonState CONFIGURED = new AvalonState( "CONFIGURED", 40 );
public final static AvalonState NAMED = new AvalonState( "NAMED", 50 );
public final static AvalonState INITIALIZED = new AvalonState( "INITIALIZED", 60 );
public final static AvalonState STARTED = new AvalonState( "STARTED", 70 );
public final static AvalonState RUNNING = new AvalonState( "RUNNING", 70 );
//from here to stopped may want to go to a different class ??
public final static AvalonState EXPORTED = new AvalonState( "EXPORTED", 80 );
public final static AvalonState UNEXPORTED = new AvalonState( "UNEXPORTED", 90 );
public final static AvalonState SUSPENDED = new AvalonState( "SUSPENDED", 100 );
public final static AvalonState RESUMED = new AvalonState( "RESUMED", 110 );
public final static AvalonState STOPPED = new AvalonState( "STOPPED", 120 );
public final static AvalonState DISPOSED = new AvalonState( "DISPOSED", 130 );
public final static AvalonState FINALIZED = new AvalonState( "FINALIZED", 140 );
protected AvalonState( final String name, final int value )
{
super( name, value );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/CamelotUtil.java
Index: CamelotUtil.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 file.
*/
package org.apache.avalon.camelot;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Iterator;
import org.apache.avalon.Component;
import org.apache.avalon.util.io.ExtensionFileFilter;
/**
* Utility methods for Camelot related facilities.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class CamelotUtil
{
/**
* Private constructor so impossible to instantiate.
*/
private CamelotUtil()
{
}
public static void deployFromDirectory( final Deployer deployer,
final File directory,
final String extention )
throws DeploymentException
{
deployFromDirectory( deployer, directory, new String[] { extention } );
}
public static void deployFromDirectory( final Deployer deployer,
final File directory,
final String[] extentions )
throws DeploymentException
{
final ExtensionFileFilter filter = new ExtensionFileFilter( extentions );
final File[] files = directory.listFiles( filter );
if( null != files )
{
deployFiles( deployer, files );
}
}
public static void deployFiles( final Deployer deployer, final File[] files )
throws DeploymentException
{
for( int i = 0; i < files.length; i++ )
{
final String filename = files[ i ].getName();
int index = filename.lastIndexOf( '.' );
if( -1 == index ) index = filename.length();
final String name = filename.substring( 0, index );
try
{
final File file = files[ i ].getCanonicalFile();
deployer.deploy( name, file.toURL() );
}
catch( final MalformedURLException mue )
{
throw new DeploymentException( "Malformed URL for " + files[ i ], mue );
}
catch( final IOException ioe )
{
throw new DeploymentException( "Unable to get canonical representation " +
"for file " + files[ i ], ioe );
}
}
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Container.java
Index: Container.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 file.
*/
package org.apache.avalon.camelot;
import java.util.Iterator;
import org.apache.avalon.Component;
/**
* This contains it during execution and may provide certain
* facilities (like a thread per EJB etc).
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Container
extends Component
{
/**
* Add a component instance to container.
*
* @param entry the component entry
*/
void add( String name, Entry entry )
throws ContainerException;
/**
* Remove a component instance from container.
*
* @param name the name of component
*/
void remove( String name )
throws ContainerException;
/**
* Retrieve Entry from container
*
* @param name the name of entry
* @return the entry
*/
Entry getEntry( String name )
throws ContainerException;
/**
* List all names of entries in container.
*
* @return the list of all entries
*/
Iterator list();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/ContainerException.java
Index: ContainerException.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.CascadingException;
/**
* Exception to indicate error manipulating container.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class ContainerException
extends CascadingException
{
/**
* Construct a new <code>ContainerException</code> instance.
*
* @param message The detail message for this exception.
*/
public ContainerException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>ContainerException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ContainerException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DefaultFactory.java
Index: DefaultFactory.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import java.util.HashMap;
import org.apache.avalon.Component;
import org.apache.avalon.AbstractLoggable;
/**
* This is the component that creates the components.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultFactory
extends AbstractLoggable
implements Factory
{
protected static class LoaderEntry
{
Loader m_loader;
long m_lastModified;
}
protected final HashMap m_loaders = new HashMap();
/**
* Create a component whos position is indicated by locator.
*
* @param locator the locator indicating the component location
* @return the component
* @exception FactoryException if an error occurs
*/
public Object create( final Locator locator )
throws FactoryException
{
final Loader loader = getLoaderFor( locator.getLocation() );
try { return loader.load( locator.getName() ); }
catch( final Exception e )
{
throw new FactoryException( "Unable to create " + locator.getName() +
" from " + locator.getLocation(), e );
}
}
public Object create( final Locator locator, final Class clazz )
throws FactoryException
{
final Object object = create( locator );
if( !clazz.isInstance( object ) )
{
throw new FactoryException( "Created object of type " + object.getClass().getName() +
" not compatable with type " + clazz.getName() );
}
return object;
}
protected Loader getLoaderFor( final URL url )
{
final String location = url.toString();
LoaderEntry loader = (LoaderEntry)m_loaders.get( location );
if( null == loader )
{
getLogger().info( "Creating ClassLoader for " + location );
loader = new LoaderEntry();
loader.m_loader = setupLoader( url );
loader.m_lastModified = System.currentTimeMillis();
m_loaders.put( location, loader );
}
else
{
//TODO: Check it up to date and reload if necessary
}
return loader.m_loader;
}
protected Loader setupLoader( final URL url )
{
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final Loader loader = createLoader( url, classLoader );
setupLogger( loader );
return loader;
}
/**
* Create a new loader.
* Put in another method so that it can be overridden.
*
* @param location the location the Loader will load from
* @return the loader
*/
protected Loader createLoader( final URL url, final ClassLoader classLoader )
{
return new DefaultLoader( url, classLoader );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DefaultLoader.java
Index: DefaultLoader.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.avalon.util.ObjectUtil;
import org.apache.avalon.util.StringUtil;
/**
* Class used to load resources from a source.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultLoader
implements Loader
{
protected ClassLoader m_classLoader;
public DefaultLoader( final ClassLoader classLoader )
{
m_classLoader = classLoader;
}
public DefaultLoader( final URL location, final ClassLoader classLoader )
{
m_classLoader = new URLClassLoader( new URL[] { location }, classLoader );
}
public DefaultLoader( final URL location )
{
this( location, Thread.currentThread().getContextClassLoader() );
}
public DefaultLoader()
{
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
m_classLoader = new URLClassLoader( new URL[0], classLoader );
}
/**
* Retrieve classloader associated with source.
*
* @return the ClassLoader
*/
public ClassLoader getClassLoader()
{
return m_classLoader;
}
public Object load( final String classname, final Class clazz )
throws FactoryException
{
final Object object = load( classname );
if( !clazz.isInstance( object ) )
{
throw new FactoryException( "Created object of type " + object.getClass().getName() +
" not compatable with type " + clazz.getName() );
}
return object;
}
/**
* Load an object from source.
*
* @param classname the name of object
* @return the Object
* @exception Exception if an error occurs
*/
public Object load( final String classname )
throws FactoryException
{
try
{
return ObjectUtil.createObject( m_classLoader, classname );
}
catch( final ClassNotFoundException cnfe )
{
throw new FactoryException( "Failed to locate class " + classname, cnfe );
}
catch( final InstantiationException ie )
{
throw new FactoryException( "Failed to instantiate class " + classname, ie );
}
catch( final IllegalAccessException iae )
{
throw new FactoryException( "Failed to instantiate class " + classname +
" as it does not have a publicly accesable " +
"default constructor", iae );
}
catch( final Throwable t )
{
throw new FactoryException( "Failed to get class " + classname +
" due to " + StringUtil.printStackTrace( t, 5, true ),
t );
}
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DefaultLocator.java
Index: DefaultLocator.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import org.apache.avalon.Component;
/**
* This contains information required to locate a component.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultLocator
implements Locator
{
protected final String m_name;
protected final URL m_location;
public DefaultLocator( final String name, final URL location )
{
m_name = name;
m_location = location;
}
/**
* Retrieve "name" of component type.
* The "name" usually indicates the classname.
*
* @return the name
*/
public String getName()
{
return m_name;
}
/**
* Retrieve location of component.
* Usually references the archive (zip/jar/war/ear)
* which contains the name (ie classname)
*
* @return the URL of location
*/
public URL getLocation()
{
return m_location;
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DefaultLocatorRegistry.java
Index: DefaultLocatorRegistry.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 file.
*/
package org.apache.avalon.camelot;
/**
* Represents a Registry of locators.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultLocatorRegistry
extends DefaultRegistry
implements LocatorRegistry
{
public DefaultLocatorRegistry()
{
super( Locator.class );
}
/**
* Retrieve a Locator by name.
*
* @param name the name
* @return the Info
* @exception RegistryException if an error occurs
*/
public Locator getLocator( String name )
throws RegistryException
{
return (Locator)getInfo( name );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DefaultRegistry.java
Index: DefaultRegistry.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 file.
*/
package org.apache.avalon.camelot;
import java.util.HashMap;
import java.util.Iterator;
/**
* Represents a Registry of names to types.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class DefaultRegistry
implements Registry
{
protected final HashMap m_infos = new HashMap();
protected final Class m_infoClass;
public DefaultRegistry( final Class clazz )
{
m_infoClass = clazz;
}
public void register( final String name, final Info info )
throws RegistryException
{
if( null != m_infos.get( name ) )
{
throw new RegistryException( "Name " + name + " already registered" );
}
else
{
checkInfo( name, info );
m_infos.put( name, info );
}
}
public void unregister( final String name )
throws RegistryException
{
if( null == m_infos.remove( name ) )
{
throw new RegistryException( "Name " + name + " not registered" );
}
}
public Info getInfo( final String name )
throws RegistryException
{
final Info info = (Info)m_infos.get( name );
if( null == info )
{
throw new RegistryException( "Name " + name + " not registered" );
}
else
{
return info;
}
}
public Iterator getInfoNames()
{
return m_infos.keySet().iterator();
}
protected void checkInfo( final String name, final Info info )
throws RegistryException
{
if( !m_infoClass.isAssignableFrom( info.getClass() ) )
{
throw new RegistryException( "Only Infos of type " + m_infoClass.getName() +
" may be placed in registry." );
}
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Deployer.java
Index: Deployer.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import org.apache.avalon.ComponentNotFoundException;
import org.apache.avalon.Component;
/**
* A Deployer is responsible for taking a URL (ie a jar/war/ear) and deploying
* it to a particular "location". "location" means different things for
* different containers. For a servlet container it may mean the place to
* mount servlet (ie /myapp --> /myapp/Cocoon.xml is mapping cocoon servlet to
* /myapp context).
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Deployer
extends Component
{
/**
* Deploy a resource indicate by url to location.
*
* @param location the location to deploy to
* @param url the url of deployment
* @exception DeploymentException if an error occurs
*/
void deploy( String location, URL url )
throws DeploymentException;
/**
* undeploy a resource from a location.
*
* @param location the location
* @exception DeploymentException if an error occurs
*/
void undeploy( String location )
throws DeploymentException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DeployerUtil.java
Index: DeployerUtil.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 file.
*/
package org.apache.avalon.camelot;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URL;
import java.util.Properties;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentNotAccessibleException;
import org.apache.avalon.ComponentNotFoundException;
import org.apache.avalon.Composer;
import org.apache.avalon.Composer;
import org.apache.avalon.configuration.Configuration;
import org.apache.avalon.configuration.ConfigurationException;
import org.apache.avalon.configuration.DefaultConfigurationBuilder;
import org.xml.sax.SAXException;
/**
* This class deploys resources from camelot based system.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class DeployerUtil
{
protected static DefaultConfigurationBuilder c_configurationBuilder;
/**
* Private constructor to block instantiation.
*/
private DeployerUtil()
{
}
protected static DefaultConfigurationBuilder getBuilder()
{
if( null == c_configurationBuilder )
{
c_configurationBuilder = new DefaultConfigurationBuilder();
}
return c_configurationBuilder;
}
/**
* Get zipFile represented by URL.
*
* @param url the URL
* @return the ZipFile
* @exception DeploymentException if an error occurs
*/
/*
public final static ZipFile getZipFileFor( final URL url )
throws DeploymentException
{
final File file = getFileFor( url );
return getZipFileFor( file );
}
*/
/**
* Retrieve zip file for file.
*
* @param file the file
* @return the zipFile
* @exception DeploymentException if an error occurs
*/
public final static ZipFile getZipFileFor( final File file )
throws DeploymentException
{
try { return new ZipFile( file ); }
catch( final IOException ioe )
{
throw new DeploymentException( "Error opening " + file +
" due to " + ioe.getMessage(),
ioe );
}
}
/**
* Utility method to load configuration from zip.
*
* @param zipFile the zip file
* @param filename the property filename
* @return the Configuration
* @exception DeploymentException if an error occurs
*/
public final static Configuration loadConfiguration( final ZipFile zipFile,
final String filename )
throws DeploymentException
{
return buildConfiguration( loadResourceStream( zipFile, filename ) );
}
/**
* Build a configuration tree based on input stream.
*
* @param input the InputStream
* @return the Configuration tree
* @exception DeploymentException if an error occurs
*/
public final static Configuration buildConfiguration( final InputStream input )
throws DeploymentException
{
try { return getBuilder().build( input ); }
catch( final SAXException se )
{
throw new DeploymentException( "Malformed configuration data", se );
}
catch( final ConfigurationException ce )
{
throw new DeploymentException( "Error building configuration", ce );
}
catch( final IOException ioe )
{
throw new DeploymentException( "Error reading configuration", ioe );
}
}
/**
* Utility method to load a manifest from a zip file.
*
* @param zipFile the zip file
* @return the Manifest
*/
public final static Manifest loadManifest( final ZipFile zipFile )
throws DeploymentException
{
final InputStream input = loadResourceStream( zipFile, "META-INF/MANIFEST.MF" );
try { return new Manifest( input ); }
catch( final IOException ioe )
{
throw new DeploymentException( "Error reading manifest", ioe );
}
finally
{
try { input.close(); }
catch( final IOException ioe ) {}
}
}
/**
* Utility method to load properties from zip.
*
* @param zipFile the zip file
* @param filename the property filename
* @return the Properties
* @exception DeploymentException if an error occurs
*/
public final static Properties loadProperties( final ZipFile zipFile,
final String filename )
throws DeploymentException
{
final Properties properties = new Properties();
try { properties.load( loadResourceStream( zipFile, filename ) ); }
catch( final IOException ioe )
{
throw new DeploymentException( "Error reading " + filename +
" from " + zipFile.getName(),
ioe );
}
return properties;
}
/**
* Load a resource from a zip file.
*
* @param zipFile the ZipFile
* @param filename the filename
* @return the InputStream
* @exception DeploymentException if an error occurs
*/
public final static InputStream loadResourceStream( final ZipFile zipFile,
final String filename )
throws DeploymentException
{
final ZipEntry entry = zipFile.getEntry( filename );
if( null == entry )
{
throw new DeploymentException( "Unable to locate " + filename +
" in " + zipFile.getName() );
}
try { return zipFile.getInputStream( entry ); }
catch( final IOException ioe )
{
throw new DeploymentException( "Error reading " + filename +
" from " + zipFile.getName(),
ioe );
}
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/DeploymentException.java
Index: DeploymentException.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.CascadingException;
/**
* Exception to indicate error deploying.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class DeploymentException
extends CascadingException
{
/**
* Construct a new <code>DeploymentException</code> instance.
*
* @param message The detail message for this exception.
*/
public DeploymentException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>DeploymentException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public DeploymentException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Entry.java
Index: Entry.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.Component;
/**
* Contains information about a particular instance of contained component.
* This would contain name, configuration data, parameters, log entries etc.
* Basically instance data.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class Entry
implements Component
{
protected Info m_info;
protected Object m_instance;
protected State m_state;
public Entry()
{
}
public Entry( final Info info, final Object instance, final State state )
{
m_info = info;
m_instance = instance;
m_state = state;
}
/**
* Retrieve Info describing instance.
*
* @return the info
*/
public Info getInfo()
{
return m_info;
}
/**
* Mutator for info property.
*
* @param info the Info
*/
public void setInfo( final Info info )
{
m_info = info;
}
/**
* Retrieve instance of component.
*
* @return the component instance
*/
public Object getInstance()
{
return m_instance;
}
/**
* Set instance of component.
*
* @return the component instance
*/
public void setInstance( final Object instance )
{
m_instance = instance;
}
/**
* Retrieve state of a component.
*
* @return the components state
*/
public State getState()
{
return m_state;
}
/**
* set state of a component.
*
* @param state the components state
*/
public void setState( final State state )
{
m_state = state;
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Factory.java
Index: Factory.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.Component;
/**
* This is the component that creates the components.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Factory
extends Component
{
/**
* Create a component whos position is indicated by locator.
*
* @param locator the locator indicating the component location
* @return the component
* @exception FactoryException if an error occurs
*/
Object create( Locator locator )
throws FactoryException;
/**
* Create a component whos position is indicated by locator.
* Make sure it is of the correct type.
*
* @param locator the locator indicating the component location
* @param clazz the expected type of component
* @return the component
* @exception FactoryException if an error occurs
*/
Object create( Locator locator, Class clazz )
throws FactoryException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/FactoryException.java
Index: FactoryException.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.CascadingException;
/**
* Exception to indicate error creating entries in factory.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class FactoryException
extends CascadingException
{
/**
* Construct a new <code>FactoryException</code> instance.
*
* @param message The detail message for this exception.
*/
public FactoryException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>FactoryException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public FactoryException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Info.java
Index: Info.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.Component;
/**
* This contains information relating to a component.
* There is currently two different sub-interfaces - MetaInfo and Locator.
* MetaInfo describes meta information about component while Locator
* locates it in the system.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Info
extends Component
{
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Loader.java
Index: Loader.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.Component;
/**
* Class used to load resources from a source.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Loader
extends Component
{
/**
* Retrieve classloader associated with source.
*
* @return the ClassLoader
*/
ClassLoader getClassLoader();
/**
* Load an object from source.
*
* @param component the name of object
* @return the Object
* @exception Exception if an error occurs
*/
Object load( String component )
throws FactoryException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Locator.java
Index: Locator.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 file.
*/
package org.apache.avalon.camelot;
import java.net.URL;
import org.apache.avalon.Component;
/**
* This contains information required to locate a component.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Locator
extends Info
{
/**
* Retrieve "name" of component type.
* The "name" usually indicates the classname.
*
* @return the name
*/
String getName();
/**
* Retrieve location of component.
* Usually references the archive (zip/jar/war/ear)
* which contains the name (ie classname)
*
* @return the URL of location
*/
URL getLocation();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/LocatorRegistry.java
Index: LocatorRegistry.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 file.
*/
package org.apache.avalon.camelot;
/**
* Represents a database of Locators.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface LocatorRegistry
extends Registry
{
/**
* Retrieve a Locator by name.
*
* @param name the name
* @return the Info
* @exception RegistryException if an error occurs
*/
Locator getLocator( String name ) throws RegistryException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/MetaInfo.java
Index: MetaInfo.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 file.
*/
package org.apache.avalon.camelot;
/**
* This contains information about the component.
* (ie would be a BlockInfo, an EJBDescriptor, a MailetInfo etc)
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface MetaInfo
extends Info
{
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/Registry.java
Index: Registry.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 file.
*/
package org.apache.avalon.camelot;
import java.util.Iterator;
import org.apache.avalon.Component;
/**
* Represents a database of Infos.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface Registry
extends Component
{
/**
* register an info under a particular name.
*
* @param name the name
* @param info the info
* @exception RegistryException if info is invalid or name already contains info under name
*/
void register( String name, Info info ) throws RegistryException;
/**
* unregister an info.
*
* @param name the name of info
* @exception RegistryException if no such info exists
*/
void unregister( String name ) throws RegistryException;
/**
* Retrieve an Info by name.
*
* @param name the name
* @return the Info
* @exception RegistryException if an error occurs
*/
Info getInfo( String name ) throws RegistryException;
/**
* Return an iterator of all names of infos registered.
*
* @return the info names
*/
Iterator getInfoNames();
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/RegistryException.java
Index: RegistryException.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.CascadingException;
/**
* Exception to indicate registry error.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public final class RegistryException
extends CascadingException
{
/**
* Construct a new <code>RegistryException</code> instance.
*
* @param message The detail message for this exception.
*/
public RegistryException( final String message )
{
this( message, null );
}
/**
* Construct a new <code>RegistryException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public RegistryException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/State.java
Index: State.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 file.
*/
package org.apache.avalon.camelot;
import org.apache.avalon.util.ValuedEnum;
/**
* Defines possible states for contained components.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class State
extends ValuedEnum
{
public State( final String name, final int value )
{
super( name, value );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/AbstractLifeCycleStage.java
Index: AbstractLifeCycleStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.Stage;
import org.apache.avalon.camelot.Entry;
/**
* Stage used in managing avalon components.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public abstract class AbstractLifeCycleStage
extends AbstractLoggable
implements LifeCycleStage
{
protected Class m_service;
protected String m_serviceName;
/**
* Process an avalon entry.
* Processing includes managing some aspect of blocks lifecycle
* and could be configuring, exporting, replicating, composing etc.
*
* @param entry the entry
* @exception Exception if an error occurs
*/
public void process( final String name, final Entry entry )
throws Exception
{
final Object object = entry.getInstance();
if( m_service.isInstance( object ) )
{
getLogger().debug( "Processing " + m_serviceName + " Stage for " + name );
process( name, entry, object );
}
}
protected abstract void process( String name, Entry entry, Object object )
throws Exception;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ComponentBuilder.java
Index: ComponentBuilder.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Component;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.camelot.Entry;
/**
* Component responsible for building componentManager information for entry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface ComponentBuilder
extends Component
{
Object createComponent( String name, Entry entry )
throws Exception;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ComponentManagerBuilder.java
Index: ComponentManagerBuilder.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Component;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.camelot.Entry;
/**
* Component responsible for building componentManager information for entry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface ComponentManagerBuilder
extends Component
{
ComponentManager createComponentManager( String name, Entry entry )
throws ComponentManagerException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/CompositionStage.java
Index: CompositionStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.camelot.Entry;
/**
* Composer stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class CompositionStage
extends AbstractLifeCycleStage
implements Composer
{
protected ComponentManagerBuilder m_builder;
public CompositionStage()
{
m_service = Composer.class;
m_serviceName = "Compose";
}
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_builder = (ComponentManagerBuilder)componentManager.
lookup( "org.apache.avalon.camelot.pipeline.ComponentManagerBuilder" );
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Composer)object).compose( m_builder.createComponentManager( name, entry ) );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ConfigurationRepository.java
Index: ConfigurationRepository.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Component;
import org.apache.avalon.camelot.Entry;
import org.apache.avalon.configuration.Configuration;
import org.apache.avalon.configuration.ConfigurationException;
/**
* Repository from which all configuration data is retrieved.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface ConfigurationRepository
extends Component
{
Configuration getConfiguration( String name, Entry entry )
throws ConfigurationException;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ConfigurationStage.java
Index: ConfigurationStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.camelot.Entry;
import org.apache.avalon.configuration.Configurable;
/**
* Configuration stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
*/
public class ConfigurationStage
extends AbstractLifeCycleStage
implements Composer
{
protected ConfigurationRepository m_repository;
public ConfigurationStage()
{
m_service = Configurable.class;
m_serviceName = "Configure";
}
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_repository = (ConfigurationRepository)componentManager.
lookup( "org.apache.avalon.camelot.pipeline.ConfigurationRepository" );
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Configurable)object).configure( m_repository.getConfiguration( name, entry ) );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ContextBuilder.java
Index: ContextBuilder.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Component;
import org.apache.avalon.Context;
import org.apache.avalon.camelot.Entry;
/**
* Component responsible for building context information for entry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface ContextBuilder
extends Component
{
Context createContext( String name, Entry entry );
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ContextualizationStage.java
Index: ContextualizationStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.Contextualizable;
import org.apache.avalon.camelot.Entry;
/**
* Setup context for avalon component.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class ContextualizationStage
extends AbstractLifeCycleStage
implements Composer
{
protected ContextBuilder m_builder;
public ContextualizationStage()
{
m_service = Contextualizable.class;
m_serviceName = "Contextualize";
}
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_builder = (ContextBuilder)componentManager.
lookup( "org.apache.avalon.camelot.pipeline.ContextBuilder" );
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Contextualizable)object).contextualize( m_builder.createContext( name, entry ) );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/CreationStage.java
Index: CreationStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.camelot.Entry;
/**
* Composer stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class CreationStage
extends AbstractLoggable
implements LifeCycleStage, Composer
{
protected ComponentBuilder m_builder;
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_builder = (ComponentBuilder)componentManager.
lookup( "org.apache.avalon.camelot.pipeline.ComponentBuilder" );
}
/**
* Create an object for entry.
*
* @param entry the entry
* @exception Exception if an error occurs
*/
public void process( final String name, final Entry entry )
throws Exception
{
getLogger().debug( "Processing Creation Stage for " + name );
final Object object = m_builder.createComponent( name, entry );
entry.setInstance( object );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/DisposingStage.java
Index: DisposingStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Disposable;
import org.apache.avalon.camelot.Entry;
/**
* Disposal stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
*/
public class DisposingStage
extends AbstractLifeCycleStage
{
public DisposingStage()
{
m_service = Disposable.class;
m_serviceName = "Dispose";
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Disposable)object).dispose();
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/InitializationStage.java
Index: InitializationStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Initializable;
import org.apache.avalon.camelot.Entry;
/**
* Initializable stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class InitializationStage
extends AbstractLifeCycleStage
{
public InitializationStage()
{
m_service = Initializable.class;
m_serviceName = "Initialize";
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Initializable)object).init();
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/LifeCyclePipeline.java
Index: LifeCyclePipeline.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import org.apache.avalon.AbstractLoggable;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.Context;
import org.apache.avalon.Contextualizable;
import org.apache.avalon.Initializable;
import org.apache.avalon.Stage;
import org.apache.avalon.camelot.AvalonState;
import org.apache.avalon.camelot.Entry;
/**
* This is basic array based pipeline.
* Stages should only be added *after* (or during) init is called.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class LifeCyclePipeline
extends AbstractLoggable
implements LifeCycleStage, Contextualizable, Composer, Initializable
{
protected ArrayList m_stages = new ArrayList();
protected ArrayList m_states = new ArrayList();
protected boolean m_consumeException;
protected Context m_context;
protected ComponentManager m_componentManager;
public void contextualize( final Context context )
{
m_context = context;
}
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_componentManager = componentManager;
}
/**
* Retrieve size of pipeline (number of stages).
*
* @return the size of pipeline
*/
public int getSize()
{
return m_stages.size();
}
/**
* Retrieve a particular stage of pipeline
*
* @param index the index of stage
* @return the stage
* @exception NoSuchElementException if index >= getSize() or index < 0
*/
public Stage getStage( final int index )
throws NoSuchElementException
{
return (Stage)m_stages.get( index );
}
public void setConsumeException( final boolean consumeException )
{
m_consumeException = consumeException;
}
/**
* Overide this method to add
*
* @exception Exception if an error occurs
*/
public void init()
throws Exception
{
}
public void addStage( final AvalonState state, final LifeCycleStage stage )
throws Exception
{
setupStage( stage );
m_states.add( state );
m_stages.add( stage );
}
protected void setupStage( final LifeCycleStage stage )
throws Exception
{
setupLogger( stage );
if( stage instanceof Contextualizable )
{
((Contextualizable)stage).contextualize( m_context );
}
if( stage instanceof Composer )
{
((Composer)stage).compose( m_componentManager );
}
if( stage instanceof Initializable )
{
((Initializable)stage).init();
}
}
/**
* Process an avalon entry.
* Processing includes managing some aspect of blocks lifecycle
* and could be configuring, exporting, replicating, composing etc.
*
* @param entry the entry
* @exception Exception if an error occurs
*/
public void process( final String name, final Entry entry )
throws Exception
{
final int size = m_stages.size();
for( int i = 0; i < size; i++ )
{
final AvalonState state = (AvalonState)m_states.get( i );
try
{
final LifeCycleStage stage = (LifeCycleStage)m_stages.get( i );
getLogger().debug( "Pre-" + state.getName() + " for component " + name );
stage.process( name, entry );
entry.setState( state );
getLogger().debug( "Post-" + state.getName() + " for component " + name );
}
catch( final Exception e )
{
m_logger.debug( "Error in " + state.getName() + " for component " + name );
entry.setState( AvalonState.ERROR );
if( m_consumeException )
{
m_logger.warn( "Error processing " + name, e );
}
else
{
throw e;
}
}
}
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/LifeCycleStage.java
Index: LifeCycleStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Stage;
import org.apache.avalon.camelot.Entry;
/**
* Stage used in managing avalon components.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
*/
public interface LifeCycleStage
extends Stage
{
/**
* Process an avalon entry.
* Processing includes managing some aspect of components lifecycle
* and could be configuring, exporting, replicating, composing etc.
*
* @param entry the entry
* @exception Exception if an error occurs
*/
void process( String name, Entry entry )
throws Exception;
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/LoggerBuilder.java
Index: LoggerBuilder.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Component;
import org.apache.avalon.camelot.Entry;
import org.apache.log.Logger;
/**
* Component responsible for building logger for entry.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public interface LoggerBuilder
extends Component
{
Logger createLogger( String name, Entry entry );
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/LoggerStage.java
Index: LoggerStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.Composer;
import org.apache.avalon.Loggable;
import org.apache.avalon.camelot.Entry;
/**
* Loggable stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
*/
public class LoggerStage
extends AbstractLifeCycleStage
implements Composer
{
protected LoggerBuilder m_builder;
public LoggerStage()
{
m_service = Loggable.class;
m_serviceName = "Logger";
}
public void compose( final ComponentManager componentManager )
throws ComponentManagerException
{
m_builder = (LoggerBuilder)componentManager.
lookup( "org.apache.avalon.camelot.pipeline.LoggerBuilder" );
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Loggable)object).setLogger( m_builder.createLogger( name, entry ) );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/OldConfigurationStage.java
Index: OldConfigurationStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Configurable;
import org.apache.avalon.DefaultConfiguration;
import org.apache.avalon.camelot.Entry;
import org.apache.avalon.configuration.Configuration;
/**
* Configuration stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @deprecated This has been deprecated in favour of new ConfigurationStage class
*/
public class OldConfigurationStage
extends ConfigurationStage
{
public OldConfigurationStage()
{
m_service = Configurable.class;
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
final DefaultConfiguration configuration =
transform( m_repository.getConfiguration( name, entry ) );
((Configurable)object).configure( configuration );
}
public final static DefaultConfiguration transform( final Configuration configuration )
{
final DefaultConfiguration newConfiguration =
new DefaultConfiguration( configuration.getName(), configuration.getLocation() );
final Configuration[] children = configuration.getChildren();
for( int i = 0; i < children.length; i++ )
{
newConfiguration.addChild( transform( children[ i ] ) );
}
final String[] attributeNames = configuration.getAttributeNames();
for( int i = 0; i < attributeNames.length; i++ )
{
final String value = configuration.getAttribute( attributeNames[ i ], null );
newConfiguration.addAttribute( attributeNames[ i ], value );
}
final String value = configuration.getValue( null );
if( null != value )
{
newConfiguration.appendValueData( value );
}
return newConfiguration;
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/RunnerStage.java
Index: RunnerStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.camelot.Entry;
import org.apache.avalon.util.thread.ThreadContext;
/**
* Runner stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
*/
public class RunnerStage
extends AbstractLifeCycleStage
{
public RunnerStage()
{
m_service = Runnable.class;
m_serviceName = "Run";
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
ThreadContext.getCurrentThreadPool().execute( (Runnable)object );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/ShutdownPipeline.java
Index: ShutdownPipeline.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.camelot.AvalonState;
/**
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class ShutdownPipeline
extends LifeCyclePipeline
{
public void init()
throws Exception
{
addStage( AvalonState.STOPPED, new StopStage() );
addStage( AvalonState.DISPOSED, new DisposingStage() );
setConsumeException( true );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/StartStage.java
Index: StartStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Startable;
import org.apache.avalon.camelot.Entry;
/**
* Start stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class StartStage
extends AbstractLifeCycleStage
{
public StartStage()
{
m_service = Startable.class;
m_serviceName = "Start";
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Startable)object).start();
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/StartupPipeline.java
Index: StartupPipeline.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.camelot.AvalonState;
/**
* This is basic array based pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class StartupPipeline
extends LifeCyclePipeline
{
public void init()
throws Exception
{
addStage( AvalonState.CREATED, new CreationStage() );
addStage( AvalonState.LOGGED, new LoggerStage() );
addStage( AvalonState.CONTEXTUALIZED, new ContextualizationStage() );
addStage( AvalonState.COMPOSED, new CompositionStage() );
addStage( AvalonState.CONFIGURED, new ConfigurationStage() );
//will be removed in future...
addStage( AvalonState.CONFIGURED, new OldConfigurationStage() );
addStage( AvalonState.INITIALIZED, new InitializationStage() );
addStage( AvalonState.STARTED, new StartStage() );
addStage( AvalonState.RUNNING, new RunnerStage() );
}
}
1.1 jakarta-avalon/src/java/org/apache/avalon/camelot/pipeline/StopStage.java
Index: StopStage.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 file.
*/
package org.apache.avalon.camelot.pipeline;
import org.apache.avalon.Stoppable;
import org.apache.avalon.camelot.Entry;
/**
* Stop stage for avalon pipeline.
*
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
*/
public class StopStage
extends AbstractLifeCycleStage
{
public StopStage()
{
m_service = Stoppable.class;
m_serviceName = "Stop";
}
protected void process( final String name, final Entry entry, final Object object )
throws Exception
{
((Stoppable)object).stop();
}
}