Moved client interface of converter code to converter subpackage. Moved "provider" part of converter package to components.converter.* Cleaned up violations of IOC with ConverterEngine and renamed ConverterEngine to MasterConverter git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269085 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,35 +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.convert.engine; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.avalon.framework.component.Component; | |||
| import org.apache.avalon.framework.camelot.Registry; | |||
| /** | |||
| * Converter engine to handle converting between types. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface ConverterEngine | |||
| extends Component, Converter | |||
| { | |||
| /** | |||
| * Get registry used to locate converters. | |||
| * | |||
| * @return the LocatorRegistry | |||
| */ | |||
| Registry getRegistry(); | |||
| /** | |||
| * Get registry for converterInfo objects. | |||
| * | |||
| * @return the ConverterRegistry | |||
| */ | |||
| ConverterRegistry getInfoRegistry(); | |||
| } | |||
| @@ -1,35 +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.convert.engine; | |||
| import org.apache.avalon.framework.camelot.Info; | |||
| /** | |||
| * This info represents meta-information about a converter. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface ConverterInfo | |||
| extends Info | |||
| { | |||
| /** | |||
| * Retrieve the source type from which it can convert. | |||
| * NB: Should this be an array ???? | |||
| * | |||
| * @return the classname from which object produced | |||
| */ | |||
| String getSource(); | |||
| /** | |||
| * Retrieve the type to which the converter converts. | |||
| * NB: Should this be an array ???? | |||
| * | |||
| * @return the classname of the produced object | |||
| */ | |||
| String getDestination(); | |||
| } | |||
| @@ -1,70 +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.convert.engine; | |||
| import java.util.HashMap; | |||
| import org.apache.avalon.framework.camelot.DefaultRegistry; | |||
| import org.apache.avalon.framework.camelot.Info; | |||
| import org.apache.avalon.framework.camelot.RegistryException; | |||
| /** | |||
| * Default implementation of ConverterInfo registry. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterRegistry | |||
| extends DefaultRegistry | |||
| implements ConverterRegistry | |||
| { | |||
| protected final HashMap m_mapping = new HashMap(); | |||
| public DefaultConverterRegistry() | |||
| { | |||
| super( ConverterInfo.class ); | |||
| } | |||
| /** | |||
| * Retrieve ConverterInfo that describes converter that converts from source to destination. | |||
| * | |||
| * @param source the source classname | |||
| * @param destination the destination classname | |||
| * @return the converter-info or null if none available | |||
| */ | |||
| public String getConverterInfoName( final String source, final String destination ) | |||
| { | |||
| final HashMap map = (HashMap)m_mapping.get( source ); | |||
| if( null == map ) return null; | |||
| return (String)map.get( destination ); | |||
| } | |||
| /** | |||
| * Overidden method so can add info into mapping. | |||
| * | |||
| * @param name the name of info | |||
| * @param info the Info | |||
| * @exception RegistryException if an error occurs | |||
| */ | |||
| protected void checkInfo( final String name, final Info info ) | |||
| throws RegistryException | |||
| { | |||
| super.checkInfo( name, info ); | |||
| final ConverterInfo converterInfo = (ConverterInfo)info; | |||
| final String source = converterInfo.getSource(); | |||
| final String destination = converterInfo.getDestination(); | |||
| HashMap map = (HashMap)m_mapping.get( source ); | |||
| if( null == map ) | |||
| { | |||
| map = new HashMap(); | |||
| m_mapping.put( source, map ); | |||
| } | |||
| map.put( destination, name ); | |||
| } | |||
| } | |||
| @@ -7,7 +7,7 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.tasklet.DataType; | |||
| import org.apache.myrmidon.api.DataType; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.components.model.Condition; | |||
| @@ -7,10 +7,6 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import java.util.Iterator; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.ant.tasklet.DataType; | |||
| import org.apache.avalon.framework.component.ComponentException; | |||
| import org.apache.avalon.framework.component.ComponentManager; | |||
| import org.apache.avalon.framework.component.ComponentSelector; | |||
| @@ -20,8 +16,11 @@ import org.apache.avalon.framework.configuration.Configuration; | |||
| import org.apache.avalon.framework.configuration.ConfigurationException; | |||
| import org.apache.avalon.framework.context.Resolvable; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.api.DataType; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.components.configurer.Configurer; | |||
| import org.apache.myrmidon.components.converter.MasterConverter; | |||
| import org.apache.myrmidon.components.type.TypeManager; | |||
| /** | |||
| @@ -33,22 +32,21 @@ public class Property | |||
| extends AbstractTask | |||
| implements Configurable, Composable | |||
| { | |||
| protected String m_name; | |||
| protected Object m_value; | |||
| protected boolean m_localScope = true; | |||
| protected ComponentSelector m_selector; | |||
| protected Converter m_converter; | |||
| protected Configurer m_configurer; | |||
| private String m_name; | |||
| private Object m_value; | |||
| private boolean m_localScope = true; | |||
| private ComponentSelector m_selector; | |||
| private MasterConverter m_converter; | |||
| private Configurer m_configurer; | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentException | |||
| { | |||
| m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE ); | |||
| final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||
| m_selector = | |||
| (ComponentSelector)typeManager.lookup( "org.apache.ant.tasklet.DataTypeSelector" ); | |||
| m_selector = (ComponentSelector)typeManager.lookup( DataType.ROLE + "Selector" ); | |||
| m_converter = (Converter)componentManager.lookup( "org.apache.ant.convert.Converter" ); | |||
| m_converter = (MasterConverter)componentManager.lookup( MasterConverter.ROLE ); | |||
| } | |||
| public void configure( final Configuration configuration ) | |||
| @@ -61,7 +59,7 @@ public class Property | |||
| final String name = attributes[ i ]; | |||
| final String value = configuration.getAttribute( name ); | |||
| Object object = null; | |||
| try { object = getContext().resolveValue( value ); } | |||
| @@ -7,7 +7,8 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| import org.apache.avalon.framework.context.Context; | |||
| /** | |||
| @@ -24,9 +25,14 @@ public class StringToByteConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Byte( (String)original ); | |||
| try { return new Byte( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,7 +7,8 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| import org.apache.avalon.framework.context.Context; | |||
| /** | |||
| @@ -24,9 +25,14 @@ public class StringToClassConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return Class.forName( (String)original ); | |||
| //TODO: Should we use ContextClassLoader here??? | |||
| try { return Class.forName( (String)original ); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new ConverterException( "Error converting to class type", e ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,8 +7,9 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * String to double converter | |||
| @@ -24,9 +25,13 @@ public class StringToDoubleConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Double( (String)original ); | |||
| try { return new Double( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -8,9 +8,11 @@ | |||
| package org.apache.ant.modules.basic; | |||
| import java.io.File; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.myrmidon.api.TaskContext; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * String to file converter | |||
| @@ -26,10 +28,17 @@ public class StringToFileConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| final TaskContext taskContext = (TaskContext)context; | |||
| return taskContext.resolveFile( (String)original ); | |||
| try | |||
| { | |||
| final TaskContext taskContext = (TaskContext)context; | |||
| return taskContext.resolveFile( (String)original ); | |||
| } | |||
| catch( final TaskException te ) | |||
| { | |||
| throw new ConverterException( "Error resolving file during conversion", te ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,7 +7,8 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| import org.apache.avalon.framework.context.Context; | |||
| /** | |||
| @@ -24,9 +25,13 @@ public class StringToFloatConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Float( (String)original ); | |||
| try { return new Float( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,7 +7,8 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| import org.apache.avalon.framework.context.Context; | |||
| /** | |||
| @@ -24,9 +25,13 @@ public class StringToIntegerConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Integer( (String)original ); | |||
| try { return new Integer( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,8 +7,9 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * String to long converter | |||
| @@ -24,9 +25,13 @@ public class StringToLongConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Long( (String)original ); | |||
| try { return new Long( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,8 +7,9 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * String to short converter | |||
| @@ -24,9 +25,14 @@ public class StringToShortConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new Short( (String)original ); | |||
| try { return new Short( (String)original ); } | |||
| catch( final NumberFormatException nfe ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", nfe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -7,9 +7,11 @@ | |||
| */ | |||
| package org.apache.ant.modules.basic; | |||
| import java.net.MalformedURLException; | |||
| import java.net.URL; | |||
| import org.apache.ant.convert.AbstractConverter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.myrmidon.converter.AbstractConverter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * String to url converter | |||
| @@ -25,9 +27,14 @@ public class StringToURLConverter | |||
| } | |||
| public Object convert( final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| return new URL( (String)original ); | |||
| try { return new URL( (String)original ); } | |||
| catch( final MalformedURLException mue ) | |||
| { | |||
| throw new ConverterException( "Error formatting object", mue ); | |||
| } | |||
| } | |||
| } | |||
| @@ -10,48 +10,50 @@ package org.apache.ant.modules.core; | |||
| import java.io.File; | |||
| import java.net.MalformedURLException; | |||
| import java.net.URL; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.ant.convert.engine.ConverterEngine; | |||
| import org.apache.ant.convert.engine.DefaultConverterInfo; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.components.deployer.TskDeployer; | |||
| import org.apache.avalon.framework.component.ComponentManager; | |||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||
| 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.camelot.DefaultLocator; | |||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||
| import org.apache.avalon.framework.camelot.RegistryException; | |||
| import org.apache.myrmidon.api.AbstractTask; | |||
| import org.apache.myrmidon.api.TaskException; | |||
| import org.apache.myrmidon.components.converter.ConverterInfo; | |||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | |||
| import org.apache.myrmidon.components.deployer.TskDeployer; | |||
| import org.apache.myrmidon.components.type.DefaultComponentFactory; | |||
| 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 | |||
| public class RegisterConverter | |||
| extends AbstractTask | |||
| implements Composable | |||
| { | |||
| protected String m_sourceType; | |||
| protected String m_destinationType; | |||
| protected String m_lib; | |||
| protected String m_classname; | |||
| protected TskDeployer m_tskDeployer; | |||
| protected ConverterEngine m_converterEngine; | |||
| private String m_sourceType; | |||
| private String m_destinationType; | |||
| private String m_lib; | |||
| private String m_classname; | |||
| private TskDeployer m_tskDeployer; | |||
| private ConverterRegistry m_converterRegistry; | |||
| private TypeManager m_typeManager; | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentException | |||
| { | |||
| m_tskDeployer = (TskDeployer)componentManager.lookup( TskDeployer.ROLE ); | |||
| m_converterEngine = (ConverterEngine)componentManager. | |||
| lookup( "org.apache.ant.convert.engine.ConverterEngine" ); | |||
| 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; | |||
| @@ -61,12 +63,12 @@ public class RegisterConverter | |||
| { | |||
| m_sourceType = sourceType; | |||
| } | |||
| public void setDestinationType( final String destinationType ) | |||
| { | |||
| m_destinationType = destinationType; | |||
| } | |||
| public void execute() | |||
| throws TaskException | |||
| { | |||
| @@ -74,11 +76,11 @@ public class RegisterConverter | |||
| { | |||
| throw new TaskException( "Must specify classname parameter" ); | |||
| } | |||
| final URL url = getURL( m_lib ); | |||
| boolean isFullyDefined = true; | |||
| if( null == m_sourceType && null == m_destinationType ) | |||
| { | |||
| isFullyDefined = false; | |||
| @@ -86,7 +88,7 @@ public class RegisterConverter | |||
| else if( null == m_sourceType || null == m_destinationType ) | |||
| { | |||
| throw new TaskException( "Must specify the source-type and destination-type " + | |||
| "parameters when supplying a name" ); | |||
| "parameters when supplying a name" ); | |||
| } | |||
| if( !isFullyDefined && null == url ) | |||
| @@ -96,35 +98,34 @@ public class RegisterConverter | |||
| if( !isFullyDefined ) | |||
| { | |||
| try | |||
| { | |||
| m_tskDeployer.deployConverter( m_classname, url.toString(), url ); | |||
| try | |||
| { | |||
| m_tskDeployer.deployConverter( m_classname, url.toString(), url ); | |||
| } | |||
| catch( final DeploymentException de ) | |||
| { | |||
| throw new TaskException( "Failed deploying " + m_classname + | |||
| " from " + url, de ); | |||
| throw new TaskException( "Failed deploying " + m_classname + | |||
| " from " + url, de ); | |||
| } | |||
| } | |||
| else | |||
| { | |||
| final DefaultConverterInfo info = | |||
| new DefaultConverterInfo( m_sourceType, m_destinationType ); | |||
| final DefaultLocator locator = new DefaultLocator( m_classname, url ); | |||
| final ConverterInfo info = new ConverterInfo( m_sourceType, m_destinationType ); | |||
| m_converterRegistry.registerConverterInfo( m_classname, info ); | |||
| try | |||
| { | |||
| m_converterEngine.getInfoRegistry().register( m_classname, info ); | |||
| m_converterEngine.getRegistry().register( m_classname, locator ); | |||
| } | |||
| catch( final RegistryException re ) | |||
| final DefaultComponentFactory factory = | |||
| new DefaultComponentFactory( new URL[] { url } ); | |||
| factory.addNameClassMapping( m_classname, m_classname ); | |||
| try { m_typeManager.registerType( Converter.ROLE, m_classname, factory ); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new TaskException( "Error registering resource", re ); | |||
| throw new TaskException( "Failed to register converter " + m_classname, e ); | |||
| } | |||
| } | |||
| } | |||
| protected URL getURL( final String libName ) | |||
| private URL getURL( final String libName ) | |||
| throws TaskException | |||
| { | |||
| if( null != libName ) | |||
| @@ -5,7 +5,7 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.tasklet; | |||
| package org.apache.myrmidon.api; | |||
| import org.apache.avalon.framework.component.Component; | |||
| @@ -13,10 +13,10 @@ import org.apache.avalon.framework.component.Component; | |||
| * Base class for those classes that can appear inside the build file | |||
| * as stand alone data types. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface DataType | |||
| extends Component | |||
| { | |||
| String ROLE = "org.apache.myrmidon.api.DataType"; | |||
| } | |||
| @@ -11,8 +11,6 @@ import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.ant.convert.ConverterException; | |||
| import org.apache.avalon.excalibur.property.PropertyException; | |||
| import org.apache.avalon.excalibur.property.PropertyUtil; | |||
| import org.apache.avalon.framework.component.ComponentException; | |||
| @@ -25,6 +23,9 @@ import org.apache.avalon.framework.context.Context; | |||
| import org.apache.avalon.framework.logger.AbstractLoggable; | |||
| import org.apache.avalon.framework.logger.Loggable; | |||
| import org.apache.log.Logger; | |||
| import org.apache.myrmidon.components.converter.MasterConverter; | |||
| import org.apache.myrmidon.converter.Converter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * Class used to configure tasks. | |||
| @@ -55,12 +56,12 @@ public class DefaultConfigurer | |||
| }; | |||
| ///Converter to use for converting between values | |||
| private Converter m_converter; | |||
| private MasterConverter m_converter; | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentException | |||
| { | |||
| m_converter = (Converter)componentManager.lookup( "org.apache.ant.convert.Converter" ); | |||
| m_converter = (MasterConverter)componentManager.lookup( MasterConverter.ROLE ); | |||
| } | |||
| /** | |||
| @@ -5,20 +5,19 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert.engine; | |||
| package org.apache.myrmidon.components.converter; | |||
| /** | |||
| * This info represents meta-information about a converter. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterInfo | |||
| implements ConverterInfo | |||
| public class ConverterInfo | |||
| { | |||
| protected final String m_source; | |||
| protected final String m_destination; | |||
| private final String m_source; | |||
| private final String m_destination; | |||
| public DefaultConverterInfo( final String source, final String destination ) | |||
| public ConverterInfo( final String source, final String destination ) | |||
| { | |||
| m_source = source; | |||
| m_destination = destination; | |||
| @@ -34,7 +33,7 @@ public class DefaultConverterInfo | |||
| { | |||
| return m_source; | |||
| } | |||
| /** | |||
| * Retrieve the type to which the converter converts. | |||
| * NB: Should this be an array ???? | |||
| @@ -5,9 +5,9 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert.engine; | |||
| package org.apache.myrmidon.components.converter; | |||
| import org.apache.avalon.framework.camelot.Registry; | |||
| import org.apache.avalon.framework.component.Component; | |||
| /** | |||
| * Interface for registry for ConverterInfos. | |||
| @@ -15,15 +15,25 @@ import org.apache.avalon.framework.camelot.Registry; | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface ConverterRegistry | |||
| extends Registry | |||
| extends Component | |||
| { | |||
| String ROLE = "org.apache.myrmidon.components.converter.ConverterRegistry"; | |||
| /** | |||
| * Retrieve name of ConverterInfo that describes converter that converts | |||
| * Retrieve name of ConverterInfo that describes converter that converts | |||
| * from source to destination. | |||
| * | |||
| * @param source the source classname | |||
| * @param destination the destination classname | |||
| * @return the converter-info or null if none available | |||
| * @return the className of converter or null if none available | |||
| */ | |||
| String getConverterInfoName( String source, String destination ); | |||
| /** | |||
| * Register a converter-info | |||
| * | |||
| * @param className the className of converter | |||
| * @param info the ConverterInfo | |||
| */ | |||
| void registerConverterInfo( String className, ConverterInfo info ); | |||
| } | |||
| @@ -0,0 +1,43 @@ | |||
| /* | |||
| * 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.myrmidon.components.converter; | |||
| import java.util.HashMap; | |||
| /** | |||
| * Default implementation of ConverterInfo registry. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterRegistry | |||
| implements ConverterRegistry | |||
| { | |||
| private final HashMap m_mapping = new HashMap(); | |||
| public String getConverterInfoName( final String source, final String destination ) | |||
| { | |||
| final HashMap map = (HashMap)m_mapping.get( source ); | |||
| if( null == map ) return null; | |||
| return (String)map.get( destination ); | |||
| } | |||
| public void registerConverterInfo( final String className, final ConverterInfo info ) | |||
| { | |||
| final String source = info.getSource(); | |||
| final String destination = info.getDestination(); | |||
| HashMap map = (HashMap)m_mapping.get( source ); | |||
| if( null == map ) | |||
| { | |||
| map = new HashMap(); | |||
| m_mapping.put( source, map ); | |||
| } | |||
| map.put( destination, className ); | |||
| } | |||
| } | |||
| @@ -5,56 +5,33 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert.engine; | |||
| package org.apache.myrmidon.components.converter; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.ant.convert.ConverterException; | |||
| import org.apache.avalon.framework.logger.AbstractLoggable; | |||
| import org.apache.avalon.framework.component.ComponentManager; | |||
| import org.apache.avalon.framework.component.ComponentException; | |||
| import org.apache.avalon.framework.component.ComponentManager; | |||
| import org.apache.avalon.framework.component.ComponentSelector; | |||
| import org.apache.avalon.framework.component.Composable; | |||
| import org.apache.avalon.framework.context.Context; | |||
| import org.apache.avalon.framework.camelot.DefaultFactory; | |||
| import org.apache.avalon.framework.camelot.DefaultRegistry; | |||
| import org.apache.avalon.framework.camelot.Factory; | |||
| import org.apache.avalon.framework.camelot.Locator; | |||
| import org.apache.avalon.framework.camelot.Registry; | |||
| import org.apache.avalon.framework.logger.AbstractLoggable; | |||
| import org.apache.myrmidon.components.converter.MasterConverter; | |||
| import org.apache.myrmidon.components.type.TypeManager; | |||
| import org.apache.myrmidon.converter.Converter; | |||
| import org.apache.myrmidon.converter.ConverterException; | |||
| /** | |||
| * Converter engine to handle converting between types. | |||
| * | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterEngine | |||
| public class DefaultMasterConverter | |||
| extends AbstractLoggable | |||
| implements ConverterEngine, Composable | |||
| implements MasterConverter, Composable | |||
| { | |||
| protected final static boolean DEBUG = false; | |||
| private final static boolean DEBUG = false; | |||
| protected Factory m_factory; | |||
| protected Registry m_registry = new DefaultRegistry( Locator.class ); | |||
| protected ConverterRegistry m_infoRegistry = new DefaultConverterRegistry(); | |||
| private ConverterRegistry m_infoRegistry; | |||
| private ComponentSelector m_selector; | |||
| /** | |||
| * Get registry used to locate converters. | |||
| * | |||
| * @return the LocatorRegistry | |||
| */ | |||
| public Registry getRegistry() | |||
| { | |||
| return m_registry; | |||
| } | |||
| /** | |||
| * Get registry for converterInfo objects. | |||
| * | |||
| * @return the ConverterRegistry | |||
| */ | |||
| public ConverterRegistry getInfoRegistry() | |||
| { | |||
| return m_infoRegistry; | |||
| } | |||
| /** | |||
| * Retrieve relevent services needed to deploy. | |||
| * | |||
| @@ -64,7 +41,10 @@ public class DefaultConverterEngine | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentException | |||
| { | |||
| m_factory = (Factory)componentManager.lookup( "org.apache.avalon.framework.camelot.Factory" ); | |||
| m_infoRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); | |||
| final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||
| m_selector = (ComponentSelector)typeManager.lookup( Converter.ROLE + "Selector" ); | |||
| } | |||
| /** | |||
| @@ -77,7 +57,7 @@ public class DefaultConverterEngine | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| public Object convert( Class destination, final Object original, final Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| final Class originalClass = original.getClass(); | |||
| @@ -93,20 +73,34 @@ public class DefaultConverterEngine | |||
| } | |||
| //TODO: Start searching inheritance hierarchy for converter | |||
| final String name = | |||
| m_infoRegistry.getConverterInfoName( originalClass.getName(), | |||
| final String name = | |||
| m_infoRegistry.getConverterInfoName( originalClass.getName(), | |||
| destination.getName() ); | |||
| if( null == name ) | |||
| if( null == name ) | |||
| { | |||
| throw new ConverterException( "Unable to find converter for " + | |||
| originalClass.getName() + " to " + | |||
| throw new ConverterException( "Unable to find converter for " + | |||
| originalClass.getName() + " to " + | |||
| destination.getName() + " conversion" ); | |||
| } | |||
| //TODO: Start caching converters instead of repeatedly instantiating em. | |||
| final Locator locator = (Locator)m_registry.getInfo( name, Locator.class ); | |||
| final Converter converter = (Converter)m_factory.create( locator, Converter.class ); | |||
| return converter.convert( destination, original, context ); | |||
| try | |||
| { | |||
| //TODO: Start caching converters instead of repeatedly instantiating em. | |||
| final Converter converter = (Converter)m_selector.select( name ); | |||
| if( DEBUG ) | |||
| { | |||
| getLogger().debug( "Found Converter: " + converter ); | |||
| } | |||
| return converter.convert( destination, original, context ); | |||
| } | |||
| catch( final ComponentException ce ) | |||
| { | |||
| throw new ConverterException( "Badly configured TypeManager missing " + | |||
| "converter definition" ); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,22 @@ | |||
| /* | |||
| * 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.myrmidon.components.converter; | |||
| import org.apache.avalon.framework.component.Component; | |||
| import org.apache.myrmidon.converter.Converter; | |||
| /** | |||
| * Master Converter to handle converting between types. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface MasterConverter | |||
| extends Component, Converter | |||
| { | |||
| String ROLE = "org.apache.myrmidon.components.converter.MasterConverter"; | |||
| } | |||
| @@ -15,12 +15,8 @@ import java.util.Iterator; | |||
| import java.util.zip.ZipEntry; | |||
| import java.util.zip.ZipException; | |||
| import java.util.zip.ZipFile; | |||
| import org.apache.ant.convert.engine.ConverterEngine; | |||
| import org.apache.ant.convert.engine.ConverterRegistry; | |||
| import org.apache.ant.convert.engine.DefaultConverterInfo; | |||
| import org.apache.avalon.framework.camelot.AbstractDeployer; | |||
| import org.apache.avalon.framework.camelot.DefaultLocator; | |||
| import org.apache.avalon.framework.camelot.DefaultRegistry; | |||
| import org.apache.avalon.framework.camelot.DeployerUtil; | |||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||
| import org.apache.avalon.framework.camelot.Loader; | |||
| @@ -35,10 +31,13 @@ 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.converter.ConverterInfo; | |||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | |||
| 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; | |||
| import org.apache.myrmidon.components.type.TypeManager; | |||
| import org.apache.myrmidon.converter.Converter; | |||
| /** | |||
| * This class deploys a .tsk file into a registry. | |||
| @@ -51,9 +50,6 @@ public class DefaultTskDeployer | |||
| { | |||
| private final static String TSKDEF_FILE = "TASK-LIB/taskdefs.xml"; | |||
| //private Registry m_dataTypeRegistry; | |||
| //private Registry m_taskRegistry; | |||
| private Registry m_converterRegistry; | |||
| private ConverterRegistry m_converterInfoRegistry; | |||
| private TypeManager m_typeManager; | |||
| @@ -75,20 +71,7 @@ public class DefaultTskDeployer | |||
| public void compose( final ComponentManager componentManager ) | |||
| throws ComponentException | |||
| { | |||
| //UGLY HACK alert !!! | |||
| //final Executor executor = (Executor)componentManager.lookup( Executor.ROLE ); | |||
| //m_taskRegistry = executor.getRegistry(); | |||
| final ConverterEngine converterEngine = (ConverterEngine)componentManager. | |||
| lookup( "org.apache.ant.convert.engine.ConverterEngine" ); | |||
| m_converterInfoRegistry = converterEngine.getInfoRegistry(); | |||
| m_converterRegistry = converterEngine.getRegistry(); | |||
| //final DataTypeEngine dataTypeEngine = (DataTypeEngine)componentManager. | |||
| //lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" ); | |||
| //m_dataTypeRegistry = dataTypeEngine.getRegistry(); | |||
| m_converterInfoRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); | |||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||
| } | |||
| @@ -128,7 +111,7 @@ public class DefaultTskDeployer | |||
| { | |||
| final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); | |||
| final DefaultComponentFactory factory = | |||
| final DefaultComponentFactory factory = | |||
| new DefaultComponentFactory( new URL[] { url } ); | |||
| try | |||
| @@ -142,7 +125,7 @@ public class DefaultTskDeployer | |||
| final Configuration[] converters = taskdefs.getChildren( "converter" ); | |||
| for( int i = 0; i < converters.length; i++ ) | |||
| { | |||
| handleConverter( converters[ i ], url ); | |||
| handleConverter( converters[ i ], url, factory ); | |||
| } | |||
| final Configuration[] datatypes = taskdefs.getChildren( "datatype" ); | |||
| @@ -155,6 +138,10 @@ public class DefaultTskDeployer | |||
| { | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new DeploymentException( "Failed to deploy " + location, e ); | |||
| } | |||
| } | |||
| public void deployConverter( String name, String location, URL url ) | |||
| @@ -171,7 +158,9 @@ public class DefaultTskDeployer | |||
| { | |||
| if( converters[ i ].getAttribute( "classname" ).equals( name ) ) | |||
| { | |||
| handleConverter( converters[ i ], url ); | |||
| final DefaultComponentFactory factory = | |||
| new DefaultComponentFactory( new URL[] { url } ); | |||
| handleConverter( converters[ i ], url, factory ); | |||
| break; | |||
| } | |||
| } | |||
| @@ -180,6 +169,10 @@ public class DefaultTskDeployer | |||
| { | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new DeploymentException( "Failed to deploy " + name, e ); | |||
| } | |||
| } | |||
| public void deployDataType( final String name, final String location, final URL url ) | |||
| @@ -197,7 +190,7 @@ public class DefaultTskDeployer | |||
| { | |||
| if( datatypes[ i ].getAttribute( "name" ).equals( name ) ) | |||
| { | |||
| final DefaultComponentFactory factory = | |||
| final DefaultComponentFactory factory = | |||
| new DefaultComponentFactory( new URL[] { url } ); | |||
| handleDataType( datatypes[ i ], url, factory ); | |||
| break; | |||
| @@ -208,6 +201,10 @@ public class DefaultTskDeployer | |||
| { | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new DeploymentException( "Failed to deploy " + name, e ); | |||
| } | |||
| } | |||
| public void deployTask( final String name, final String location, final URL url ) | |||
| @@ -224,7 +221,7 @@ public class DefaultTskDeployer | |||
| { | |||
| if( tasks[ i ].getAttribute( "name" ).equals( name ) ) | |||
| { | |||
| final DefaultComponentFactory factory = | |||
| final DefaultComponentFactory factory = | |||
| new DefaultComponentFactory( new URL[] { url } ); | |||
| handleTask( tasks[ i ], url, factory ); | |||
| break; | |||
| @@ -235,90 +232,56 @@ public class DefaultTskDeployer | |||
| { | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new DeploymentException( "Failed to deploy " + name, e ); | |||
| } | |||
| } | |||
| private void handleConverter( final Configuration converter, final URL url ) | |||
| throws DeploymentException, ConfigurationException | |||
| private void handleConverter( final Configuration converter, | |||
| final URL url, | |||
| final DefaultComponentFactory factory ) | |||
| throws Exception | |||
| { | |||
| final String name = converter.getAttribute( "classname" ); | |||
| final String source = converter.getAttribute( "source" ); | |||
| final String destination = converter.getAttribute( "destination" ); | |||
| final DefaultConverterInfo info = new DefaultConverterInfo( source, destination ); | |||
| final ConverterInfo info = new ConverterInfo( source, destination ); | |||
| m_converterInfoRegistry.registerConverterInfo( name, info ); | |||
| try { m_converterInfoRegistry.register( name, info ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new DeploymentException( "Error registering converter info " + | |||
| name + " due to " + re, | |||
| re ); | |||
| } | |||
| final DefaultLocator locator = new DefaultLocator( name, url ); | |||
| try { m_converterRegistry.register( name, locator ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new DeploymentException( "Error registering converter locator " + | |||
| name + " due to " + re, | |||
| re ); | |||
| } | |||
| factory.addNameClassMapping( name, name ); | |||
| m_typeManager.registerType( Converter.ROLE, name, factory ); | |||
| getLogger().debug( "Registered converter " + name + " that converts from " + | |||
| 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 | |||
| throws Exception | |||
| { | |||
| final String name = task.getAttribute( "name" ); | |||
| final String className = task.getAttribute( "classname" ); | |||
| /* | |||
| final DefaultLocator info = new DefaultLocator( className, url ); | |||
| try { m_taskRegistry.register( name, info ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new DeploymentException( "Error registering " + name + " due to " + re, | |||
| re ); | |||
| } | |||
| */ | |||
| 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 ); | |||
| } | |||
| m_typeManager.registerType( Task.ROLE, name, factory ); | |||
| 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 | |||
| throws Exception | |||
| { | |||
| final String name = datatype.getAttribute( "name" ); | |||
| final String className = datatype.getAttribute( "classname" ); | |||
| /* | |||
| final DefaultLocator info = new DefaultLocator( className, url ); | |||
| try { m_dataTypeRegistry.register( name, info ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new DeploymentException( "Error registering " + name + " due to " + re, | |||
| re ); | |||
| } | |||
| */ | |||
| factory.addNameClassMapping( name, className ); | |||
| try { m_typeManager.registerType( "org.apache.ant.tasklet.DataType", name, factory ); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new DeploymentException( "Error registering " + name + " due to " + e, e ); | |||
| } | |||
| m_typeManager.registerType( "org.apache.ant.tasklet.DataType", name, factory ); | |||
| getLogger().debug( "Registered datatype " + name + " as " + className ); | |||
| } | |||
| @@ -8,7 +8,8 @@ | |||
| package org.apache.myrmidon.components.embeddor; | |||
| import java.io.File; | |||
| import org.apache.ant.convert.engine.ConverterEngine; | |||
| import org.apache.myrmidon.components.converter.MasterConverter; | |||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | |||
| import org.apache.avalon.excalibur.io.FileUtil; | |||
| import org.apache.avalon.framework.activity.Initializable; | |||
| import org.apache.avalon.framework.camelot.CamelotUtil; | |||
| @@ -24,10 +25,10 @@ import org.apache.avalon.framework.parameters.Parameters; | |||
| 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.deployer.TskDeployer; | |||
| 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; | |||
| import org.apache.myrmidon.components.type.TypeManager; | |||
| /** | |||
| * Default implementation of Embeddor. | |||
| @@ -44,13 +45,12 @@ public class MyrmidonEmbeddor | |||
| private TskDeployer m_deployer; | |||
| private TypeManager m_typeManager; | |||
| private ConverterEngine m_converterEngine; | |||
| private MasterConverter m_converter; | |||
| private ConverterRegistry m_converterRegistry; | |||
| private Executor m_executor; | |||
| private Configurer m_configurer; | |||
| private Factory m_factory; | |||
| private DefaultComponentManager m_componentManager; | |||
| private Parameters m_parameters; | |||
| @@ -106,7 +106,6 @@ public class MyrmidonEmbeddor | |||
| m_defaults = createDefaultParameters(); | |||
| //create all the components | |||
| m_factory = new DefaultFactory(); | |||
| createComponents(); | |||
| //setup the component manager | |||
| @@ -136,13 +135,13 @@ public class MyrmidonEmbeddor | |||
| public void dispose() | |||
| throws Exception | |||
| { | |||
| m_converterEngine = null; | |||
| m_converterRegistry = null; | |||
| m_converter = null; | |||
| m_executor = null; | |||
| m_projectManager = null; | |||
| m_builder = null; | |||
| m_deployer = null; | |||
| m_configurer = null; | |||
| m_factory = null; | |||
| m_componentManager = null; | |||
| m_parameters = null; | |||
| m_defaults = null; | |||
| @@ -167,9 +166,10 @@ public class MyrmidonEmbeddor | |||
| defaults.setParameter( "myrmidon.lib.path", "lib" ); | |||
| //create all the default properties for components | |||
| defaults.setParameter( "org.apache.ant.convert.engine.ConverterEngine", | |||
| "org.apache.ant.convert.engine.DefaultConverterEngine" ); | |||
| defaults.setParameter( MasterConverter.ROLE, | |||
| "org.apache.myrmidon.components.converter.DefaultMasterConverter" ); | |||
| defaults.setParameter( ConverterRegistry.ROLE, | |||
| "org.apache.myrmidon.components.converter.DefaultConverterRegistry" ); | |||
| defaults.setParameter( TypeManager.ROLE, | |||
| "org.apache.myrmidon.components.type.DefaultTypeManager" ); | |||
| defaults.setParameter( Executor.ROLE, | |||
| @@ -195,10 +195,7 @@ public class MyrmidonEmbeddor | |||
| { | |||
| final DefaultComponentManager componentManager = new DefaultComponentManager(); | |||
| componentManager.put( "org.apache.ant.convert.engine.ConverterEngine", | |||
| m_converterEngine ); | |||
| componentManager.put( "org.apache.ant.convert.Converter", m_converterEngine ); | |||
| componentManager.put( "org.apache.avalon.framework.camelot.Factory", m_factory ); | |||
| componentManager.put( MasterConverter.ROLE, m_converter ); | |||
| //Following components required when Myrmidon is used as build tool | |||
| componentManager.put( ProjectManager.ROLE, m_projectManager ); | |||
| @@ -209,6 +206,7 @@ public class MyrmidonEmbeddor | |||
| //Following components used when want to types (ie tasks/mappers etc) | |||
| componentManager.put( TypeManager.ROLE, m_typeManager ); | |||
| componentManager.put( ConverterRegistry.ROLE, m_converterRegistry ); | |||
| //Following components required when allowing Container tasks | |||
| componentManager.put( Configurer.ROLE, m_configurer ); | |||
| @@ -227,8 +225,11 @@ public class MyrmidonEmbeddor | |||
| { | |||
| String component = null; | |||
| component = getParameter( "org.apache.ant.convert.engine.ConverterEngine" ); | |||
| m_converterEngine = (ConverterEngine)createComponent( component, ConverterEngine.class ); | |||
| component = getParameter( ConverterRegistry.ROLE ); | |||
| m_converterRegistry = (ConverterRegistry)createComponent( component, ConverterRegistry.class ); | |||
| component = getParameter( "org.apache.myrmidon.components.converter.MasterConverter" ); | |||
| m_converter = (MasterConverter)createComponent( component, MasterConverter.class ); | |||
| component = getParameter( Configurer.ROLE ); | |||
| m_configurer = (Configurer)createComponent( component, Configurer.class ); | |||
| @@ -257,8 +258,8 @@ public class MyrmidonEmbeddor | |||
| private void setupComponents() | |||
| throws Exception | |||
| { | |||
| setupComponent( m_factory ); | |||
| setupComponent( m_converterEngine ); | |||
| setupComponent( m_converterRegistry ); | |||
| setupComponent( m_converter ); | |||
| setupComponent( m_executor ); | |||
| setupComponent( m_projectManager ); | |||
| setupComponent( m_builder ); | |||
| @@ -417,7 +418,7 @@ public class MyrmidonEmbeddor | |||
| } | |||
| catch( final ClassNotFoundException cnfe ) | |||
| { | |||
| throw new Exception( "Could not find the class for " + clazz + | |||
| throw new Exception( "Could not find the class for " + clazz + | |||
| " (" + component + ")" ); | |||
| } | |||
| } | |||
| @@ -7,7 +7,6 @@ | |||
| */ | |||
| package org.apache.myrmidon.components.executor; | |||
| import org.apache.ant.convert.engine.ConverterEngine; | |||
| import org.apache.avalon.framework.activity.Disposable; | |||
| import org.apache.avalon.framework.activity.Initializable; | |||
| import org.apache.avalon.framework.component.Component; | |||
| @@ -50,7 +49,6 @@ public class DefaultExecutor | |||
| { | |||
| //cache CM so it can be used while executing tasks | |||
| m_componentManager = componentManager; | |||
| //m_factory = (Factory)componentManager.lookup( "org.apache.avalon.framework.camelot.Factory" ); | |||
| m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE ); | |||
| @@ -5,7 +5,7 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert; | |||
| package org.apache.myrmidon.converter; | |||
| import org.apache.avalon.framework.context.Context; | |||
| @@ -17,8 +17,8 @@ import org.apache.avalon.framework.context.Context; | |||
| public abstract class AbstractConverter | |||
| implements Converter | |||
| { | |||
| protected final Class m_source; | |||
| protected final Class m_destination; | |||
| private final Class m_source; | |||
| private final Class m_destination; | |||
| /** | |||
| * Constructor for a converter between types source and destination | |||
| @@ -42,7 +42,7 @@ public abstract class AbstractConverter | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| public Object convert( final Class destination, final Object original, Context context ) | |||
| throws Exception | |||
| throws ConverterException | |||
| { | |||
| if( m_destination != destination ) | |||
| { | |||
| @@ -52,10 +52,10 @@ public abstract class AbstractConverter | |||
| if( !m_source.isInstance( original ) ) | |||
| { | |||
| throw new IllegalArgumentException( "Object '" + original + "' is not an " + | |||
| throw new IllegalArgumentException( "Object '" + original + "' is not an " + | |||
| "instance of " + m_source.getName() ); | |||
| } | |||
| return convert( original, context ); | |||
| } | |||
| @@ -68,6 +68,6 @@ public abstract class AbstractConverter | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| protected abstract Object convert( Object original, Context context ) | |||
| throws Exception; | |||
| throws ConverterException; | |||
| } | |||
| @@ -5,8 +5,9 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert; | |||
| package org.apache.myrmidon.converter; | |||
| import org.apache.avalon.framework.component.Component; | |||
| import org.apache.avalon.framework.context.Context; | |||
| /** | |||
| @@ -15,10 +16,13 @@ import org.apache.avalon.framework.context.Context; | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface Converter | |||
| extends Component | |||
| { | |||
| String ROLE = "org.apache.myrmidon.converter.Converter"; | |||
| /** | |||
| * Convert original to destination type. | |||
| * Destination is passed so that one converter can potentiall | |||
| * Destination is passed so that one converter can potentiall | |||
| * convert to multiple different types. | |||
| * | |||
| * @param destination the destinaiton type | |||
| @@ -28,5 +32,5 @@ public interface Converter | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| Object convert( Class destination, Object original, Context context ) | |||
| throws ConverterException, Exception; | |||
| throws ConverterException; | |||
| } | |||
| @@ -5,13 +5,13 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.convert; | |||
| package org.apache.myrmidon.converter; | |||
| import org.apache.avalon.framework.CascadingException; | |||
| /** | |||
| * ConverterException thrown when a problem occurs during convertion etc. | |||
| * | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class ConverterException | |||
| @@ -20,7 +20,7 @@ public class ConverterException | |||
| /** | |||
| * Basic constructor with a message | |||
| * | |||
| * @param message the message | |||
| * @param message the message | |||
| */ | |||
| public ConverterException( final String message ) | |||
| { | |||
| @@ -30,7 +30,7 @@ public class ConverterException | |||
| /** | |||
| * Constructor that builds cascade so that other exception information can be retained. | |||
| * | |||
| * @param message the message | |||
| * @param message the message | |||
| * @param throwable the throwable | |||
| */ | |||
| public ConverterException( final String message, final Throwable throwable ) | |||
| @@ -7,7 +7,7 @@ | |||
| */ | |||
| package org.apache.myrmidon.framework; | |||
| import org.apache.ant.tasklet.DataType; | |||
| import org.apache.myrmidon.api.DataType; | |||
| /** | |||
| * Interface for ItemSet. | |||
| @@ -7,7 +7,7 @@ | |||
| */ | |||
| package org.apache.myrmidon.framework; | |||
| import org.apache.ant.tasklet.DataType; | |||
| import org.apache.myrmidon.api.DataType; | |||
| /** | |||
| * Interface for Mappers. | |||