git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269133 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,100 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.modules.core; | |||||
| import java.io.File; | |||||
| 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.TaskException; | |||||
| import org.apache.myrmidon.api.AbstractTask; | |||||
| import org.apache.myrmidon.components.deployer.Deployer; | |||||
| import org.apache.myrmidon.components.executor.Executor; | |||||
| import org.apache.myrmidon.components.type.TypeManager; | |||||
| /** | |||||
| * Method to register a a typeet. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public abstract class AbstractTypeDefinition | |||||
| extends AbstractTask | |||||
| implements Composable | |||||
| { | |||||
| private String m_lib; | |||||
| private String m_name; | |||||
| private String m_classname; | |||||
| private Deployer m_deployer; | |||||
| private TypeManager m_typeManager; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| { | |||||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
| m_deployer = (Deployer)componentManager.lookup( Deployer.ROLE ); | |||||
| } | |||||
| public void setLib( final String lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void setName( final String name ) | |||||
| { | |||||
| m_name = name; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void execute() | |||||
| throws TaskException | |||||
| { | |||||
| if( null == m_name ) | |||||
| { | |||||
| throw new TaskException( "Must specify name parameter" ); | |||||
| } | |||||
| else if( null == m_lib && null == m_classname ) | |||||
| { | |||||
| throw new TaskException( "Must specify classname if you don't specify " + | |||||
| "lib parameter" ); | |||||
| } | |||||
| final File file = getFile( m_lib ); | |||||
| registerResource( m_name, m_classname, file ); | |||||
| } | |||||
| protected final Deployer getDeployer() | |||||
| { | |||||
| return m_deployer; | |||||
| } | |||||
| protected final TypeManager getTypeManager() | |||||
| { | |||||
| return m_typeManager; | |||||
| } | |||||
| private final File getFile( final String libName ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null != libName ) | |||||
| { | |||||
| return getContext().resolveFile( libName ); | |||||
| } | |||||
| else | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| protected abstract void registerResource( String name, String classname, File file ) | |||||
| throws TaskException; | |||||
| } | |||||
| @@ -1,2 +0,0 @@ | |||||
| This package is required for operation. No task within this directory is allowed to | |||||
| require parameters other than strings for converter. | |||||
| @@ -1,141 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.modules.core; | |||||
| import java.io.File; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | |||||
| 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.TaskException; | |||||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | |||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.deployer.Deployer; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeFactory; | |||||
| import org.apache.myrmidon.components.type.TypeManager; | |||||
| import org.apache.myrmidon.converter.Converter; | |||||
| /** | |||||
| * Method to register a single converter. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class RegisterConverter | |||||
| extends AbstractTask | |||||
| implements Composable | |||||
| { | |||||
| private String m_sourceType; | |||||
| private String m_destinationType; | |||||
| private String m_lib; | |||||
| private String m_classname; | |||||
| private Deployer m_deployer; | |||||
| private ConverterRegistry m_converterRegistry; | |||||
| private TypeManager m_typeManager; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentException | |||||
| { | |||||
| m_deployer = (Deployer)componentManager.lookup( Deployer.ROLE ); | |||||
| m_converterRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); | |||||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||||
| } | |||||
| public void setLib( final String lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void setSourceType( final String sourceType ) | |||||
| { | |||||
| m_sourceType = sourceType; | |||||
| } | |||||
| public void setDestinationType( final String destinationType ) | |||||
| { | |||||
| m_destinationType = destinationType; | |||||
| } | |||||
| public void execute() | |||||
| throws TaskException | |||||
| { | |||||
| if( null == m_classname ) | |||||
| { | |||||
| throw new TaskException( "Must specify classname parameter" ); | |||||
| } | |||||
| boolean isFullyDefined = true; | |||||
| final File file = getFile( m_lib ); | |||||
| if( null == m_sourceType && null == m_destinationType ) | |||||
| { | |||||
| isFullyDefined = false; | |||||
| } | |||||
| else if( null == m_sourceType || null == m_destinationType ) | |||||
| { | |||||
| throw new TaskException( "Must specify the source-type and destination-type " + | |||||
| "parameters when supplying a name" ); | |||||
| } | |||||
| if( !isFullyDefined && null == file ) | |||||
| { | |||||
| throw new TaskException( "Must supply parameter if not fully specifying converter" ); | |||||
| } | |||||
| if( !isFullyDefined ) | |||||
| { | |||||
| try | |||||
| { | |||||
| m_deployer.deployConverter( m_classname, file ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw new TaskException( "Failed deploying " + m_classname + | |||||
| " from " + file, de ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| try | |||||
| { | |||||
| m_converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType ); | |||||
| final URL url = file.toURL(); | |||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url } ); | |||||
| factory.addNameClassMapping( m_classname, m_classname ); | |||||
| m_typeManager.registerType( Converter.ROLE, m_classname, factory ); | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| throw new TaskException( "Failed to register converter " + m_classname, e ); | |||||
| } | |||||
| } | |||||
| } | |||||
| private File getFile( final String libName ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null != libName ) | |||||
| { | |||||
| return getContext().resolveFile( libName ); | |||||
| } | |||||
| else | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,53 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.modules.core; | |||||
| import java.io.File; | |||||
| import java.net.URL; | |||||
| import org.apache.myrmidon.api.DataType; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeFactory; | |||||
| /** | |||||
| * Method to register a single datatype. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class RegisterDataType | |||||
| extends AbstractTypeDefinition | |||||
| { | |||||
| protected void registerResource( final String name, | |||||
| final String className, | |||||
| final File file ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null == className ) | |||||
| { | |||||
| try { getDeployer().deployType( DataType.ROLE, name, file ); } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw new TaskException( "Failed deploying " + name + " from " + file, de ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| try | |||||
| { | |||||
| final URL url = file.toURL(); | |||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url } ); | |||||
| factory.addNameClassMapping( name, className ); | |||||
| getTypeManager().registerType( DataType.ROLE, name, factory ); | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| throw new TaskException( "Failed registering " + name + " from " + file, e ); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,53 +0,0 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.modules.core; | |||||
| import java.io.File; | |||||
| import java.net.URL; | |||||
| import org.apache.myrmidon.api.Task; | |||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.type.DefaultTypeFactory; | |||||
| /** | |||||
| * Method to register a single tasklet. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class RegisterTasklet | |||||
| extends AbstractTypeDefinition | |||||
| { | |||||
| protected void registerResource( final String name, | |||||
| final String className, | |||||
| final File file ) | |||||
| throws TaskException | |||||
| { | |||||
| if( null == className ) | |||||
| { | |||||
| try { getDeployer().deployType( Task.ROLE, name, file ); } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw new TaskException( "Failed deploying " + name + " from " + file, de ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| try | |||||
| { | |||||
| final URL url = file.toURL(); | |||||
| final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url } ); | |||||
| factory.addNameClassMapping( name, className ); | |||||
| getTypeManager().registerType( Task.ROLE, name, factory ); | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| throw new TaskException( "Failed registering " + name + " from " + file, e ); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||