From 362616390fb06104b98d1ddcab5e2bc8d998a793 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 3 Jun 2001 05:14:48 +0000 Subject: [PATCH] Removed ConverterInfo and simplified ConverterRegistry git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269088 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/modules/core/RegisterConverter.java | 9 ++-- .../components/converter/ConverterInfo.java | 48 ------------------- .../converter/ConverterRegistry.java | 9 ++-- .../converter/DefaultConverterRegistry.java | 11 ++--- .../converter/DefaultMasterConverter.java | 9 ++-- .../deployer/DefaultTskDeployer.java | 22 ++------- 6 files changed, 22 insertions(+), 86 deletions(-) delete mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterInfo.java diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java index c4dbd601a..3700d6f6b 100644 --- a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java @@ -15,7 +15,6 @@ 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.ConverterInfo; import org.apache.myrmidon.components.converter.ConverterRegistry; import org.apache.myrmidon.components.deployer.DeploymentException; import org.apache.myrmidon.components.deployer.TskDeployer; @@ -110,13 +109,11 @@ public class RegisterConverter } else { - final ConverterInfo info = new ConverterInfo( m_sourceType, m_destinationType ); - m_converterRegistry.registerConverterInfo( m_classname, info ); - - final DefaultComponentFactory factory = - new DefaultComponentFactory( new URL[] { url } ); + m_converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType ); + 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 ) { diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterInfo.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterInfo.java deleted file mode 100644 index 17f16b373..000000000 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterInfo.java +++ /dev/null @@ -1,48 +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.myrmidon.components.converter; - -/** - * This info represents meta-information about a converter. - * - * @author Peter Donald - */ -public class ConverterInfo -{ - private final String m_source; - private final String m_destination; - - public ConverterInfo( final String source, final String destination ) - { - m_source = source; - m_destination = destination; - } - - /** - * Retrieve the source type from which it can convert. - * NB: Should this be an array ???? - * - * @return the classname from which object produced - */ - public String getSource() - { - return m_source; - } - - /** - * Retrieve the type to which the converter converts. - * NB: Should this be an array ???? - * - * @return the classname of the produced object - */ - public String getDestination() - { - return m_destination; - } -} - diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterRegistry.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterRegistry.java index 0c28a4c61..fffbc618d 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterRegistry.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/ConverterRegistry.java @@ -27,13 +27,14 @@ public interface ConverterRegistry * @param destination the destination classname * @return the className of converter or null if none available */ - String getConverterInfoName( String source, String destination ); + String getConverterName( String source, String destination ); /** - * Register a converter-info + * Register a converter * * @param className the className of converter - * @param info the ConverterInfo + * @param source the source classname + * @param destination the destination classname */ - void registerConverterInfo( String className, ConverterInfo info ); + void registerConverter( String className, String source, String destination ); } diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultConverterRegistry.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultConverterRegistry.java index 7415539a4..b2d0deff1 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultConverterRegistry.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultConverterRegistry.java @@ -10,7 +10,7 @@ package org.apache.myrmidon.components.converter; import java.util.HashMap; /** - * Default implementation of ConverterInfo registry. + * Default implementation of Converter registry. * * @author Peter Donald */ @@ -19,18 +19,17 @@ public class DefaultConverterRegistry { private final HashMap m_mapping = new HashMap(); - public String getConverterInfoName( final String source, final String destination ) + public String getConverterName( 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 ) + public void registerConverter( final String className, + final String source, + final String destination ) { - final String source = info.getSource(); - final String destination = info.getDestination(); - HashMap map = (HashMap)m_mapping.get( source ); if( null == map ) { diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java index cc11789b5..3081f1c9a 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java @@ -29,7 +29,7 @@ public class DefaultMasterConverter { private final static boolean DEBUG = false; - private ConverterRegistry m_infoRegistry; + private ConverterRegistry m_registry; private ComponentSelector m_selector; /** @@ -41,7 +41,7 @@ public class DefaultMasterConverter public void compose( final ComponentManager componentManager ) throws ComponentException { - m_infoRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); + m_registry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); m_selector = (ComponentSelector)typeManager.lookup( Converter.ROLE + "Selector" ); @@ -73,9 +73,8 @@ public class DefaultMasterConverter } //TODO: Start searching inheritance hierarchy for converter - final String name = - m_infoRegistry.getConverterInfoName( originalClass.getName(), - destination.getName() ); + final String name = m_registry.getConverterName( originalClass.getName(), + destination.getName() ); if( null == name ) { 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 e014ee872..cb2a7eaf1 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 @@ -26,7 +26,6 @@ import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.myrmidon.api.Task; import org.apache.myrmidon.api.DataType; -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.ComponentFactory; @@ -46,8 +45,8 @@ public class DefaultTskDeployer { private final static String TSKDEF_FILE = "TASK-LIB/taskdefs.xml"; - private DefaultConfigurationBuilder m_configurationBuilder; - private ConverterRegistry m_converterInfoRegistry; + private DefaultConfigurationBuilder m_configurationBuilder = new DefaultConfigurationBuilder(); + private ConverterRegistry m_converterRegistry; private TypeManager m_typeManager; /** @@ -68,7 +67,7 @@ public class DefaultTskDeployer public void compose( final ComponentManager componentManager ) throws ComponentException { - m_converterInfoRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); + m_converterRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); } @@ -245,16 +244,6 @@ public class DefaultTskDeployer } } - private DefaultConfigurationBuilder getBuilder() - { - if( null == m_configurationBuilder ) - { - m_configurationBuilder = new DefaultConfigurationBuilder(); - } - - return m_configurationBuilder; - } - /** * Retrieve zip file for file. * @@ -298,7 +287,7 @@ public class DefaultTskDeployer private Configuration buildConfiguration( final InputStream input ) throws DeploymentException { - try { return getBuilder().build( input ); } + try { return m_configurationBuilder.build( input ); } catch( final SAXException se ) { throw new DeploymentException( "Malformed configuration data", se ); @@ -354,8 +343,7 @@ public class DefaultTskDeployer final String source = converter.getAttribute( "source" ); final String destination = converter.getAttribute( "destination" ); - final ConverterInfo info = new ConverterInfo( source, destination ); - m_converterInfoRegistry.registerConverterInfo( name, info ); + m_converterRegistry.registerConverter( name, source, destination ); factory.addNameClassMapping( name, name ); m_typeManager.registerType( Converter.ROLE, name, factory );