mcconnell 2002/12/21 01:26:34 Modified: assembly/src/java/org/apache/avalon/assembly/appliance Appliance.java DefaultAppliance.java assembly/src/java/org/apache/avalon/assembly/lifecycle DefaultDeploymentService.java DeploymentService.java assembly/src/java/org/apache/avalon/assembly/lifecycle/context ContextualizationService.java DefaultContextualizationService.java assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal ExtendedDisposalService.java assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization ExtendedInitializationService.java assembly/src/java/org/apache/avalon/assembly/lifestyle AbstractLifestyleHandler.java Added: assembly/src/java/org/apache/avalon/assembly/appliance ContextBuilder.java Log: Context related cleanup. Revision Changes Path 1.14 +15 -1 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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Appliance.java 21 Dec 2002 05:17:22 -0000 1.13 +++ Appliance.java 21 Dec 2002 09:26:33 -0000 1.14 @@ -55,6 +55,7 @@ import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.assembly.lifestyle.LifestyleException; import org.apache.avalon.assembly.lifecycle.AssemblyException; @@ -112,6 +113,12 @@ Type getType(); /** + * Return the component class + * @return the class + */ + Class getComponentClass(); + + /** * Return the profile backing the appliance. * @return the profile that this appliance is managing */ @@ -161,6 +168,13 @@ * @return the Configuration for the appliance. */ Configuration getConfiguration(); + + /** + * Get the component context. + * + * @return the component context + */ + Context getContext(); /** * Return the context directive for the profile. A context directive 1.18 +204 -78 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.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- DefaultAppliance.java 21 Dec 2002 05:17:22 -0000 1.17 +++ DefaultAppliance.java 21 Dec 2002 09:26:33 -0000 1.18 @@ -81,6 +81,7 @@ import org.apache.avalon.meta.info.Type; import org.apache.avalon.meta.info.StageDescriptor; import org.apache.avalon.meta.info.LoggerDescriptor; +import org.apache.avalon.meta.info.ContextDescriptor; import org.apache.avalon.meta.model.Profile; import org.apache.avalon.meta.model.LoggingDirective; import org.apache.avalon.meta.model.ContextDirective; @@ -101,6 +102,8 @@ protected static String PROTOCOL = "native"; + private static final ContextBuilder BUILDER = new ContextBuilder(); + //===================================================================== // state //===================================================================== @@ -108,7 +111,7 @@ /** * The profile. */ - private ApplianceContext m_context; + private ApplianceContext m_applianceContext; /** * The lifestyle service from which the appliance lifestyle handler is established. @@ -121,11 +124,16 @@ private AssemblyService m_assembly; /** - * The appliance context. + * The system context. */ private Context m_system; /** + * The derived component context. + */ + private Context m_context; + + /** * The lifestyle handler. */ private LifestyleHandler m_handler; @@ -181,6 +189,16 @@ */ private String m_name; + /** + * The assembled state of the appliance. + */ + private boolean m_assembled; + + /** + * The appliance target component class. + */ + private Class m_class; + //============================================================== // constructor //============================================================== @@ -216,73 +234,34 @@ } m_assembly = assembly; - m_context = context; + m_applianceContext = context; m_logger = logger; m_engine = engine; m_system = system; + String classname = getType().getInfo().getClassname(); try { - m_domain = (String) m_system.get( "urn:assembly:domain" ); + m_class = engine.loadClass( classname ); } catch( Throwable e ) { - m_domain = "localhost"; + final String error = + "Cannot load class for appliance " + this + + " from classname: " + classname; + throw new ApplianceException( error, e ); } - - m_name = context.getName(); - - m_path = m_context.getPartitionName() + m_name; - - // - // make sure that the deployment context is fully populated - // - + try { - Map map = context.getDeploymentContext(); - - // - // setup the name and the partition - // - - map.put( "urn:avalon:name", m_name ); - map.put( "urn:avalon:partition.name", m_context.getPartitionName() ); - - // - // setup the home and working directory for the component - // - - File base = (File) system.get( "urn:assembly:home" ); - File dir = new File( base, "work" ); - dir.mkdirs(); - File home = new File( dir, m_path ); - File work = new File( home, "temp" ); - home.mkdir(); - work.mkdir(); - work.deleteOnExit(); - map.put( "urn:avalon:home", home ); - map.put( "urn:avalon:work", work ); - - // - // assign the updated map as the deployment context - // - - m_deployment = map; - - } - catch( ContextException e ) - { - final String error = "System context does not contain the entry 'urn:assembly:home'" - + " in appliance: " + this; - throw new IllegalStateException( error ); + m_domain = (String) m_system.get( "urn:assembly:domain" ); } catch( Throwable e ) { - final String error = - "Unexpected exception while preparing deployment context in appliance: " + this; - throw new ApplianceException( error, e ); + m_domain = "localhost"; } + m_name = context.getName(); + m_path = m_applianceContext.getPartitionName() + m_name; // // finally, create the lifestyle handler @@ -318,7 +297,16 @@ */ public Type getType() { - return m_context.getType(); + return m_applianceContext.getType(); + } + + /** + * Return the component class + * @return the class + */ + public Class getComponentClass() + { + return m_class; } /** @@ -348,7 +336,7 @@ */ public String getPartitionName() { - return m_context.getPartitionName(); + return m_applianceContext.getPartitionName(); } /** @@ -360,6 +348,16 @@ } /** + * Get the component context. + * + * @return the component context + */ + public Context getContext() + { + return m_context; + } + + /** * Get the deployment context. The deployment context includes * supplimentary context values provided by the client that can be * used by the context management framework during the creation @@ -386,7 +384,7 @@ */ public ContextDirective getContextDirective() { - return m_context.getContextDirective(); + return m_applianceContext.getContextDirective(); } /** @@ -396,7 +394,7 @@ */ public Parameters getParameters() { - return m_context.getParameters(); + return m_applianceContext.getParameters(); } /** @@ -406,7 +404,7 @@ */ public Configuration getConfiguration() { - return m_context.getConfiguration(); + return m_applianceContext.getConfiguration(); } /** @@ -416,7 +414,7 @@ */ public Profile getProfile() { - return m_context.getProfile(); + return m_applianceContext.getProfile(); } /** @@ -428,7 +426,7 @@ */ public boolean getActivationPolicy() { - return m_context.getActivationPolicy(); + return m_applianceContext.getActivationPolicy(); } /** @@ -460,7 +458,140 @@ */ public LoggingDirective getLoggingDirective() { - return m_context.getLoggingDirective(); + return m_applianceContext.getLoggingDirective(); + } + + /** + * Assemble the appliance. + * @exception AssemblyException if an error occurs during appliance assembly + */ + public void assemble() throws AssemblyException + { + if( m_assembled ) + { + return; + } + + m_assembly.assemble( this ); + if( isContextEnabled() ) + { + Map map = buildContextMap(); + m_context = buildContextObject( map ); + } + + setEnabled( true ); + m_assembled = true; + } + + private boolean isContextEnabled() + { + if( getContextProvider() != null ) + { + return true; + } + else + { + return Contextualizable.class.isAssignableFrom( m_class ); + } + } + + /** + * Build the context map. + * @exception AssemblyException if an error occurs during context creation + */ + private Map buildContextMap() throws AssemblyException + { + ContextDescriptor descriptor = getType().getContext(); + + // + // make sure that the deployment context is fully populated + // + + try + { + Map map = m_applianceContext.getDeploymentContext(); + + // + // setup the name and the partition + // + + map.put( "urn:avalon:name", m_name ); + map.put( "urn:avalon:partition.name", m_applianceContext.getPartitionName() ); + + // + // setup the home and working directory for the component + // + + File base = (File) m_system.get( "urn:assembly:home" ); + File dir = new File( base, "work" ); + dir.mkdirs(); + File home = new File( dir, m_path ); + File work = new File( home, "temp" ); + home.mkdir(); + work.mkdir(); + work.deleteOnExit(); + map.put( "urn:avalon:home", home ); + map.put( "urn:avalon:work", work ); + + // + // assign the updated map as the deployment context + // + + m_deployment = map; + + } + catch( ContextException e ) + { + final String error = "System context does not contain the entry 'urn:assembly:home'" + + " in appliance: " + this; + throw new IllegalStateException( error ); + } + catch( Throwable e ) + { + final String error = + "Unexpected exception while preparing deployment context in appliance: " + this; + throw new AssemblyException( error, e ); + } + + try + { + return BUILDER.buildContextMap( m_engine, this, m_deployment, m_system ); + } + catch( Throwable e ) + { + final String error = + "Unable to create context map in appliance: " + this; + throw new AssemblyException( error, e ); + } + } + + + /** + * Assemble the appliance. + * @exception AssemblyException if an error occurs during appliance assembly + */ + private Context buildContextObject( Map map ) throws AssemblyException + { + ContextDirective directive = getContextDirective(); + try + { + return BUILDER.createContextInstance( m_engine, directive, map ); + } + catch( Throwable e ) + { + final String error = + "Unable to create context carrier in appliance: " + this; + throw new AssemblyException( error, e ); + } + } + + + /** + * Disassemble the appliance. + */ + public void disassemble() + { + m_assembly.disassemble( this ); } /** @@ -556,6 +687,10 @@ */ public Object access( DependencyDescriptor dependency ) throws LifestyleException { + if( !m_assembled ) + { + throw new IllegalStateException( "assembly" ); + } return m_handler.access( dependency ); } @@ -564,6 +699,10 @@ */ public Object access() throws LifestyleException { + if( !m_assembled ) + { + throw new IllegalStateException( "assembly" ); + } return m_handler.access(); } @@ -573,6 +712,10 @@ */ public Object access( StageDescriptor stage ) throws LifestyleException { + if( !m_assembled ) + { + throw new IllegalStateException( "assembly" ); + } return m_handler.access( stage ); } @@ -593,23 +736,6 @@ "Lifestyle handler raised a release error in appliance: " + this; throw new ApplianceRuntimeException( error, e ); } - } - - /** - * Assemble the appliance. - * @exception AssemblyException if an error occurs during appliance assembly - */ - public void assemble() throws AssemblyException - { - m_assembly.assemble( this ); - } - - /** - * Disassemble the appliance. - */ - public void disassemble() - { - m_assembly.disassemble( this ); } public String toString() 1.1 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/ContextBuilder.java Index: ContextBuilder.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.avalon.assembly.appliance; import java.util.Map; import java.lang.reflect.Constructor; import java.util.HashMap; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.context.Contextualizable; 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.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.DefaultServiceManager; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.assembly.appliance.Appliance; import org.apache.avalon.assembly.engine.RepositoryManager; import org.apache.avalon.assembly.engine.EngineClassLoader; import org.apache.avalon.assembly.service.UnknownServiceException; import org.apache.avalon.meta.model.Entry; import org.apache.avalon.meta.model.Import; import org.apache.avalon.meta.model.Profile; import org.apache.avalon.meta.model.ContextDirective; import org.apache.avalon.meta.info.ContextDescriptor; import org.apache.avalon.meta.info.EntryDescriptor; import org.apache.avalon.meta.info.ExtensionDescriptor; import org.apache.avalon.meta.info.ReferenceDescriptor; import org.apache.avalon.meta.info.Service; /** * The context service provides support for the contextualization of a * supplied component instance relative to the criteria establihsed under a * supplied appliance. * * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision: 1.1 $ $Date: 2002/12/21 09:26:33 $ */ class ContextBuilder { /** * Internal utility to construct a context map using a descriptor, directive and source * context instances. * * @param engine the service management engine * @param appliance the appliance containing the context dependency declarations * @param map supplimentary context values supplied by the client * @param system th system context * @return a context map containing only those context entries required under the * supplied descriptor * @exception Exception if a required context value cannot be resolved or an error * occurs during context value creation */ static Map buildContextMap( EngineClassLoader engine, Appliance appliance, Map map, Context system ) throws ContextException { // // get the type descriptor for the context and the profile // directive // ContextDescriptor descriptor = appliance.getType().getContext(); ContextDirective directive = appliance.getContextDirective(); RepositoryManager repository = engine.getRepository(); // // create a temporary context object to hold both the system context // and any context values supplied by the client // Context source = new DefaultContext( map, system ); // // construct a new map based on the target components requirements // return buildContext( engine, repository, descriptor, directive, source ); } /** * Internal utility to construct a context map using a descriptor, directive and source * context instances. * * @param classloader the classloader * @param descriptor the target component context descriptor * @param directive the target component context directives * @param context the context containing source values * @return a context map containing only those context entries required under the * supplied descriptor * @exception ContextException if a required context value cannot be resolved */ private static Map buildContext( ClassLoader classloader, RepositoryManager repository, ContextDescriptor descriptor, ContextDirective directive, Context context ) throws ContextException { // // Create a new empty map that we will populate based on the descriptor // criteria, with assistance from the supplied directive, using the supplied // context as the source // Map map = new HashMap(); // // get the entries declared by the context descriptor plus and // entries declared within a service definition if one exists // EntryDescriptor[] entries = getMergedEntries( repository, descriptor ); // // commence population of the map // for( int i = 0; i < entries.length; i++ ) { EntryDescriptor entry = entries[ i ]; String key = entry.getKey(); // // if the entry is already in the supplied context then use it // // ### converge next two operation into a if then else on // system context entries with the next line as the final else // case Object object = getContextValue( context, key ); //object = resolveStandardKey( appliance, context, key ); // // If the context value is unresolved, try to handle resolution // using an import directive supplied under the directive // if( object == null ) { // // check if the profile declares an import directive // for the context // if( directive != null ) { Import imp = directive.getImport( key ); if( imp != null ) { String name = imp.getImportName(); object = getContextValue( context, name ); if( object == null ) { if( entry.isRequired() ) { final String error = "Import directive for key: " + key + " via name: " + name + " cannot be resolved."; throw new ContextException( error ); } } } // // if the context value is unresolved, try to construct a context // value using an entry constructor directive // if( object == null ) { // // check if the directive declares a context value constructor // Entry ent = directive.getEntry( key ); if( ent != null ) { try { object = ent.getValue( classloader, map ); } catch( Throwable e ) { final String error = "Rresolution error for context entry directive: " + ent; throw new ContextException( error, e ); } if( object == null ) { final String error = "Unable to build a context value for the entry: '" + key + "' type: " + entry.getType(); if( entry.isRequired() ) { throw new ContextException( error ); } } } } } } // // finally, if the object is still null, and its not optional, then // throw an exception, otherwise, add the object to the context // if( object != null ) { try { boolean ok = objectImplementsType( classloader, object, entry.getType() ); if( ok ) { map.put( key, object ); } else { final String error = "Object resolved for the key '" + key + "' of class '" + object.getClass().getName() + "' does not implement the type '" + entry.getType(); throw new ContextException( error ); } } catch( ClassNotFoundException cnfe ) { final String error = "Context criteria for the key '" + key + "' specifies an unknown type '" + entry.getType() + "'."; throw new ContextException( error ); } } else { if( entry.isRequired() ) { final String error = "Unable to resolve a context value for the entry: '" + key + "' type: " + entry.getType(); throw new ContextException( error ); } } } return map; } private static EntryDescriptor[] getMergedEntries( RepositoryManager repository, ContextDescriptor descriptor ) throws IllegalArgumentException { try { Service service = repository.getServiceManager().getService( descriptor.getReference() ); EntryDescriptor[] entries = service.getEntries(); EntryDescriptor[] result = descriptor.merge( service.getEntries() ); return result; } catch( UnknownServiceException e ) { return descriptor.getEntries(); } } /** * Internal utility to get a context value or null if the context key * is unknown. * @param context the context object * @param key the context key to lookup * @return the context value derived from the key or null if the key is unknown */ protected static Object getContextValue( Context context, String key ) { if( context == null ) { return null; } try { return context.get( key ); } catch( ContextException e ) { return null; } } /** * Check whether the specified value is compatible with specified type. * * @param value the value * @param type the desired type * @return true if value is compatible with type, false otherwise */ private static boolean objectImplementsType( ClassLoader classloader, final Object value, final String type ) throws ClassNotFoundException { if( type == null ) { throw new NullPointerException( "type" ); } if( value == null ) { throw new NullPointerException( "value" ); } final Class clazz = value.getClass(); final Class typeClass = classloader.loadClass( type ); return typeClass.isAssignableFrom( clazz ); } /** * Internal utility to construct a custom context instance. The object returned * is based on the declarations in the supplied directive and defaults to the * [EMAIL PROTECTED] DefaultContext} class. * * @param classloader the classloader to use * @param directive the context creation directive * @param map a map to apply to the created instance under its constructor * @return a context object created in accordance with the supplied directive * @exception ContextException if a required context value cannot be resolved or an error * occurs during context value creation */ static Context createContextInstance( ClassLoader classloader, ContextDirective directive, Map map ) throws ContextException { // // check for meta-data about how to create a specialized context type // and if its present then create it using the standard constructor // pattern otherwise use the DefaultContext implementation // if( directive != null ) { final String classname = directive.getClassname(); Class clazz; try { clazz = classloader.loadClass( classname ); } catch( ClassNotFoundException cnfe ) { throw new ContextException( "Could not find context class " + classname, cnfe ); } if( !Context.class.isAssignableFrom( clazz ) ) { final String error = "Context directive references a type that is not derived from " + Context.class.getName(); throw new ContextException( error ); } try { Constructor constructor = clazz.getConstructor( new Class[]{Map.class, Context.class} ); return (Context) constructor.newInstance( new Object[]{map, null} ); } catch( NoSuchMethodException e ) { final String error = "Custom context class: [" + classname + "] does not implement the required constructor pattern <init>( Map, Context )."; throw new ContextException( error, e ); } catch( Throwable e ) { throw new ContextException( "Unexpected exception while creating context from " + classname, e ); } } else { return new DefaultContext( map ); } } } 1.11 +3 -16 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DefaultDeploymentService.java Index: DefaultDeploymentService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DefaultDeploymentService.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- DefaultDeploymentService.java 21 Dec 2002 05:17:22 -0000 1.10 +++ DefaultDeploymentService.java 21 Dec 2002 09:26:34 -0000 1.11 @@ -297,7 +297,7 @@ * @param context the containment context * @return the deployed component */ - public Object deploy( Appliance appliance, ClassLoader classloader, Context context ) + public Object deploy( Appliance appliance, ClassLoader classloader ) throws DeploymentException { if( !m_initialized ) @@ -313,10 +313,6 @@ { throw new NullPointerException( "classloader" ); } - if( context == null ) - { - throw new NullPointerException( "context" ); - } // // make sure we are deploying a fully assembled appliance @@ -359,7 +355,7 @@ m_logging.enableLogging( appliance, instance ); m_configuration.configure( appliance, instance ); m_parameters.parameterize( appliance, instance ); - m_contextualization.contextualize( appliance, instance, context ); + m_contextualization.contextualize( appliance, instance ); m_composition.service( appliance, instance ); m_initialization.initialize( appliance, instance ); m_startup.start( appliance, instance ); @@ -473,9 +469,6 @@ { DefaultContextualizationService service = new DefaultContextualizationService(); service.enableLogging( getLogger().getChildLogger( "context" ) ); - service.contextualize( m_context ); - service.service( m_manager ); - service.initialize(); return service; } catch( Throwable e ) @@ -510,9 +503,6 @@ { ExtendedInitializationService service = new ExtendedInitializationService(); service.enableLogging( getLogger().getChildLogger( "init" ) ); - service.contextualize( m_context ); - service.service( m_manager ); - service.initialize(); return service; } else @@ -554,9 +544,6 @@ { ExtendedDisposalService service = new ExtendedDisposalService(); service.enableLogging( getLogger().getChildLogger( "disposal" ) ); - service.contextualize( m_context ); - service.service( m_manager ); - service.initialize(); return service; } else 1.4 +2 -3 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DeploymentService.java Index: DeploymentService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/DeploymentService.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DeploymentService.java 17 Dec 2002 11:35:50 -0000 1.3 +++ DeploymentService.java 21 Dec 2002 09:26:34 -0000 1.4 @@ -77,10 +77,9 @@ * @param classloader the classloader to use * @param appliance the appliance to deploy * @param logger the logging channel to assign to the component - * @param context the containment context * @return the deployed component */ - Object deploy( Appliance appliance, ClassLoader classloader, Context context ) + Object deploy( Appliance appliance, ClassLoader classloader ) throws DeploymentException; /** 1.2 +2 -2 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ContextualizationService.java Index: ContextualizationService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/ContextualizationService.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ContextualizationService.java 29 Nov 2002 13:04:55 -0000 1.1 +++ ContextualizationService.java 21 Dec 2002 09:26:34 -0000 1.2 @@ -70,6 +70,6 @@ * @param object the object to contextualize */ void contextualize( - Appliance appliance, Object object, Context context ) + Appliance appliance, Object object ) throws ContextException; } 1.9 +11 -88 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java Index: DefaultContextualizationService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/context/DefaultContextualizationService.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DefaultContextualizationService.java 20 Dec 2002 11:54:28 -0000 1.8 +++ DefaultContextualizationService.java 21 Dec 2002 09:26:34 -0000 1.9 @@ -60,7 +60,6 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.assembly.appliance.Appliance; -import org.apache.avalon.assembly.lifecycle.ContextHandler; import org.apache.avalon.meta.model.Entry; import org.apache.avalon.meta.model.Import; import org.apache.avalon.meta.model.Profile; @@ -76,44 +75,19 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public class DefaultContextualizationService extends ContextHandler +public class DefaultContextualizationService extends AbstractLogEnabled implements ContextualizationService { //============================================================== - // state - //============================================================== - - private Context m_context; - - //============================================================== - // Contextualizable - //============================================================== - - /** - * <p>Application of a runtime context to this appliance. - * The supplied context contains standard and container specific context - * entries and may be used by the context service in establish the - * context to apply to components.</p> - * @param context the containerment context - */ - public void contextualize( Context context ) throws ContextException - { - super.contextualize( context ); - m_context = context; - } - - //============================================================== // ContextService //============================================================== /** - * Contextualization of a supplied object in accordance with the profile - * directives assiacted with the supplied appliance. + * Contextualization of a supplied object. * @param appliance the appliace - * @param object the object to configure + * @param object the object to contextualize */ - public void contextualize( - Appliance appliance, Object object, Context context ) throws ContextException + public void contextualize( Appliance appliance, Object object ) throws ContextException { if( appliance == null ) { @@ -124,44 +98,18 @@ throw new NullPointerException( "object" ); } - Appliance provider = appliance.getContextProvider(); + Context context = appliance.getContext(); - if(( provider != null ) || (object instanceof Contextualizable )) + if( context != null ) { - // - // the component is requesting contextualization in one form or another - // - - if( getLogger().isDebugEnabled() ) - { - final String message = appliance.toString(); - getLogger().debug( message ); - } - - Context source; - if( appliance.getDeploymentContext() != null ) - { - source = new DefaultContext( appliance.getDeploymentContext(), context ); - } - else - { - source = context; - } - - // - // populate the "standard" context with the actual context entries that - // the component is requesting - // - - Context standard = - createStandardContext( appliance, source ); + Appliance provider = appliance.getContextProvider(); // // resolve the contextualization strategy - either its a custom // interface and handler, or its classic Avalon - try custom first // - + if( provider != null ) { if( getLogger().isDebugEnabled() ) @@ -175,7 +123,7 @@ try { Contextualization handler = (Contextualization) provider.access(); - handler.contextualize( object, standard ); + handler.contextualize( object, context ); return; } catch( Throwable e ) @@ -192,7 +140,7 @@ try { - ((Contextualizable)object).contextualize( standard ); + ((Contextualizable)object).contextualize( context ); } catch( ContextException e ) { @@ -213,31 +161,6 @@ "Unexpected exception during contextualization of target: " + appliance; throw new ContextException( error, e ); } - } - } - - /** - * Create a new Context for component. - * - * @param profile the profile - * @param context a supplimentary context usable during import resolution - * @return a new Context for service - * @throws DeploymentException if an error occurs in standard - * context creation - */ - public Context createStandardContext( Appliance appliance, Context context ) - throws ContextException - { - try - { - return buildContext( appliance, context ); - } - catch( Throwable e ) - { - final String error = - "Unexpected error while preparing standard context for the appliance: " - + appliance; - throw new ContextException( error, e ); } } } 1.9 +7 -51 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/ExtendedDisposalService.java Index: ExtendedDisposalService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/disposal/ExtendedDisposalService.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ExtendedDisposalService.java 21 Dec 2002 03:28:37 -0000 1.8 +++ ExtendedDisposalService.java 21 Dec 2002 09:26:34 -0000 1.9 @@ -53,16 +53,11 @@ import java.util.Map; import java.util.Hashtable; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.activity.Disposable; -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.assembly.appliance.Appliance; -import org.apache.avalon.assembly.lifecycle.ContextHandler; import org.apache.avalon.assembly.lifecycle.DeploymentException; -import org.apache.avalon.assembly.engine.Engine; +import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.context.Context; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.meta.info.StageDescriptor; import org.apache.avalon.meta.info.Type; import org.apache.avalon.meta.info.ExtensionDescriptor; @@ -78,26 +73,9 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public class ExtendedDisposalService extends ContextHandler implements DisposalService -{ - Context m_context; - //============================================================== - // Contextualizable - //============================================================== - - /** - * <p>Application of a runtime context to this appliance. - * The supplied context contains standard and container specific context - * entries and may be used by the context service in establish the - * context to apply to components.</p> - * @param context the containerment context - */ - public void contextualize( Context context ) throws ContextException - { - super.contextualize( context ); - m_context = context; - } +public class ExtendedDisposalService extends AbstractLogEnabled implements DisposalService +{ /** * Dispose of the supplied object. @@ -106,11 +84,6 @@ */ public void dispose( Appliance appliance, Object object ) { - if( m_context == null ) - { - throw new IllegalStateException("context"); - } - if( appliance == null ) { throw new NullPointerException("appliance"); @@ -178,23 +151,6 @@ throw new DeploymentException( error ); } - Context context; - try - { - Type type = provider.getType(); - final ExtensionDescriptor descriptor = type.getExtension( stage ); - context = createContext( provider, descriptor, m_context ); - } - catch( Throwable e ) - { - final String error = - "Extension handler context establishment error on appliance: '" - + appliance - + "' under stage: '" + stage - + "' for provider: '" + provider; - throw new DeploymentException( error, e ); - } - Creator handler = null; try { @@ -212,7 +168,7 @@ try { - handler.destroy( object, context ); + handler.destroy( object, appliance.getContext() ); provider.release( handler ); } catch( Throwable e ) 1.10 +3 -45 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/ExtendedInitializationService.java Index: ExtendedInitializationService.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifecycle/initialization/ExtendedInitializationService.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ExtendedInitializationService.java 21 Dec 2002 03:28:37 -0000 1.9 +++ ExtendedInitializationService.java 21 Dec 2002 09:26:34 -0000 1.10 @@ -60,7 +60,6 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.assembly.appliance.Appliance; -import org.apache.avalon.assembly.lifecycle.ContextHandler; import org.apache.avalon.assembly.lifecycle.DeploymentException; import org.apache.avalon.assembly.engine.Engine; import org.apache.avalon.meta.info.StageDescriptor; @@ -78,27 +77,8 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public class ExtendedInitializationService extends ContextHandler implements InitializationService +public class ExtendedInitializationService extends AbstractLogEnabled implements InitializationService { - Context m_context; - - //============================================================== - // Contextualizable - //============================================================== - - /** - * <p>Application of a runtime context to this appliance. - * The supplied context contains standard and container specific context - * entries and may be used by the context service in establish the - * context to apply to components.</p> - * @param context the containerment context - */ - public void contextualize( Context context ) throws ContextException - { - super.contextualize( context ); - m_context = context; - } - /** * Initialize a supplied object in accordance with the parameters * associated with the supplied appliance. @@ -108,11 +88,6 @@ public void initialize( Appliance appliance, Object object ) throws Exception { - if( m_context == null ) - { - throw new IllegalStateException("context"); - } - if( appliance == null ) { throw new NullPointerException("appliance"); @@ -158,23 +133,6 @@ throw new DeploymentException( error ); } - Context context; - try - { - Type type = provider.getType(); - final ExtensionDescriptor descriptor = type.getExtension( stage ); - context = createContext( provider, descriptor, m_context ); - } - catch( Throwable e ) - { - final String error = - "Extension handler context establishment error on appliance: '" - + appliance - + "' under stage: '" + stage - + "' for provider: '" + provider; - throw new DeploymentException( error, e ); - } - Creator handler = null; try { @@ -192,7 +150,7 @@ try { - handler.create( object, context ); + handler.create( object, appliance.getContext() ); provider.release( handler ); } catch( Throwable e ) 1.14 +4 -92 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java Index: AbstractLifestyleHandler.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/lifestyle/AbstractLifestyleHandler.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- AbstractLifestyleHandler.java 21 Dec 2002 03:28:38 -0000 1.13 +++ AbstractLifestyleHandler.java 21 Dec 2002 09:26:34 -0000 1.14 @@ -80,7 +80,7 @@ * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public abstract class AbstractLifestyleHandler extends ContextHandler implements Serviceable, Initializable, Disposable, LifestyleHandler +public abstract class AbstractLifestyleHandler extends AbstractLogEnabled implements Serviceable, Initializable, Disposable, LifestyleHandler { //============================================================== // state @@ -137,7 +137,6 @@ */ public void contextualize( Context context ) throws ContextException { - super.contextualize( context ); m_classloader = (ClassLoader) context.get( "urn:avalon:classloader" ); m_appliance = (Appliance) context.get( "urn:assembly:appliance.target" ); try @@ -171,7 +170,6 @@ */ public void service( ServiceManager manager ) throws ServiceException { - super.service( manager ); m_deployment = (DeploymentService) manager.lookup( "urn:assembly:lifecycle.deployment" ); } @@ -188,7 +186,6 @@ */ public void initialize() throws Exception { - super.initialize(); if( getLogger() == null ) { throw new LifestyleException("logger"); @@ -276,7 +273,7 @@ { try { - return m_deployment.deploy( m_appliance, m_classloader, m_context ); + return m_deployment.deploy( m_appliance, m_classloader ); } catch( Throwable e ) { @@ -357,7 +354,7 @@ Accessor extension = (Accessor) provider.access( stage ); try { - Context context = getStageContext( stage ); + Context context = getAppliance().getContext(); if( access ) { extension.access( object, context ); @@ -379,33 +376,6 @@ } } - private Context getStageContext( StageDescriptor stage ) - { - if( m_map == null ) - { - try - { - m_map = createExtensionContextMap( m_appliance, m_context ); - } - catch( Throwable e ) - { - final String error = - "Internal error while attempting to construct the extension context map for appliance: " - + m_appliance; - throw new LifestyleRuntimeException( error, e ); - } - } - Context context = (Context) m_map.get( stage ); - if( context == null ) - { - final String error = - "Null context returned in appliance: " + m_appliance - + " for the stage: " + stage; - throw new NullPointerException( error ); - } - return context; - } - private Class getImplementationClass( Appliance appliance ) { try @@ -420,64 +390,6 @@ + m_appliance; throw new LifestyleRuntimeException( error, e ); } - } - - /** - * Handles creation of a map of context entries keyed by extension stage. Context - * entries are built using the supplied deployment context argument together - * with profile directives relative to type constraints. - * - * @param profile the profile - * @param context the deployment context - * @return the map of context entries keyed by stage - * @exception LifestyleException if an error occurs while preparing the map - */ - private Map createExtensionContextMap( Appliance appliance, Context context ) - throws LifestyleException - { - if( appliance == null ) - { - throw new NullPointerException( "appliance" ); - } - if( context == null ) - { - throw new NullPointerException( "context" ); - } - - // - // build the set of extension context instances - // - - Profile profile = appliance.getProfile(); - Hashtable table = new Hashtable(); - StageDescriptor[] stages = profile.getType().getStages(); - for( int i = 0; i < stages.length; i++ ) - { - StageDescriptor stage = stages[ i ]; - Appliance provider = appliance.getExtensionProvider( stage ); - if( provider == null ) - { - throw new NullPointerException( "provider" ); - } - - Type type = provider.getType(); - final ExtensionDescriptor ext = type.getExtension( stage ); - try - { - Context extensionContext = createContext( provider, ext, context ); - table.put( stage, extensionContext ); - } - catch( Throwable e ) - { - final String error = - "Unexpected error while creating context for extension: " - + provider - + " in appliance " + appliance - + " for stage: " + stage; - throw new LifestyleException( error, e ); - } - } - return table; } /**
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>