mcconnell 2003/01/09 03:25:27 Modified: assembly/src/java/org/apache/avalon/assembly/appliance Appliance.java ApplianceContext.java DefaultAppliance.java DefaultApplianceContext.java assembly/src/java/org/apache/avalon/assembly/engine EngineClassLoader.java Resources.properties assembly/src/java/org/apache/avalon/assembly/locator DefaultLocator.java Locator.java LocatorException.java assembly/src/test/org/apache/avalon/assembly/engine EngineTestCase.java assembly/src/xdocs why.xml Log: Seperation of appliance factory concerns from the classloader implementation. Revision Changes Path 1.19 +13 -2 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/Appliance.java Index: Appliance.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/Appliance.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Appliance.java 8 Jan 2003 18:33:20 -0000 1.18 +++ Appliance.java 9 Jan 2003 11:25:26 -0000 1.19 @@ -55,10 +55,13 @@ import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.logger.LogEnabled; import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.assembly.lifestyle.LifestyleException; import org.apache.avalon.assembly.lifecycle.AssemblyException; +import org.apache.avalon.assembly.locator.Contextualizable; import org.apache.avalon.meta.info.DependencyDescriptor; import org.apache.avalon.meta.info.StageDescriptor; import org.apache.avalon.meta.model.LoggingDirective; @@ -75,13 +78,21 @@ * @version $Revision$ $Date$ */ -public interface Appliance +public interface Appliance extends LogEnabled, Contextualizable, Initializable { /** * Meta-info attribute name under which an alternative appliance class may be declared. */ static final String APPLIANCE_CLASS_ATTRIBUTE_NAME = "urn:assembly:appliance.class"; + + /** + * Meta-info attribute name under which an custom appliance factory may be declared + * by a component type. + */ + static final String APPLIANCE_FACTORY_KEY = + "urn:assembly:appliance.factory"; + /** * Get the appliance name. 1.8 +7 -1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceContext.java Index: ApplianceContext.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ApplianceContext.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ApplianceContext.java 27 Dec 2002 16:21:41 -0000 1.7 +++ ApplianceContext.java 9 Jan 2003 11:25:26 -0000 1.8 @@ -171,6 +171,12 @@ String getApplianceClassname(); /** + * Get the appliance factory classname. + * @return the classname of the appliance factory. + */ + String getApplianceFactoryClassname(); + + /** * Get the appliance profile. * @return the profile */ 1.21 +42 -51 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java Index: DefaultAppliance.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- DefaultAppliance.java 27 Dec 2002 16:21:55 -0000 1.20 +++ DefaultAppliance.java 9 Jan 2003 11:25:26 -0000 1.21 @@ -64,12 +64,8 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.context.Context; -import org.apache.avalon.framework.context.DefaultContext; import org.apache.avalon.framework.context.ContextException; -import org.apache.avalon.framework.context.Contextualizable; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; -import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.context.DefaultContext; import org.apache.avalon.assembly.engine.Engine; import org.apache.avalon.assembly.engine.EngineClassLoader; @@ -88,6 +84,9 @@ import org.apache.avalon.meta.model.LoggingDirective; import org.apache.avalon.meta.model.ContextDirective; +import org.apache.avalon.assembly.locator.Locator; +import org.apache.avalon.assembly.locator.Contextualizable; + /** * Default implementation of an appliance that supports the association of * depedent appliance instances, appliance lifestyle handler, and establishes @@ -96,7 +95,7 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public class DefaultAppliance implements Appliance +public class DefaultAppliance extends AbstractLogEnabled implements Appliance, Contextualizable, Initializable { //===================================================================== // static @@ -169,7 +168,7 @@ /** * The logging channel. */ - private Logger m_logger; + //private Logger m_logger; /** * The appliance URL. @@ -201,50 +200,41 @@ */ private Class m_class; - //============================================================== - // constructor - //============================================================== + private LifestyleService m_lifestyle; - public DefaultAppliance( - EngineClassLoader engine, LifestyleService lifestyle, AssemblyService assembly, - ApplianceContext context, Context system, Logger logger ) - throws ApplianceException + //===================================================================== + // Contextualizable + //===================================================================== + + /** + * Supply a object locator to the instance. + * @param locator the object locator + * @exception LocatorException if a object location error occurs + */ + public void contextualize( Locator context ) throws ContextException + { + m_engine = (EngineClassLoader) context.get( "urn:assembly:engine" ); + m_assembly = (AssemblyService) context.get( "urn:assembly:assembly.service" ); + m_lifestyle = (LifestyleService) context.get( "urn:assembly:lifestyle.service" ); + m_applianceContext = (ApplianceContext) context.get( "urn:assembly:appliance.context" ); + m_system = (Context) context.get( "urn:assembly:appliance.system" ); + } + + //===================================================================== + // Initializable + //===================================================================== + + public void initialize() throws Exception { - if( engine == null ) - { - throw new NullPointerException( "engine" ); - } - if( context == null ) - { - throw new NullPointerException( "context" ); - } - if( lifestyle == null ) - { - throw new NullPointerException( "lifestyle" ); - } - if( assembly == null ) - { - throw new NullPointerException( "assembly" ); - } - if( system == null ) + if( m_engine == null ) { - throw new NullPointerException( "system" ); + throw new IllegalStateException( "engine" ); } - if( logger == null ) - { - throw new NullPointerException( "logger" ); - } - - m_assembly = assembly; - m_applianceContext = context; - m_logger = logger; - m_engine = engine; - m_system = system; String classname = getType().getInfo().getClassname(); try { - m_class = engine.loadClass( classname ); + m_class = m_engine.loadClass( classname ); } catch( Throwable e ) { @@ -262,7 +252,7 @@ { m_domain = "localhost"; } - m_name = context.getName(); + m_name = m_applianceContext.getName(); m_path = m_applianceContext.getPartitionName() + m_name; // @@ -271,7 +261,7 @@ try { - m_handler = lifestyle.createHandler( this, engine, system ); + m_handler = m_lifestyle.createHandler( this, m_engine, m_system ); } catch( Throwable e ) { @@ -279,6 +269,7 @@ "Unexpected lifestyle handler establishment failure in appliance: " + this; throw new ApplianceException( error, e ); } + } //===================================================================== @@ -444,7 +435,7 @@ } else { - return Contextualizable.class.isAssignableFrom( m_class ); + return org.apache.avalon.framework.context.Contextualizable.class.isAssignableFrom( m_class ); } } @@ -712,8 +703,8 @@ * Return the loging channel for the appliance. * @return the logging channel */ - protected Logger getLogger() - { - return m_logger; - } + //protected Logger getLogger() + //{ + // return m_logger; + //} } 1.5 +38 -1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceContext.java Index: DefaultApplianceContext.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultApplianceContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DefaultApplianceContext.java 28 Dec 2002 01:29:45 -0000 1.4 +++ DefaultApplianceContext.java 9 Jan 2003 11:25:26 -0000 1.5 @@ -159,6 +159,11 @@ */ private String m_classname; + /** + * The appliance factory classname. + */ + private String m_factory; + //============================================================== // constructor @@ -212,6 +217,38 @@ else { return m_classname; + } + } + + /** + * Get the appliance factory classname. + * @param classname of the appliance factory implementation. + * @exception NullPointerException if the supplied classname is null + * @exception IllegalStateException if the context is write protected + */ + public void setApplianceFactoryClassname( String classname ) + { + checkWriteable(); + if( classname == null ) + { + throw new NullPointerException( "classname" ); + } + m_factory = classname; + } + + /** + * Get the appliance base classname. + * @return the classname of the appliance factory (null if undefined) + */ + public String getApplianceFactoryClassname() + { + if( m_factory == null ) + { + return getType().getInfo().getAttribute( Appliance.APPLIANCE_FACTORY_KEY ); + } + else + { + return m_factory; } } 1.23 +85 -379 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java Index: EngineClassLoader.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/EngineClassLoader.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- EngineClassLoader.java 9 Jan 2003 03:58:26 -0000 1.22 +++ EngineClassLoader.java 9 Jan 2003 11:25:26 -0000 1.23 @@ -67,6 +67,8 @@ import org.apache.avalon.assembly.engine.type.TypeManager; import org.apache.avalon.assembly.engine.profile.ProfileManager; import org.apache.avalon.assembly.appliance.Appliance; +import org.apache.avalon.assembly.appliance.ApplianceFactory; +import org.apache.avalon.assembly.appliance.DefaultApplianceFactory; import org.apache.avalon.assembly.appliance.ApplianceContext; import org.apache.avalon.assembly.appliance.DefaultApplianceContext; import org.apache.avalon.assembly.appliance.ApplianceException; @@ -74,25 +76,17 @@ import org.apache.avalon.assembly.appliance.DefaultAppliance; import org.apache.avalon.assembly.appliance.DefaultApplianceManager; import org.apache.avalon.assembly.appliance.DependencyGraph; -import org.apache.avalon.assembly.appliance.MappedServiceManager; -import org.apache.avalon.assembly.lifecycle.AssemblyService; -import org.apache.avalon.assembly.lifecycle.DefaultAssemblyService; -import org.apache.avalon.assembly.lifecycle.AssemblyException; -import org.apache.avalon.assembly.lifecycle.DeploymentService; -import org.apache.avalon.assembly.lifecycle.DefaultDeploymentService; -import org.apache.avalon.assembly.lifestyle.LifestyleException; -import org.apache.avalon.assembly.lifestyle.LifestyleService; -import org.apache.avalon.assembly.lifestyle.DefaultLifestyleService; -import org.apache.avalon.assembly.lifestyle.LifestyleHandler; -import org.apache.avalon.assembly.logging.LoggingDescriptor; -import org.apache.avalon.assembly.logging.DefaultLoggingManager; -import org.apache.avalon.assembly.logging.LoggingManager; -import org.apache.avalon.assembly.logging.TargetDescriptor; import org.apache.avalon.assembly.engine.model.LibraryDescriptor; import org.apache.avalon.assembly.engine.model.ClasspathDescriptor; import org.apache.avalon.assembly.engine.model.FilesetDescriptor; import org.apache.avalon.assembly.engine.model.IncludeDescriptor; import org.apache.avalon.assembly.engine.model.ClasspathDescriptor; +import org.apache.avalon.assembly.logging.LoggingDescriptor; +import org.apache.avalon.assembly.logging.DefaultLoggingManager; +import org.apache.avalon.assembly.logging.LoggingManager; +import org.apache.avalon.assembly.logging.TargetDescriptor; +import org.apache.avalon.assembly.locator.Locator; +import org.apache.avalon.assembly.locator.DefaultLocator; import org.apache.avalon.framework.Version; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.logger.Logger; @@ -117,18 +111,14 @@ import org.apache.avalon.meta.model.Profile; import org.apache.avalon.meta.model.LoggingDirective; import org.apache.avalon.meta.model.Category; -import org.apache.avalon.excalibur.extension.Extension; -import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; +import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.packagemanager.OptionalPackage; import org.apache.avalon.excalibur.packagemanager.PackageManager; import org.apache.avalon.excalibur.packagemanager.ExtensionManager; import org.apache.avalon.excalibur.packagemanager.impl.DefaultExtensionManager; import org.apache.avalon.excalibur.packagemanager.impl.DelegatingExtensionManager; -import org.apache.excalibur.mpool.DefaultPoolManager; -import org.apache.excalibur.mpool.PoolManager; -import org.apache.excalibur.event.command.CommandManager; -import org.apache.excalibur.event.command.TPCThreadManager; +import org.apache.avalon.excalibur.extension.Extension; /** * Default implementation of the service management engine. @@ -136,7 +126,8 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public class EngineClassLoader extends URLClassLoader implements Engine, LogEnabled, Configurable, Contextualizable, Serviceable, Initializable +public class EngineClassLoader extends URLClassLoader + implements Engine, LogEnabled, Contextualizable, Initializable { //============================================================== // static @@ -166,15 +157,9 @@ private DependencyGraph m_graph; /** - * The supplied configuration. The configuration may be empty - * as defaults are provided for all values. - */ - private Configuration m_config; - - /** * The base system wide context. */ - private Context m_system; + private Locator m_system; /** * The system wide context where system refers to the context that @@ -199,16 +184,6 @@ private DefaultRepositoryManager m_repository; /** - * The lifestyle service. - */ - private LifestyleService m_lifestyle; - - /** - * The assembly service. - */ - private AssemblyService m_assembly; - - /** * A map of custom context entries that suppliment the standard system * context at the scope of this engine. The map is supplied by a client * at the time of engine establishment via the engine context. @@ -261,6 +236,11 @@ */ private boolean m_bootstrap = false; + /** + * Default appliance factory. + */ + private ApplianceFactory m_factory; + //======================================================================= // constructor //======================================================================= @@ -277,6 +257,7 @@ /** * Creation of a new engine with a parent. + * @param parent the parent classloader */ public EngineClassLoader( ClassLoader parent ) { @@ -287,6 +268,8 @@ /** * Creation of a new engine with a partner and URL array. + * @param urls a set of URLs to add to the classloader + * @param parent the parent classloader */ public EngineClassLoader( URL[] urls, ClassLoader parent ) { @@ -319,22 +302,6 @@ } //============================================================== - // Configurable - //============================================================== - - /** - * Supply of the static configuration for the deployment service. - * @param config the static configuration - */ - public void configure( Configuration config ) throws ConfigurationException - { - if( config == null ) - { - throw new NullPointerException( "config" ); - } - } - - //============================================================== // Contextualizable //============================================================== @@ -392,35 +359,16 @@ { // use default value } - } - - //============================================================== - // Serviceable - //============================================================== - /** - * <p>Application of a supporting service to the engine.</p> - * <table> - * <tr> - * <td>key</td><td>type</td><td>description</td> - * </tr> - * <tr> - * <td>urn:assembly:logging.manager</td> - * <td>[EMAIL PROTECTED] org.apache.avalon.assembly.logging.LoggingManager}</td> - * <td>A logging manager.</td> - * </tr> - * </table> - * @param manager the service manager - */ - public void service( ServiceManager manager ) throws ServiceException - { - if( manager == null ) + try { - throw new NullPointerException( "manager" ); + String key = "urn:assembly:logging.manager"; + m_logging = (LoggingManager) context.get( key ); + } + catch( ContextException ce ) + { + // optional } - - String key = "urn:assembly:logging.manager"; - m_logging = (LoggingManager) manager.lookup( key ); } //============================================================== @@ -445,15 +393,14 @@ if( getLogger().isDebugEnabled() ) { - getLogger().debug( "initialization" ); + getLogger().debug( REZ.getString( "initialization" ) ); } createRepositoryManager(); - - m_assembly = createAssemblyService( m_facilities, m_graph ); - m_lifestyle = createLifestyleService( m_facilities ); + m_factory = DefaultApplianceFactory.createApplianceFactory( + this, getLogger(), getSystemContext() ); m_appliances = createApplianceManager( m_facilities ); - + // // install the set of extensions // @@ -467,11 +414,11 @@ if( include.isDirectory() ) { list.add( include ); - getLogger().debug( "including kernel extension dir: " + include ); + getLogger().debug( REZ.getString( "kernel.extension", include ) ); } else { - final String error = "Invalid include directory: " + include; + final String error = REZ.getString( "error.include", include ); throw new IllegalArgumentException( error ); } } @@ -495,7 +442,8 @@ list.add( test ); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "including system extension dir: " + test ); + final String msg = REZ.getString( "system.extension", token ); + getLogger().debug( msg ); } } else @@ -506,17 +454,14 @@ list.add( file ); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "including relative extension dir: " + file ); + getLogger().debug( REZ.getString( "relative.extension", file ) ); } } else { if( getLogger().isWarnEnabled() ) { - final String warning = - "The extension directory path: '" + token - + "' does not refer to a directory."; - getLogger().warn( warning ); + getLogger().warn( REZ.getString( "extension.warning", token ) ); } } } @@ -548,7 +493,7 @@ if( getLogger().isDebugEnabled() ) { - getLogger().debug( "bootstraping from classpath" ); + getLogger().debug( REZ.getString( "bootstrap.classpath" ) ); } // @@ -565,7 +510,7 @@ URL url = new File( token ).getCanonicalFile().toURL(); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "path: " + url ); + getLogger().debug( REZ.getString( "bootstrap.path", url ) ); } addURL( url ); } @@ -581,7 +526,7 @@ } catch( Throwable e ) { - final String error = "Classpath deployment failure."; + final String error = REZ.getString( "error.classpath" ); throw new EngineException( error, e ); } @@ -592,13 +537,16 @@ for( int i=0; i<m_urls.length; i++ ) { URL url = m_urls[i]; - getLogger().debug("processing: '" + url + "'." ); + if( getLogger().isDebugEnabled() ) + { + getLogger().debug( REZ.getString( "processing.url", url ) ); + } addURL( url ); } if( getLogger().isDebugEnabled() ) { - getLogger().debug( "ready" ); + getLogger().debug( REZ.getString( "ready" ) ); } } @@ -670,7 +618,7 @@ super.addURL( url ); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "add: " + url ); + getLogger().debug( REZ.getString( "add.url", url ) ); } m_repository.install( url ); } @@ -686,22 +634,20 @@ { throw new NullPointerException( "classpath" ); } - if( getLogger() == null ) { throw new IllegalStateException( "logging" ); } - if( getLogger().isDebugEnabled() ) { - getLogger().debug( "adding classpath" ); + getLogger().debug( REZ.getString( "add.classpath" ) ); } List list = new ArrayList(); FilesetDescriptor[] dirs = classpath.getFilesetDescriptors(); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "classpath contains " + dirs.length + " fileset entries"); + getLogger().debug( REZ.getString( "add.classpath.info", "" + dirs.length ) ); } for( int i = 0; i < dirs.length; i++ ) @@ -713,24 +659,20 @@ anchor = new File( m_home, descriptor.getBaseDirectory() ).getCanonicalFile(); if( !anchor.exists() ) { - final String error = - "Classpath base directory does not exist: " - + anchor; - throw new EngineRuntimeException( error ); + throw new EngineRuntimeException( + REZ.getString( "classpath.dir.error", anchor ) ); } } catch( Throwable e ) { - final String error = - "Error processing a classpath bae directory: " - + descriptor; - throw new EngineRuntimeException( error, e ); + throw new EngineRuntimeException( + REZ.getString( "classpath.base.error", descriptor ) , e ); } IncludeDescriptor[] includes = descriptor.getIncludeDescriptors(); if( getLogger().isDebugEnabled() ) { - getLogger().debug( "fileset contains " + includes.length + " iinclude entries"); + getLogger().debug( REZ.getString( "classpath.include", "" + includes.length ) ); } for( int j = 0; j < includes.length; j++ ) { @@ -741,17 +683,14 @@ } catch( Throwable e ) { - final String error = - "Error processing a classpath include: " - + inc; - throw new EngineRuntimeException( error, e ); + throw new EngineRuntimeException( + REZ.getString( "classpath.include.error", inc ) , e ); } } } - if( getLogger().isDebugEnabled() ) { - getLogger().debug( "classpath ok" ); + getLogger().debug( REZ.getString( "classpath.ok" ) ); } } @@ -776,16 +715,14 @@ } catch( Throwable e ) { - final String error = - "Internal error while attempting to add optional package: " + ext; + final String error = REZ.getString("add.ext.error", ext ); throw new EngineRuntimeException( error, e ); } } } catch( Throwable e ) { - final String error = - "Internal error while attempting to add extension url: " + url; + final String error = REZ.getString("add.extension.error", url ); throw new EngineRuntimeException( error, e ); } } @@ -812,7 +749,7 @@ { if( getLogger().isDebugEnabled() ) { - getLogger().debug( "register:" + path ); + getLogger().debug( REZ.getString( "register.path", path ) ); } TypeManager types = getRepository().getTypeManager(); @@ -826,7 +763,7 @@ } catch( Throwable e ) { - // type is already registered + // type already registered } } @@ -867,9 +804,7 @@ Profile profile = getRepository().getProfileManager().getProfile( dependency ); if( profile == null ) { - final String error = - "No profiles matching the requested dependency: " - + dependency; + final String error = REZ.getString( "resolve.fail", dependency ); throw new EngineException( error ); } else @@ -911,18 +846,15 @@ if( getLogger().isDebugEnabled() ) { - getLogger().debug( "resolve: " + stage ); + getLogger().debug( REZ.getString( "resolve.stage.notice", stage ) ); } - Appliance appliance = m_appliances.getAppliance( stage ); if( appliance == null ) { Profile profile = getRepository().getProfileManager().getProfile( stage ); if( profile == null ) { - final String error = - "No profiles matching the requested stage: " - + stage; + final String error = REZ.getString( "resolve.stage.fail", stage ); throw new EngineException( error ); } else @@ -945,113 +877,32 @@ */ public Appliance createAppliance( ApplianceContext context, boolean shared ) throws ApplianceException { + if( context == null ) + { + throw new NullPointerException( "context" ); + } + String classname = context.getApplianceFactoryClassname(); Appliance appliance; - try + if( classname == null ) { - String name = context.getName(); - Logger logger = getLogger().getChildLogger( name ); - appliance = buildAppliance( context, getSystemContext(), logger ); + appliance = m_factory.createAppliance( this, context ); } - catch( Throwable e ) + else { - final String error = - "Unable to create appliance for: " - + context.getPartitionName() - + "/" + context.getName(); - throw new ApplianceException( error, e ); + String name = context.getName(); + Logger logger = getLogger().getChildLogger( name ); + ApplianceFactory factory = + DefaultApplianceFactory.createApplianceFactory( + this, classname, logger, getSystemContext() ); + appliance = factory.createAppliance( this, context ); } - if( shared ) { m_appliances.addAppliance( appliance ); } - - if( getLogger().isDebugEnabled() ) - { - try - { - getLogger().debug( "created " + appliance.getURL() ); - } - catch( Throwable e ) - { - getLogger().debug( "created " + appliance ); - } - } - return appliance; } - private Appliance buildAppliance( ApplianceContext context, Context system, Logger logger ) - throws ClassNotFoundException, ApplianceException - { - String classname = context.getApplianceClassname(); - if( classname != null ) - { - Class clazz; - try - { - clazz = loadClass( classname ); - } - catch( ClassNotFoundException cnfe ) - { - throw new ClassNotFoundException( - "Could not find appliance class " + classname, cnfe ); - } - - try - { - Constructor constructor = clazz.getConstructor( - new Class[]{ - EngineClassLoader.class, - LifestyleService.class, - AssemblyService.class, - ApplianceContext.class, - Context.class, - Logger.class } ); - Object[] args = new Object[]{ - this, - m_lifestyle, - m_assembly, - context, - system, - logger }; - return (Appliance) constructor.newInstance( args ); - } - catch( NoSuchMethodException nsme ) - { - throw new ApplianceException( - "The supplied classname: '" - + classname - + "' does not implement a constructor matching the pattern: ( " - + Engine.class.getName() - + ", " + LifestyleService.class.getName() - + ", " + AssemblyService.class.getName() - + ", " + ApplianceContext.class.getName() - + ", " + Context.class.getName() - + ", " + Logger.class.getName() - + " )." ); - } - catch( ClassCastException cce ) - { - throw new ApplianceException( - "The supplied classname: '" - + classname - + "' does not implement the interface: " - + Appliance.class.getName() ); - } - catch( Throwable e ) - { - throw new ApplianceException( - "Unexpected exception while creating appliance from " - + classname, e ); - } - } - else - { - return new DefaultAppliance( this, m_lifestyle, m_assembly, context, system, logger ); - } - } - //============================================================== // utilities //============================================================== @@ -1086,7 +937,6 @@ { if( getParent() instanceof EngineClassLoader ) { - // nothing to do return new URL[0]; } else @@ -1147,7 +997,6 @@ } DefaultApplianceManager manager = new DefaultApplianceManager(); - manager.enableLogging( getLogger() ); manager.contextualize( new DefaultContext() ); // <-- placeholder for parent manager DefaultServiceManager services = new DefaultServiceManager(); @@ -1158,95 +1007,7 @@ return manager; } - /** - * Utility to create the default lifestyle service. - * @param manager a service manager - * @return the bootstrap lifestyle service - */ - private LifestyleService createLifestyleService( Map facilities ) throws Exception - { - if( getLogger().isDebugEnabled() ) - { - getLogger().debug( "creating lifestyle service" ); - } - - DeploymentService deployment = bootstrapDeploymentService( facilities ); - - DefaultLifestyleService lifestyle = new DefaultLifestyleService(); - lifestyle.enableLogging( getLogger().getChildLogger( "lifestyle" ) ); - DefaultServiceManager manager = new DefaultServiceManager(); - manager.put( "urn:assembly:lifecycle.deployment", deployment ); - manager.put( "urn:assembly:engine.classloader", this ); - manager.makeReadOnly(); - lifestyle.service( manager ); - DefaultContext context = new DefaultContext(); - context.put( "urn:assembly:pool-manager", getPoolManager( ) ); - context.makeReadOnly(); - lifestyle.contextualize( context ); - lifestyle.initialize(); - return lifestyle; - } - - private DeploymentService bootstrapDeploymentService( Map facilities ) - throws ServiceException - { - try - { - DefaultDeploymentService deployment = new DefaultDeploymentService(); - deployment.enableLogging( getLogger() ); - MappedServiceManager manager = new MappedServiceManager( facilities ); - manager.put("urn:assembly:logging.manager", m_logging ); - manager.put("urn:assembly:engine.classloader", this ); - deployment.service( manager ); - deployment.contextualize( new DefaultContext() ); - deployment.initialize(); - return deployment; - } - catch( Throwable e ) - { - final String error = - "Internal error while attempting to create bootstrap deployment service."; - throw new ServiceException( error, e ); - } - } - - /** - * Utility to create the default assembly service. - * @param manager a service manager - * @return the bootstrap assembly service - */ - private AssemblyService createAssemblyService( Map facilities, DependencyGraph map ) - throws ServiceException - { - if( getLogger().isDebugEnabled() ) - { - getLogger().debug( "creating assembly service" ); - } - - try - { - DefaultAssemblyService assembly = new DefaultAssemblyService(); - assembly.enableLogging( getLogger().getChildLogger( "assembly" ) ); - MappedServiceManager manager = new MappedServiceManager( facilities ); - manager.put("urn:assembly:engine.classloader", this ); - assembly.service( manager ); - DefaultContext context = new DefaultContext(); - if( map != null ) - { - context.put( "urn:assembly:dependency-map", map ); - } - assembly.contextualize( context ); - assembly.initialize(); - return assembly; - } - catch( Throwable e ) - { - final String error = "Internal error while preparing boostrap assembly service."; - throw new ServiceException( "urn:assembly:assembly-service", error, e ); - } - } - - private Context getSystemContext() + private Locator getSystemContext() { if( m_system != null ) { @@ -1258,14 +1019,14 @@ getLogger().debug( "resolving system context" ); } - DefaultContext context; + DefaultLocator context; if( m_map != null ) { - context = new DefaultContext( m_map ); + context = new DefaultLocator( m_map ); } else { - context = new DefaultContext(); + context = new DefaultLocator(); } try @@ -1287,55 +1048,12 @@ context.put( "urn:assembly:domain", "localhost" ); } + context.put( "urn:assembly:logging", getLoggingManager() ); + context.put( "urn:assembly:dependency.graph", getDependencyGraph() ); m_system = context; return m_system; } - private PoolManager getPoolManager( ) - { - if( getLogger().isDebugEnabled() ) - { - getLogger().debug( "bootstrap pool manager" ); - } - - try - { - // - // Set up the ThreadManager that the CommandManager uses - // - - TPCThreadManager threadManager = new TPCThreadManager(); - threadManager.enableLogging( getLogger().getChildLogger( "threads" ) ); - Parameters params = new Parameters(); - params.setParameter( "threads-per-processor", "2" ); - params.setParameter( "sleep-time", "1000" ); - params.setParameter( "block-timeout", "250" ); - threadManager.parameterize( params ); - threadManager.initialize(); - - // - // Set up the CommandManager that the PoolManager uses. - // - - CommandManager commandManager = new CommandManager(); - threadManager.register( commandManager ); - - // - // Set up the PoolManager that the pooled lifecycle helper needs - // - - DefaultPoolManager poolManager = - new DefaultPoolManager( commandManager.getCommandSink() ); - return poolManager; - } - catch( Throwable e ) - { - final String error = - "Internal error during establishment of the default pool manager."; - throw new EngineRuntimeException( error, e ); - } - } - private boolean isDirectory( URL url ) { if( url.getProtocol().equals( "file" ) ) @@ -1374,7 +1092,6 @@ final Manifest[] manifests = getManifests( classPath ); final Extension[] available = Extension.getAvailable( manifests ); final Extension[] required = Extension.getRequired( manifests ); - final ArrayList dependencies = new ArrayList(); final ArrayList unsatisfied = new ArrayList(); @@ -1413,7 +1130,6 @@ throws Exception { final ArrayList manifests = new ArrayList(); - for( int i = 0; i < classPath.length; i++ ) { final String element = classPath[ i ]; @@ -1437,16 +1153,6 @@ } } } - return (Manifest[])manifests.toArray( new Manifest[ 0 ] ); - } - - /** - * Strips the ".class" ending off of a Type/Block/Service name. - */ - private final String cleanName( String name ) - { - int end = name.indexOf( ".class" ); - return name.substring( 0, ( end >= 0 ) ? end : name.length() ); } } 1.2 +27 -0 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/Resources.properties Index: Resources.properties =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/engine/Resources.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Resources.properties 7 Dec 2002 14:01:42 -0000 1.1 +++ Resources.properties 9 Jan 2003 11:25:26 -0000 1.2 @@ -1,4 +1,31 @@ +initialization=initialization +kernel.extension=including kernel extension dir: {0} +system.extension=including system extension dir: {0} +relative.extension=including relative extension dir: {0} +error.include=Invalid include directory: {0} +extension.warning=The extension directory path: '{0}' does not refer to a directory.; +bootstrap.classpath=bootstraping from classpath +bootstrap.path=path: {0} +error.classpath=path: Classpath deployment failure. +processing.url=processing: {0} +ready=ready +add.url=add: {0} +add.classpath=adding classpath +add.classpath.info=classpath contains {0} fileset entries +classpath.dir.error=Classpath base directory does not exist: {0} +classpath.base.error=Error processing classpath base directory: {0} +classpath.include=fileset contains {0} include entries +classpath.include.error=Error processing a classpath include: {0} +classpath.ok=classpath ok +add.ext.error=Internal error while attempting to add optional package: {0} +add.extension.error=Internal error while attempting to add extension url: {0} +register.path=register: {0} +resolve.fail=No profiles matching the requested dependency: {0} +resolve=No profiles matching the requested dependency: {0} +resolve.stage.notice=resolve: {0} +resolve.stage.fail=No profiles matching the requested stage: {0} + target.nocreate=Error creating LogTarget named "{0}" for file {0}. (Reason: {2}). unknown-priority=Unknown priority "{0}" for Logger named "{1}". category-create=Creating a log category named "{0}" that writes to "{1}" target at priority "{2}". 1.3 +9 -9 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/DefaultLocator.java Index: DefaultLocator.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/DefaultLocator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DefaultLocator.java 27 Dec 2002 16:13:38 -0000 1.2 +++ DefaultLocator.java 9 Jan 2003 11:25:26 -0000 1.3 @@ -60,6 +60,7 @@ import java.util.Map; import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.context.ContextException; /** * Default implementation of Locator. @@ -193,10 +194,10 @@ { try { - get( m_dictionary.translate( key ) ); + getObject( m_dictionary.translate( key ) ); return true; } - catch( LocatorException le ) + catch( ContextException le ) { return false; } @@ -210,8 +211,8 @@ * @return the object resolved from the supplied key * @throws LocatorException if the key is unknown */ - protected Object get( final Object key ) - throws LocatorException + protected Object getObject( final Object key ) + throws ContextException { final Object data = m_data.get( key ); @@ -237,11 +238,11 @@ if( m_parent instanceof DefaultLocator ) { - return ((DefaultLocator)m_parent).get( key ); + return ((DefaultLocator)m_parent).getObject( key ); } else { - return m_parent.locate( key ); + return m_parent.get( key ); } } @@ -252,11 +253,10 @@ * @return the object resolved from the supplied key * @throws LocatorException if the key is unknown */ - public Object locate( final Object key ) - throws LocatorException + public Object get( final Object key ) throws ContextException { - final Object data = get( m_dictionary.translate( key ) ); + final Object data = getObject( m_dictionary.translate( key ) ); if( data instanceof Reclaimable ) { 1.3 +3 -9 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/Locator.java Index: Locator.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/Locator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Locator.java 23 Dec 2002 00:13:35 -0000 1.2 +++ Locator.java 9 Jan 2003 11:25:26 -0000 1.3 @@ -50,6 +50,7 @@ package org.apache.avalon.assembly.locator; +import org.apache.avalon.framework.context.Context; /** * A locator is a general utility class that provides support for the @@ -58,7 +59,7 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public interface Locator +public interface Locator extends Context { /** * Returns TRUE if the supplied key is know by the locator. @@ -66,13 +67,6 @@ * @return TRUE if the key is know else FALSE */ boolean hasEntry( Object key ); - - /** - * Locate an object using a supplied key - * @param key the lookup key - * @return object the object referenced by the key - */ - Object locate( Object key ) throws LocatorException; /** * Return the <code>Object</code> when you are finished with it. This 1.4 +3 -3 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/LocatorException.java Index: LocatorException.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/locator/LocatorException.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LocatorException.java 27 Dec 2002 16:12:59 -0000 1.3 +++ LocatorException.java 9 Jan 2003 11:25:26 -0000 1.4 @@ -50,7 +50,7 @@ package org.apache.avalon.assembly.locator; -import org.apache.avalon.framework.CascadingException; +import org.apache.avalon.framework.context.ContextException; /** * Exception to indicate that there was a lifecycle related error. @@ -59,7 +59,7 @@ * @version $Revision$ $Date$ */ public class LocatorException - extends CascadingException + extends ContextException { final Object m_key; 1.11 +1 -4 avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/EngineTestCase.java Index: EngineTestCase.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/engine/EngineTestCase.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- EngineTestCase.java 21 Dec 2002 05:17:22 -0000 1.10 +++ EngineTestCase.java 9 Jan 2003 11:25:26 -0000 1.11 @@ -58,12 +58,9 @@ engine.enableLogging( getLogger() ); DefaultContext context = new DefaultContext(); context.put( "urn:assembly:engine.bootstrap", "" + bootstrap ); + context.put( "urn:assembly:logging.manager", m_logManager ); context.makeReadOnly(); engine.contextualize( context ); - DefaultServiceManager manager = new DefaultServiceManager(); - manager.put( "urn:assembly:logging.manager", m_logManager ); - manager.makeReadOnly(); - engine.service( manager ); engine.initialize(); m_engine = engine; } 1.2 +16 -21 avalon-sandbox/assembly/src/xdocs/why.xml Index: why.xml =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/xdocs/why.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- why.xml 1 Dec 2002 06:43:22 -0000 1.1 +++ why.xml 9 Jan 2003 11:25:27 -0000 1.2 @@ -51,32 +51,27 @@ <source> - // - // container-side code hadling component type registration - // - - final String classname = "org.apache.avalon.playground.BasicComponent"; - - DefaultEngine engine = new DefaultEngine(); - engine.enableLogging( m_logger ); - engine.initialize(); - engine.register( classname ); - - // - // container-side code handling service access - // - - final String service = "org.apache.avalon.playground.BasicService"; - DependencyDescriptor dependency = - new DependencyDescriptor( "demo", service, Version.getVersion( "1.1" ) ); - Appliance appliance = m_engine.resolve( dependency ); + // add an implementation component to the engine + + engine.register( "org.apache.avalon.playground.BasicComponent" ); + + // get an appliance handling the versioned service we want + + Appliance appliance = m_engine.resolve( + new DependencyDescriptor( + "demo", + "org.apache.avalon.playground.BasicService", + Version.getVersion( "1.1" ) ) + ); + + // get the fully prepared component Object object = appliance.access( dependency ); </source> <p> -The above code demonstrates the elimination of knowlge about the component deployment strategy. All aspect concerning the component logging, configuration, parameterization, contexulization, dependency composition, initialization, starup, shutdown and disposal are managed by the engine. +The above code demonstrates the elimination of knowlge about the component deployment strategy. All aspect concerning the component logging, configuration, parameterization, contexulization, dependency composition, initialization, startup, shutdown and disposal are managed by the engine. </p> </s1>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>