From b689612fa923ba74b5c89dc891aeff801799e555 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sat, 2 Jun 2001 06:58:12 +0000 Subject: [PATCH] Integrate TypeManager into embeddor and in deployment mechanism. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269081 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/myrmidon/api/Task.java | 2 + .../deployer/DefaultTskDeployer.java | 58 ++++++++++++++----- .../components/embeddor/MyrmidonEmbeddor.java | 21 +++++-- .../components/type/DefaultTypeManager.java | 5 ++ .../myrmidon/components/type/TypeManager.java | 3 +- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java b/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java index 3217c44ce..ccc6615c7 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java @@ -25,6 +25,8 @@ package org.apache.myrmidon.api; */ public interface Task { + String ROLE = "org.apache.myrmidon.api.Task"; + /** * Execute task. * This method is called to perform actual work associated with task. diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java index a87075520..0d477d271 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java @@ -35,7 +35,11 @@ import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.Loggable; import org.apache.log.Logger; +import org.apache.myrmidon.api.Task; import org.apache.myrmidon.components.executor.Executor; +import org.apache.myrmidon.components.type.TypeManager; +import org.apache.myrmidon.components.type.ComponentFactory; +import org.apache.myrmidon.components.type.DefaultComponentFactory; /** * This class deploys a .tsk file into a registry. @@ -52,13 +56,13 @@ public class DefaultTskDeployer private Registry m_taskRegistry; private Registry m_converterRegistry; private ConverterRegistry m_converterInfoRegistry; + private TypeManager m_typeManager; /** * Default constructor. */ public DefaultTskDeployer() { - super(); m_autoUndeploy = true; m_type = "Task"; } @@ -86,6 +90,8 @@ public class DefaultTskDeployer lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); m_dataTypeRegistry = dataTypeEngine.getRegistry(); + + m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); } /** @@ -124,12 +130,15 @@ public class DefaultTskDeployer { final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); + final DefaultComponentFactory factory = + new DefaultComponentFactory( new URL[] { url } ); + try { final Configuration[] tasks = taskdefs.getChildren( "task" ); for( int i = 0; i < tasks.length; i++ ) { - handleTask( tasks[ i ], url ); + handleTask( tasks[ i ], url, factory ); } final Configuration[] converters = taskdefs.getChildren( "converter" ); @@ -141,7 +150,7 @@ public class DefaultTskDeployer final Configuration[] datatypes = taskdefs.getChildren( "datatype" ); for( int i = 0; i < datatypes.length; i++ ) { - handleDataType( datatypes[ i ], url ); + handleDataType( datatypes[ i ], url, factory ); } } catch( final ConfigurationException ce ) @@ -190,7 +199,9 @@ public class DefaultTskDeployer { if( datatypes[ i ].getAttribute( "name" ).equals( name ) ) { - handleDataType( datatypes[ i ], url ); + final DefaultComponentFactory factory = + new DefaultComponentFactory( new URL[] { url } ); + handleDataType( datatypes[ i ], url, factory ); break; } } @@ -215,7 +226,9 @@ public class DefaultTskDeployer { if( tasks[ i ].getAttribute( "name" ).equals( name ) ) { - handleTask( tasks[ i ], url ); + final DefaultComponentFactory factory = + new DefaultComponentFactory( new URL[] { url } ); + handleTask( tasks[ i ], url, factory ); break; } } @@ -257,13 +270,15 @@ public class DefaultTskDeployer source + " to " + destination ); } - private void handleTask( final Configuration task, final URL url ) + private void handleTask( final Configuration task, + final URL url, + final DefaultComponentFactory factory ) throws DeploymentException, ConfigurationException { final String name = task.getAttribute( "name" ); - final String classname = task.getAttribute( "classname" ); + final String className = task.getAttribute( "classname" ); - final DefaultLocator info = new DefaultLocator( classname, url ); + final DefaultLocator info = new DefaultLocator( className, url ); try { m_taskRegistry.register( name, info ); } catch( final RegistryException re ) @@ -272,16 +287,26 @@ public class DefaultTskDeployer re ); } - getLogger().debug( "Registered task " + name + " as " + classname ); + factory.addNameClassMapping( name, className ); + + try { m_typeManager.registerType( Task.ROLE, name, factory ); } + catch( final Exception e ) + { + throw new DeploymentException( "Error registering " + name + " due to " + e, e ); + } + + getLogger().debug( "Registered task " + name + " as " + className ); } - private void handleDataType( final Configuration datatype, final URL url ) + private void handleDataType( final Configuration datatype, + final URL url, + final DefaultComponentFactory factory ) throws DeploymentException, ConfigurationException { final String name = datatype.getAttribute( "name" ); - final String classname = datatype.getAttribute( "classname" ); + final String className = datatype.getAttribute( "classname" ); - final DefaultLocator info = new DefaultLocator( classname, url ); + final DefaultLocator info = new DefaultLocator( className, url ); try { m_dataTypeRegistry.register( name, info ); } catch( final RegistryException re ) @@ -290,6 +315,13 @@ public class DefaultTskDeployer re ); } - getLogger().debug( "Registered datatype " + name + " as " + classname ); + factory.addNameClassMapping( name, className ); + try { m_typeManager.registerType( Task.ROLE, name, factory ); } + catch( final Exception e ) + { + throw new DeploymentException( "Error registering " + name + " due to " + e, e ); + } + + getLogger().debug( "Registered datatype " + name + " as " + className ); } } diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java index 62f248baf..e83897610 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java @@ -26,6 +26,7 @@ import org.apache.myrmidon.api.JavaVersion; import org.apache.myrmidon.components.builder.ProjectBuilder; import org.apache.myrmidon.components.configurer.Configurer; import org.apache.myrmidon.components.executor.Executor; +import org.apache.myrmidon.components.type.TypeManager; import org.apache.myrmidon.components.manager.ProjectManager; import org.apache.myrmidon.components.deployer.TskDeployer; @@ -39,14 +40,17 @@ public class MyrmidonEmbeddor extends AbstractLoggable implements Embeddor { - private ConverterEngine m_converterEngine; - private DataTypeEngine m_dataTypeEngine; - private Executor m_executor; private ProjectManager m_projectManager; - private ProjectBuilder m_builder; private TskDeployer m_deployer; + + private DataTypeEngine m_dataTypeEngine; + private TypeManager m_typeManager; + private ConverterEngine m_converterEngine; + + private Executor m_executor; private Configurer m_configurer; + private Factory m_factory; @@ -170,6 +174,9 @@ public class MyrmidonEmbeddor "org.apache.ant.convert.engine.DefaultConverterEngine" ); defaults.setParameter( "org.apache.ant.tasklet.engine.DataTypeEngine", "org.apache.ant.tasklet.engine.DefaultDataTypeEngine" ); + + defaults.setParameter( TypeManager.ROLE, + "org.apache.myrmidon.components.type.DefaultTypeManager" ); defaults.setParameter( Executor.ROLE, "org.apache.myrmidon.components.executor.DefaultExecutor" ); defaults.setParameter( ProjectManager.ROLE, @@ -206,6 +213,9 @@ public class MyrmidonEmbeddor //Following components required when Myrmidon allows user deployment of tasks etal. componentManager.put( TskDeployer.ROLE, m_deployer ); + //Following components used when want to types (ie tasks/mappers etc) + componentManager.put( TypeManager.ROLE, m_typeManager ); + //Following components required when allowing Container tasks componentManager.put( Configurer.ROLE, m_configurer ); componentManager.put( Executor.ROLE, m_executor ); @@ -229,6 +239,9 @@ public class MyrmidonEmbeddor component = getParameter( "org.apache.ant.tasklet.engine.DataTypeEngine" ); m_dataTypeEngine = (DataTypeEngine)createComponent( component, DataTypeEngine.class ); + component = getParameter( TypeManager.ROLE ); + m_typeManager = (TypeManager)createComponent( component, TypeManager.class ); + component = getParameter( Executor.ROLE ); m_executor = (Executor)createComponent( component, Executor.class ); diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java index e87e334b3..bba1724c9 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java @@ -26,6 +26,11 @@ public class DefaultTypeManager ///Maps role to TypedComponentSelector. private final HashMap m_roleMap = new HashMap(); + public DefaultTypeManager() + { + this( null ); + } + public DefaultTypeManager( final TypeManager parent ) { m_parent = parent; diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java index 5cc645cca..78a89c069 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java @@ -7,6 +7,7 @@ */ package org.apache.myrmidon.components.type; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentManager; /** @@ -15,7 +16,7 @@ import org.apache.avalon.framework.component.ComponentManager; * @author Peter Donald */ public interface TypeManager - extends ComponentManager + extends Component, ComponentManager { String ROLE = "org.apache.myrmidon.components.type.TypeManager";