From c171b4c9f2bf641be687e7d5edb9456d4ecd3930 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Fri, 25 Jan 2002 11:27:21 +0000 Subject: [PATCH] Update to use new getService() method for retrienving sertvices Submitted By: "Adam Murdoch" git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270852 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/antlib/runtime/ConverterDef.java | 19 +++------- .../org/apache/antlib/runtime/Facility.java | 35 +++---------------- .../org/apache/antlib/runtime/Import.java | 14 ++------ .../antlib/runtime/Resources.properties | 1 - 4 files changed, 11 insertions(+), 58 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java b/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java index f771a54f2..69cadb2cd 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java @@ -11,9 +11,6 @@ import java.io.File; import java.net.URL; import org.apache.avalon.excalibur.i18n.ResourceManager; 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.TaskException; import org.apache.myrmidon.converter.Converter; @@ -28,7 +25,6 @@ import org.apache.myrmidon.interfaces.type.TypeManager; */ public class ConverterDef extends AbstractTask - implements Composable { private final static Resources REZ = ResourceManager.getPackageResources( ConverterDef.class ); @@ -37,15 +33,6 @@ public class ConverterDef private String m_destinationType; private File m_lib; private String m_classname; - private ConverterRegistry m_converterRegistry; - private TypeManager m_typeManager; - - public void compose( final ComponentManager componentManager ) - throws ComponentException - { - m_converterRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE ); - m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); - } public void setLib( final File lib ) { @@ -93,13 +80,15 @@ public class ConverterDef try { - m_converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType ); + final ConverterRegistry converterRegistry = (ConverterRegistry)getService( ConverterRegistry.class ); + converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType ); final URL url = m_lib.toURL(); final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[]{url} ); factory.addNameClassMapping( m_classname, m_classname ); - m_typeManager.registerType( Converter.ROLE, m_classname, factory ); + final TypeManager typeManager = (TypeManager)getService( TypeManager.class ); + typeManager.registerType( Converter.ROLE, m_classname, factory ); } catch( final Exception e ) { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java index 4bac1688c..1c0033520 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java @@ -9,9 +9,6 @@ package org.apache.antlib.runtime; import org.apache.avalon.excalibur.i18n.ResourceManager; 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.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -19,9 +16,7 @@ import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.aspects.AspectHandler; import org.apache.myrmidon.framework.AbstractContainerTask; import org.apache.myrmidon.interfaces.aspect.AspectManager; -import org.apache.myrmidon.interfaces.type.TypeException; import org.apache.myrmidon.interfaces.type.TypeFactory; -import org.apache.myrmidon.interfaces.type.TypeManager; /** * Task that definesMethod to register a single converter. @@ -30,7 +25,7 @@ import org.apache.myrmidon.interfaces.type.TypeManager; */ public class Facility extends AbstractContainerTask - implements Composable, Configurable + implements Configurable { private final static Resources REZ = ResourceManager.getPackageResources( Facility.class ); @@ -38,28 +33,6 @@ public class Facility private String m_namespace; private AspectHandler m_aspectHandler; - private AspectManager m_aspectManager; - private TypeFactory m_factory; - - public void compose( final ComponentManager componentManager ) - throws ComponentException - { - super.compose( componentManager ); - - m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE ); - - final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); - try - { - m_factory = typeManager.getFactory( AspectHandler.ROLE ); - } - catch( final TypeException te ) - { - final String message = REZ.getString( "facility.no-factory.error" ); - throw new ComponentException( message, te ); - } - } - public void configure( final Configuration configuration ) throws ConfigurationException { @@ -77,7 +50,8 @@ public class Facility { try { - m_aspectHandler = (AspectHandler)m_factory.create( children[ 0 ].getName() ); + final TypeFactory typeFactory = getTypeFactory( AspectHandler.ROLE ); + m_aspectHandler = (AspectHandler)typeFactory.create( children[ 0 ].getName() ); } catch( final Exception e ) { @@ -109,6 +83,7 @@ public class Facility throw new TaskException( message ); } - m_aspectManager.addAspectHandler( m_namespace, m_aspectHandler ); + final AspectManager aspectManager = (AspectManager)getService( AspectManager.class ); + aspectManager.addAspectHandler( m_namespace, m_aspectHandler ); } } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Import.java b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Import.java index 0dc46aca3..ba9cfba03 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Import.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Import.java @@ -10,9 +10,6 @@ package org.apache.antlib.runtime; import java.io.File; import org.apache.avalon.excalibur.i18n.ResourceManager; 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.TaskException; import org.apache.myrmidon.interfaces.deployer.Deployer; @@ -25,19 +22,11 @@ import org.apache.myrmidon.interfaces.deployer.DeploymentException; */ public class Import extends AbstractTask - implements Composable { private final static Resources REZ = ResourceManager.getPackageResources( Import.class ); private File m_lib; - private Deployer m_deployer; - - public void compose( final ComponentManager componentManager ) - throws ComponentException - { - m_deployer = (Deployer)componentManager.lookup( Deployer.ROLE ); - } public void setLib( final File lib ) { @@ -55,7 +44,8 @@ public class Import try { - m_deployer.deploy( m_lib ); + final Deployer deployer = (Deployer)getService( Deployer.class ); + deployer.deploy( m_lib ); } catch( final DeploymentException de ) { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties index 6acc6dd25..4bc1233e9 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties @@ -4,7 +4,6 @@ converterdef.no-destination.error=Must specify the destination-type parameter. converterdef.no-lib.error=Must specify the lib parameter. converterdef.no-register.error=Failed to register converter {0}. -facility.no-factory.error=Unable to retrieve AspectHandler factory from TypeManager. facility.no-create.error=Failed to create aspect handler of type {0}. facility.multi-element.error=Expected one sub-element to configure facility. facility.no-namespace.error=Must specify namespace parameter.