Submitted By: "Adam Murdoch" <adammurdoch_ml@yahoo.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270847 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,9 +8,7 @@ | |||||
| package org.apache.myrmidon.api; | package org.apache.myrmidon.api; | ||||
| import java.io.File; | import java.io.File; | ||||
| import org.apache.avalon.framework.context.Context; | |||||
| import org.apache.avalon.framework.context.ContextException; | import org.apache.avalon.framework.context.ContextException; | ||||
| import org.apache.avalon.framework.context.Contextualizable; | |||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
| /** | /** | ||||
| @@ -31,6 +29,7 @@ public abstract class AbstractTask | |||||
| * @param context the context | * @param context the context | ||||
| */ | */ | ||||
| public void contextualize( final TaskContext context ) | public void contextualize( final TaskContext context ) | ||||
| throws TaskException | |||||
| { | { | ||||
| m_context = context; | m_context = context; | ||||
| } | } | ||||
| @@ -104,6 +103,12 @@ public abstract class AbstractTask | |||||
| getContext().setProperty( name, value, scope ); | getContext().setProperty( name, value, scope ); | ||||
| } | } | ||||
| protected final Object getService( final Class serviceClass ) | |||||
| throws TaskException | |||||
| { | |||||
| return getContext().getService( serviceClass ); | |||||
| } | |||||
| protected final TaskContext createSubContext( final String name ) | protected final TaskContext createSubContext( final String name ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| @@ -29,7 +29,8 @@ public interface Task | |||||
| * The Task will use the TaskContext to receive information | * The Task will use the TaskContext to receive information | ||||
| * about it's environment. | * about it's environment. | ||||
| */ | */ | ||||
| void contextualize( TaskContext context ); | |||||
| void contextualize( TaskContext context ) | |||||
| throws TaskException; | |||||
| /** | /** | ||||
| * Execute task. | * Execute task. | ||||
| @@ -81,9 +81,6 @@ public class AspectAwareExecutor | |||||
| debug( "contextualizing.notice" ); | debug( "contextualizing.notice" ); | ||||
| doContextualize( task, taskModel, frame.getContext() ); | doContextualize( task, taskModel, frame.getContext() ); | ||||
| debug( "composing.notice" ); | |||||
| doCompose( task, taskModel, frame.getComponentManager() ); | |||||
| debug( "configuring.notice" ); | debug( "configuring.notice" ); | ||||
| getAspectManager().preConfigure( taskModel ); | getAspectManager().preConfigure( taskModel ); | ||||
| doConfigure( task, taskModel, frame.getContext() ); | doConfigure( task, taskModel, frame.getContext() ); | ||||
| @@ -12,9 +12,11 @@ import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.context.Context; | import org.apache.avalon.framework.context.Context; | ||||
| import org.apache.avalon.framework.context.Contextualizable; | import org.apache.avalon.framework.context.Contextualizable; | ||||
| import org.apache.avalon.framework.context.ContextException; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | import org.apache.avalon.framework.logger.LogEnabled; | ||||
| import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.interfaces.executor.ExecutionFrame; | import org.apache.myrmidon.interfaces.executor.ExecutionFrame; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| @@ -24,36 +26,28 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class DefaultExecutionFrame | public class DefaultExecutionFrame | ||||
| implements ExecutionFrame, LogEnabled, Contextualizable, Composable | |||||
| implements ExecutionFrame, LogEnabled, Contextualizable | |||||
| { | { | ||||
| private TypeManager m_typeManager; | |||||
| private Logger m_logger; | private Logger m_logger; | ||||
| private TaskContext m_context; | private TaskContext m_context; | ||||
| private ComponentManager m_componentManager; | |||||
| private TypeManager m_typeManager; | |||||
| public void enableLogging( final Logger logger ) | public void enableLogging( final Logger logger ) | ||||
| { | { | ||||
| m_logger = logger; | m_logger = logger; | ||||
| } | } | ||||
| public void contextualize( final Context context ) | |||||
| public void contextualize( final Context context ) throws ContextException | |||||
| { | { | ||||
| m_context = (TaskContext)context; | m_context = (TaskContext)context; | ||||
| } | |||||
| /** | |||||
| * Retrieve relevent services needed to deploy. | |||||
| * | |||||
| * @param componentManager the ComponentManager | |||||
| * @exception ComponentException if an error occurs | |||||
| */ | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| { | |||||
| m_componentManager = componentManager; | |||||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
| try | |||||
| { | |||||
| m_typeManager = (TypeManager)m_context.getService( TypeManager.class ); | |||||
| } | |||||
| catch( TaskException te ) | |||||
| { | |||||
| throw new ContextException(te.getMessage(), te); | |||||
| } | |||||
| } | } | ||||
| public TypeManager getTypeManager() | public TypeManager getTypeManager() | ||||
| @@ -70,9 +64,4 @@ public class DefaultExecutionFrame | |||||
| { | { | ||||
| return m_context; | return m_context; | ||||
| } | } | ||||
| public ComponentManager getComponentManager() | |||||
| { | |||||
| return m_componentManager; | |||||
| } | |||||
| } | } | ||||
| @@ -61,9 +61,6 @@ public class DefaultExecutor | |||||
| debug( "contextualizing.notice" ); | debug( "contextualizing.notice" ); | ||||
| doContextualize( task, taskModel, frame.getContext() ); | doContextualize( task, taskModel, frame.getContext() ); | ||||
| debug( "composing.notice" ); | |||||
| doCompose( task, taskModel, frame.getComponentManager() ); | |||||
| debug( "configuring.notice" ); | debug( "configuring.notice" ); | ||||
| doConfigure( task, taskModel, frame.getContext() ); | doConfigure( task, taskModel, frame.getContext() ); | ||||
| @@ -115,29 +112,6 @@ public class DefaultExecutor | |||||
| } | } | ||||
| } | } | ||||
| protected final void doCompose( final Task task, | |||||
| final Configuration taskModel, | |||||
| final ComponentManager componentManager ) | |||||
| throws TaskException | |||||
| { | |||||
| if( task instanceof Composable ) | |||||
| { | |||||
| try | |||||
| { | |||||
| ( (Composable)task ).compose( componentManager ); | |||||
| } | |||||
| catch( final Throwable throwable ) | |||||
| { | |||||
| final String message = | |||||
| REZ.getString( "compose.error", | |||||
| taskModel.getName(), | |||||
| taskModel.getLocation(), | |||||
| throwable.getMessage() ); | |||||
| throw new TaskException( message, throwable ); | |||||
| } | |||||
| } | |||||
| } | |||||
| protected final void doContextualize( final Task task, | protected final void doContextualize( final Task task, | ||||
| final Configuration taskModel, | final Configuration taskModel, | ||||
| final TaskContext context ) | final TaskContext context ) | ||||
| @@ -1,7 +1,6 @@ | |||||
| creating.notice=Creating. | creating.notice=Creating. | ||||
| logger.notice=Setting Logger. | logger.notice=Setting Logger. | ||||
| contextualizing.notice=Contextualizing. | contextualizing.notice=Contextualizing. | ||||
| composing.notice=Composing. | |||||
| configuring.notice=Configuring. | configuring.notice=Configuring. | ||||
| initializing.notice=Initializing. | initializing.notice=Initializing. | ||||
| executing.notice=Executing. | executing.notice=Executing. | ||||
| @@ -9,7 +8,6 @@ disposing.notice=Disposing. | |||||
| no-create.error=Unable to create task {0}. | no-create.error=Unable to create task {0}. | ||||
| config.error=Error configuring task {0} at {1} (Reason: {2}). | config.error=Error configuring task {0} at {1} (Reason: {2}). | ||||
| compose.error=Error composing task {0} at {1} (Reason: {2}). | |||||
| contextualize.error=Error contextualizing task {0} at {1} (Reason: {2}). | contextualize.error=Error contextualizing task {0} at {1} (Reason: {2}). | ||||
| dispose.error=Error disposing task {0} at {1} (Reason: {2}). | dispose.error=Error disposing task {0} at {1} (Reason: {2}). | ||||
| init.error=Error initializing task {0} at {1} (Reason: {2}). | init.error=Error initializing task {0} at {1} (Reason: {2}). | ||||
| @@ -8,12 +8,14 @@ | |||||
| package org.apache.myrmidon.components.workspace; | package org.apache.myrmidon.components.workspace; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.Map; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
| import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.avalon.excalibur.property.PropertyException; | import org.apache.avalon.excalibur.property.PropertyException; | ||||
| import org.apache.avalon.excalibur.property.PropertyUtil; | import org.apache.avalon.excalibur.property.PropertyUtil; | ||||
| import org.apache.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.context.ContextException; | import org.apache.avalon.framework.context.ContextException; | ||||
| import org.apache.avalon.framework.context.DefaultContext; | import org.apache.avalon.framework.context.DefaultContext; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| @@ -31,32 +33,44 @@ public class DefaultTaskContext | |||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( DefaultTaskContext.class ); | ResourceManager.getPackageResources( DefaultTaskContext.class ); | ||||
| private ComponentManager m_componentManager; | |||||
| /** | /** | ||||
| * Constructor for Context with no parent contexts. | * Constructor for Context with no parent contexts. | ||||
| */ | */ | ||||
| public DefaultTaskContext( final Map contextData ) | |||||
| public DefaultTaskContext() | |||||
| { | { | ||||
| super( contextData ); | |||||
| this( (TaskContext)null ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Constructor for Context with no parent contexts. | |||||
| * Constructor that specified parent context. | |||||
| */ | */ | ||||
| public DefaultTaskContext() | |||||
| public DefaultTaskContext( final TaskContext parent ) | |||||
| { | { | ||||
| this( (TaskContext)null ); | |||||
| this( parent, null ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Constructor. | |||||
| * Constructor that specifies the ComponentManager for context. | |||||
| */ | */ | ||||
| public DefaultTaskContext( final TaskContext parent ) | |||||
| public DefaultTaskContext( final ComponentManager componentManager ) | |||||
| { | |||||
| this( null, componentManager ); | |||||
| } | |||||
| /** | |||||
| * Constructor that takes both parent context and a service directory. | |||||
| */ | |||||
| public DefaultTaskContext( final TaskContext parent, | |||||
| final ComponentManager componentManager ) | |||||
| { | { | ||||
| super( parent ); | super( parent ); | ||||
| m_componentManager = componentManager; | |||||
| } | } | ||||
| /** | /** | ||||
| * Retrieve Name of tasklet. | |||||
| * Retrieve Name of task. | |||||
| * | * | ||||
| * @return the name | * @return the name | ||||
| */ | */ | ||||
| @@ -104,7 +118,42 @@ public class DefaultTaskContext | |||||
| public Object getService( final Class serviceClass ) | public Object getService( final Class serviceClass ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| throw new TaskException( "No services available atm" ); | |||||
| // Try this context first | |||||
| final String name = serviceClass.getName(); | |||||
| if( m_componentManager.hasComponent( name ) ) | |||||
| { | |||||
| try | |||||
| { | |||||
| final Component service = m_componentManager.lookup( name ); | |||||
| if( !serviceClass.isInstance( service ) ) | |||||
| { | |||||
| final String message = | |||||
| REZ.getString( "bad-service-class.error", | |||||
| name, | |||||
| service.getClass().getName(), | |||||
| serviceClass.getName() ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| return service; | |||||
| } | |||||
| catch( final ComponentException ce ) | |||||
| { | |||||
| final String message = REZ.getString( "bad-find-service.error", name ); | |||||
| throw new TaskException( message, ce ); | |||||
| } | |||||
| } | |||||
| // Try parent | |||||
| final TaskContext parent = (TaskContext)getParent(); | |||||
| if( null != parent ) | |||||
| { | |||||
| return parent.getService( serviceClass ); | |||||
| } | |||||
| // Not found | |||||
| final String message = REZ.getString( "bad-find-service.error", name ); | |||||
| throw new TaskException( message ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -194,9 +243,11 @@ public class DefaultTaskContext | |||||
| { | { | ||||
| checkPropertyValid( name, value ); | checkPropertyValid( name, value ); | ||||
| if( CURRENT == scope ) { | |||||
| if( CURRENT == scope ) | |||||
| { | |||||
| put( name, value ); | put( name, value ); | ||||
| } else if( PARENT == scope ) | |||||
| } | |||||
| else if( PARENT == scope ) | |||||
| { | { | ||||
| if( null == getParent() ) | if( null == getParent() ) | ||||
| { | { | ||||
| @@ -19,7 +19,6 @@ import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | import org.apache.avalon.framework.component.DefaultComponentManager; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.context.ContextException; | |||||
| import org.apache.avalon.framework.logger.AbstractLogEnabled; | import org.apache.avalon.framework.logger.AbstractLogEnabled; | ||||
| import org.apache.avalon.framework.logger.LogKitLogger; | import org.apache.avalon.framework.logger.LogKitLogger; | ||||
| import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
| @@ -31,6 +30,7 @@ import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.deployer.DefaultDeployer; | import org.apache.myrmidon.components.deployer.DefaultDeployer; | ||||
| import org.apache.myrmidon.components.executor.DefaultExecutionFrame; | import org.apache.myrmidon.components.executor.DefaultExecutionFrame; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | |||||
| import org.apache.myrmidon.framework.Condition; | import org.apache.myrmidon.framework.Condition; | ||||
| import org.apache.myrmidon.interfaces.deployer.Deployer; | import org.apache.myrmidon.interfaces.deployer.Deployer; | ||||
| import org.apache.myrmidon.interfaces.deployer.DeploymentException; | import org.apache.myrmidon.interfaces.deployer.DeploymentException; | ||||
| @@ -41,6 +41,7 @@ import org.apache.myrmidon.interfaces.model.Target; | |||||
| import org.apache.myrmidon.interfaces.model.TypeLib; | import org.apache.myrmidon.interfaces.model.TypeLib; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | import org.apache.myrmidon.interfaces.workspace.Workspace; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| import org.apache.myrmidon.listeners.ProjectListener; | import org.apache.myrmidon.listeners.ProjectListener; | ||||
| /** | /** | ||||
| @@ -141,7 +142,7 @@ public class DefaultWorkspace | |||||
| private TaskContext createBaseContext() | private TaskContext createBaseContext() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final TaskContext context = new DefaultTaskContext(); | |||||
| final TaskContext context = new DefaultTaskContext( m_componentManager ); | |||||
| final String[] names = m_parameters.getNames(); | final String[] names = m_parameters.getNames(); | ||||
| for( int i = 0; i < names.length; i++ ) | for( int i = 0; i < names.length; i++ ) | ||||
| @@ -219,9 +220,6 @@ public class DefaultWorkspace | |||||
| private ExecutionFrame createExecutionFrame( final Project project ) | private ExecutionFrame createExecutionFrame( final Project project ) | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final TaskContext context = new DefaultTaskContext( m_baseContext ); | |||||
| context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | |||||
| //Create per frame ComponentManager | //Create per frame ComponentManager | ||||
| final DefaultComponentManager componentManager = | final DefaultComponentManager componentManager = | ||||
| new DefaultComponentManager( m_componentManager ); | new DefaultComponentManager( m_componentManager ); | ||||
| @@ -267,6 +265,11 @@ public class DefaultWorkspace | |||||
| componentManager.put( Project.ROLE + "/" + name, other ); | componentManager.put( Project.ROLE + "/" + name, other ); | ||||
| } | } | ||||
| // Create and configure the context | |||||
| final DefaultTaskContext context = | |||||
| new DefaultTaskContext( m_baseContext, componentManager ); | |||||
| context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | |||||
| final DefaultExecutionFrame frame = new DefaultExecutionFrame(); | final DefaultExecutionFrame frame = new DefaultExecutionFrame(); | ||||
| try | try | ||||
| @@ -276,7 +279,6 @@ public class DefaultWorkspace | |||||
| frame.enableLogging( logger ); | frame.enableLogging( logger ); | ||||
| frame.contextualize( context ); | frame.contextualize( context ); | ||||
| frame.compose( componentManager ); | |||||
| } | } | ||||
| catch( final Exception e ) | catch( final Exception e ) | ||||
| { | { | ||||
| @@ -401,10 +403,10 @@ public class DefaultWorkspace | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| catch( final ContextException ce ) | |||||
| catch( final TaskException te ) | |||||
| { | { | ||||
| final String message = REZ.getString( "condition-eval.error", name ); | final String message = REZ.getString( "condition-eval.error", name ); | ||||
| throw new TaskException( message, ce ); | |||||
| throw new TaskException( message, te ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -15,7 +15,10 @@ no-version.error=No JavaVersion in Context. | |||||
| no-name.error=No Name in Context. | no-name.error=No Name in Context. | ||||
| no-dir.error=No Base Directory in Context. | no-dir.error=No Base Directory in Context. | ||||
| no-parent.error=Can't set a property with parent scope when context has no parent. | no-parent.error=Can't set a property with parent scope when context has no parent. | ||||
| bad-find-services.error=Unable to find service "{0}". | |||||
| bad-scope.error=Unknown property scope! ({0}). | bad-scope.error=Unknown property scope! ({0}). | ||||
| bad-property.error=Property {0} must have a value of type {1}. | bad-property.error=Property {0} must have a value of type {1}. | ||||
| null-resolved-value.error=Value "{0}" resolved to null. | null-resolved-value.error=Value "{0}" resolved to null. | ||||
| bad-resolve.error=Unable to resolve value "{0}". | |||||
| bad-resolve.error=Unable to resolve value "{0}". | |||||
| bad-find-service.error=Could not find service "{0}". | |||||
| bad-service-class.error=Find service "{0}" but it was of type {1} where it was expected to be of type {2}. | |||||
| @@ -9,20 +9,21 @@ package org.apache.myrmidon.framework; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
| import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.context.Context; | |||||
| import org.apache.avalon.framework.context.ContextException; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.api.TaskContext; | |||||
| import org.apache.myrmidon.converter.Converter; | import org.apache.myrmidon.converter.Converter; | ||||
| import org.apache.myrmidon.converter.ConverterException; | import org.apache.myrmidon.converter.ConverterException; | ||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| import org.apache.myrmidon.interfaces.executor.Executor; | import org.apache.myrmidon.interfaces.executor.Executor; | ||||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | |||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| import org.apache.myrmidon.interfaces.type.TypeException; | |||||
| /** | /** | ||||
| * This is the class that Task writers should extend to provide custom tasks. | * This is the class that Task writers should extend to provide custom tasks. | ||||
| @@ -31,7 +32,6 @@ import org.apache.myrmidon.interfaces.executor.Executor; | |||||
| */ | */ | ||||
| public abstract class AbstractContainerTask | public abstract class AbstractContainerTask | ||||
| extends AbstractTask | extends AbstractTask | ||||
| implements Composable | |||||
| { | { | ||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( AbstractContainerTask.class ); | ResourceManager.getPackageResources( AbstractContainerTask.class ); | ||||
| @@ -45,12 +45,18 @@ public abstract class AbstractContainerTask | |||||
| ///For executing sub-elements as tasks | ///For executing sub-elements as tasks | ||||
| private Executor m_executor; | private Executor m_executor; | ||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| /** | |||||
| * Retrieve context from container. | |||||
| * | |||||
| * @param context the context | |||||
| */ | |||||
| public void contextualize( TaskContext context ) | |||||
| throws TaskException | |||||
| { | { | ||||
| m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE ); | |||||
| m_converter = (MasterConverter)componentManager.lookup( MasterConverter.ROLE ); | |||||
| m_executor = (Executor)componentManager.lookup( Executor.ROLE ); | |||||
| super.contextualize( context ); | |||||
| m_configurer = (Configurer)getService( Configurer.class ); | |||||
| m_converter = (MasterConverter)getService( MasterConverter.class ); | |||||
| m_executor = (Executor)getService( Executor.class ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -102,6 +108,24 @@ public abstract class AbstractContainerTask | |||||
| getConfigurer().configure( object, name, value, getContext() ); | getConfigurer().configure( object, name, value, getContext() ); | ||||
| } | } | ||||
| /** | |||||
| * Locates a type factory. | |||||
| */ | |||||
| protected final TypeFactory getTypeFactory( final String role ) | |||||
| throws TaskException | |||||
| { | |||||
| final TypeManager typeManager = (TypeManager)getService( TypeManager.class ); | |||||
| try | |||||
| { | |||||
| return typeManager.getFactory( role ); | |||||
| } | |||||
| catch( final TypeException te ) | |||||
| { | |||||
| final String message = REZ.getString( "container.no-factory.error", role ); | |||||
| throw new TaskException( message, te ); | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Convenience method for sub-class to retrieve Configurer. | * Convenience method for sub-class to retrieve Configurer. | ||||
| * | * | ||||
| @@ -12,9 +12,6 @@ import java.net.URL; | |||||
| import java.net.URLClassLoader; | import java.net.URLClassLoader; | ||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
| import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.component.Composable; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.interfaces.role.RoleManager; | import org.apache.myrmidon.interfaces.role.RoleManager; | ||||
| @@ -31,7 +28,6 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| */ | */ | ||||
| public abstract class AbstractTypeDef | public abstract class AbstractTypeDef | ||||
| extends AbstractTask | extends AbstractTask | ||||
| implements Composable | |||||
| { | { | ||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( AbstractTypeDef.class ); | ResourceManager.getPackageResources( AbstractTypeDef.class ); | ||||
| @@ -39,15 +35,6 @@ public abstract class AbstractTypeDef | |||||
| private File m_lib; | private File m_lib; | ||||
| private String m_name; | private String m_name; | ||||
| private String m_className; | private String m_className; | ||||
| private TypeManager m_typeManager; | |||||
| private RoleManager m_roleManager; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| { | |||||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
| m_roleManager = (RoleManager)componentManager.lookup( RoleManager.ROLE ); | |||||
| } | |||||
| public void setLib( final File lib ) | public void setLib( final File lib ) | ||||
| { | { | ||||
| @@ -80,15 +67,17 @@ public abstract class AbstractTypeDef | |||||
| } | } | ||||
| final String typeName = getTypeName(); | final String typeName = getTypeName(); | ||||
| final String role = m_roleManager.getRoleForName( typeName ); | |||||
| final RoleManager roleManager = (RoleManager)getService( RoleManager.class ); | |||||
| final String role = roleManager.getRoleForName( typeName ); | |||||
| final ClassLoader classLoader = createClassLoader(); | final ClassLoader classLoader = createClassLoader(); | ||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( classLoader ); | final DefaultTypeFactory factory = new DefaultTypeFactory( classLoader ); | ||||
| factory.addNameClassMapping( m_name, m_className ); | factory.addNameClassMapping( m_name, m_className ); | ||||
| final TypeManager typeManager = (TypeManager)getService( TypeManager.class ); | |||||
| try | try | ||||
| { | { | ||||
| m_typeManager.registerType( role, m_name, factory ); | |||||
| typeManager.registerType( role, m_name, factory ); | |||||
| } | } | ||||
| catch( final TypeException te ) | catch( final TypeException te ) | ||||
| { | { | ||||
| @@ -116,10 +105,5 @@ public abstract class AbstractTypeDef | |||||
| } | } | ||||
| } | } | ||||
| protected final TypeManager getTypeManager() | |||||
| { | |||||
| return m_typeManager; | |||||
| } | |||||
| protected abstract String getTypeName(); | protected abstract String getTypeName(); | ||||
| } | } | ||||
| @@ -1,6 +1,7 @@ | |||||
| container.null-value.error=Value ({0}) resolved to null. | container.null-value.error=Value ({0}) resolved to null. | ||||
| container.bad-resolve.error=Error resolving value ({0}). | container.bad-resolve.error=Error resolving value ({0}). | ||||
| container.bad-config.error=Error converting value. | container.bad-config.error=Error converting value. | ||||
| container.no-factory.error=Could not locate the type factory for type "{0}". | |||||
| typedef.no-name.error=Must specify name parameter. | typedef.no-name.error=Must specify name parameter. | ||||
| typedef.no-classname.error=Must specify classname parameter. | typedef.no-classname.error=Must specify classname parameter. | ||||
| @@ -11,7 +12,6 @@ condition.no-resolve.error=Error resolving {0}. | |||||
| pattern.ifelse-duplicate.error=Can only set one of if/else for pattern data type. | pattern.ifelse-duplicate.error=Can only set one of if/else for pattern data type. | ||||
| type.no-factory.error=Unable to retrieve DataType factory from TypeManager. | |||||
| type.no-create.error=Unable to create datatype. | type.no-create.error=Unable to create datatype. | ||||
| type.no-id.error=Id must be specified. | type.no-id.error=Id must be specified. | ||||
| @@ -9,17 +9,13 @@ package org.apache.myrmidon.framework; | |||||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | import org.apache.avalon.excalibur.i18n.ResourceManager; | ||||
| import org.apache.avalon.excalibur.i18n.Resources; | import org.apache.avalon.excalibur.i18n.Resources; | ||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.configuration.Configurable; | import org.apache.avalon.framework.configuration.Configurable; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.configuration.DefaultConfiguration; | import org.apache.avalon.framework.configuration.DefaultConfiguration; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | |||||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | import org.apache.myrmidon.interfaces.type.TypeFactory; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| /** | /** | ||||
| * This is the property "task" to declare a binding of a datatype to a name. | * This is the property "task" to declare a binding of a datatype to a name. | ||||
| @@ -36,24 +32,6 @@ public class TypeInstanceTask | |||||
| private String m_id; | private String m_id; | ||||
| private Object m_value; | private Object m_value; | ||||
| private boolean m_localScope = true; | private boolean m_localScope = true; | ||||
| private TypeFactory m_factory; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| { | |||||
| super.compose( componentManager ); | |||||
| final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
| try | |||||
| { | |||||
| m_factory = typeManager.getFactory( DataType.ROLE ); | |||||
| } | |||||
| catch( final TypeException te ) | |||||
| { | |||||
| final String message = REZ.getString( "type.no-factory.error" ); | |||||
| throw new ComponentException( message, te ); | |||||
| } | |||||
| } | |||||
| public void configure( final Configuration configuration ) | public void configure( final Configuration configuration ) | ||||
| throws ConfigurationException | throws ConfigurationException | ||||
| @@ -85,7 +63,8 @@ public class TypeInstanceTask | |||||
| try | try | ||||
| { | { | ||||
| m_value = m_factory.create( configuration.getName() ); | |||||
| final TypeFactory typeFactory = getTypeFactory( DataType.ROLE ); | |||||
| m_value = typeFactory.create( configuration.getName() ); | |||||
| } | } | ||||
| catch( final Exception e ) | catch( final Exception e ) | ||||
| { | { | ||||
| @@ -24,6 +24,4 @@ public interface ExecutionFrame | |||||
| Logger getLogger(); | Logger getLogger(); | ||||
| TaskContext getContext(); | TaskContext getContext(); | ||||
| ComponentManager getComponentManager(); | |||||
| } | } | ||||