ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/property DefaultPropertyResolver.java
Date Thu, 21 Mar 2002 10:29:15 GMT
adammurdoch    02/03/21 02:29:15

  Modified:    proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        AbstractComponentTest.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/test
                        DefaultConfigurerTestCase.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/test
                        DefaultDeployerTestCase.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/property/test
                        AbstractPropertyResolverTestCase.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/property
                        DefaultPropertyResolver.java
  Added:       proposal/myrmidon/src/java/org/apache/antlib/core
                        ObjectToStringConverter.java
  Log:
  * Changed DefaultPropertyResolver to use the converter to convert from Object -> String.
  
  * Added general purpose Object -> String converter that simply uses Object.toString().
  
  * Reorganised AbstractComponentTestCase, to give sub-classes the opportunity to replace
    the default implementation of a component, with a particular implementation.
  
  Revision  Changes    Path
  1.17      +19 -9     jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractComponentTest.java	15 Mar 2002 02:48:21 -0000	1.16
  +++ AbstractComponentTest.java	21 Mar 2002 10:29:15 -0000	1.17
  @@ -73,27 +73,27 @@
               m_serviceManager = new DefaultServiceManager();
               List components = new ArrayList();
   
  -            Object component = new DefaultMasterConverter();
  +            Object component = createComponent( Converter.ROLE, DefaultMasterConverter.class
);
               m_serviceManager.put( Converter.ROLE, component );
               components.add( component );
   
  -            component = new DefaultConverterRegistry();
  +            component = createComponent( ConverterRegistry.ROLE, DefaultConverterRegistry.class
);
               m_serviceManager.put( ConverterRegistry.ROLE, component );
               components.add( component );
   
  -            component = new DefaultTypeManager();
  +            component = createComponent( TypeManager.ROLE, DefaultTypeManager.class );
               m_serviceManager.put( TypeManager.ROLE, component );
               components.add( component );
   
  -            component = new DefaultConfigurer();
  +            component = createComponent( Configurer.ROLE, DefaultConfigurer.class );
               m_serviceManager.put( Configurer.ROLE, component );
               components.add( component );
   
  -            component = new DefaultDeployer();
  +            component = createComponent( Deployer.ROLE, DefaultDeployer.class );
               m_serviceManager.put( Deployer.ROLE, component );
               components.add( component );
   
  -            component = new DefaultExecutor();
  +            component = createComponent( Executor.ROLE, DefaultExecutor.class );
               m_serviceManager.put( Executor.ROLE, component );
               components.add( component );
   
  @@ -102,15 +102,15 @@
               m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr );
               components.add( classLoaderMgr );
   
  -            component = new DefaultExtensionManager();
  +            component = createComponent( ExtensionManager.ROLE, DefaultExtensionManager.class
);
               m_serviceManager.put( ExtensionManager.ROLE, component );
               components.add( component );
   
  -            component = new DefaultRoleManager();
  +            component = createComponent( RoleManager.ROLE, DefaultRoleManager.class );
               m_serviceManager.put( RoleManager.ROLE, component );
               components.add( component );
   
  -            component = new DefaultPropertyResolver();
  +            component = createComponent( PropertyResolver.ROLE, DefaultPropertyResolver.class
);
               m_serviceManager.put( PropertyResolver.ROLE, component );
               components.add( component );
   
  @@ -145,6 +145,16 @@
           }
   
           return m_serviceManager;
  +    }
  +
  +    /**
  +     * Creates an instance of a component.  Sub-classes can override this
  +     * method to add a particular implementation to the set of test components.
  +     */
  +    protected Object createComponent( final String role, final Class defaultImpl )
  +        throws Exception
  +    {
  +        return defaultImpl.newInstance();
       }
   
       /**
  
  
  
  1.3       +19 -1     jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/test/DefaultConfigurerTestCase.java
  
  Index: DefaultConfigurerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/test/DefaultConfigurerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultConfigurerTestCase.java	19 Mar 2002 11:19:24 -0000	1.2
  +++ DefaultConfigurerTestCase.java	21 Mar 2002 10:29:15 -0000	1.3
  @@ -15,6 +15,7 @@
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.components.AbstractComponentTest;
  +import org.apache.myrmidon.components.configurer.DefaultConfigurer;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestAttributeConvert;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestConfigAdder;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestContent;
  @@ -30,6 +31,7 @@
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceAttribute;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceConversion;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestReferenceElement;
  +import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAndAdd;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAttribute;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetElement;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdder;
  @@ -38,7 +40,6 @@
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedAdderRole;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestTypedConfigAdder;
   import org.apache.myrmidon.components.configurer.test.data.ConfigTestUnknownReference;
  -import org.apache.myrmidon.components.configurer.test.data.ConfigTestSetAndAdd;
   import org.apache.myrmidon.components.workspace.DefaultTaskContext;
   import org.apache.myrmidon.framework.DataType;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
  @@ -78,6 +79,23 @@
           m_context = new DefaultTaskContext( null, getServiceManager(), getLogger() );
           final File baseDir = new File( "." ).getAbsoluteFile();
           m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
  +    }
  +
  +    /**
  +     * Creates an instance of a component.  Sub-classes can override this
  +     * method to add a particular implementation to the set of test components.
  +     */
  +    protected Object createComponent( final String role, final Class defaultImpl )
  +        throws Exception
  +    {
  +        if( role.equals( Configurer.ROLE) )
  +        {
  +            return new DefaultConfigurer();
  +        }
  +        else
  +        {
  +            return super.createComponent( role, defaultImpl );
  +        }
       }
   
       /**
  
  
  
  1.2       +18 -0     jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/test/DefaultDeployerTestCase.java
  
  Index: DefaultDeployerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/test/DefaultDeployerTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultDeployerTestCase.java	17 Mar 2002 08:07:09 -0000	1.1
  +++ DefaultDeployerTestCase.java	21 Mar 2002 10:29:15 -0000	1.2
  @@ -11,6 +11,7 @@
   import org.apache.aut.converter.Converter;
   import org.apache.aut.converter.ConverterException;
   import org.apache.myrmidon.components.AbstractComponentTest;
  +import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.framework.DataType;
   import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  @@ -46,6 +47,23 @@
           super.setUp();
           m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE );
           m_converter = (Converter)getServiceManager().lookup( Converter.ROLE );
  +    }
  +
  +    /**
  +     * Creates an instance of a component.  Sub-classes can override this
  +     * method to add a particular implementation to the set of test components.
  +     */
  +    protected Object createComponent( final String role, final Class defaultImpl )
  +        throws Exception
  +    {
  +        if( role.equals( Deployer.ROLE) )
  +        {
  +            return new DefaultDeployer();
  +        }
  +        else
  +        {
  +            return super.createComponent( role, defaultImpl );
  +        }
       }
   
       /**
  
  
  
  1.3       +27 -7     jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java
  
  Index: AbstractPropertyResolverTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/property/test/AbstractPropertyResolverTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractPropertyResolverTestCase.java	20 Mar 2002 22:30:55 -0000	1.2
  +++ AbstractPropertyResolverTestCase.java	21 Mar 2002 10:29:15 -0000	1.3
  @@ -9,10 +9,11 @@
   
   import java.io.File;
   import java.util.Date;
  +import org.apache.antlib.core.ObjectToStringConverter;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.myrmidon.AbstractMyrmidonTest;
  -import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.components.AbstractComponentTest;
   import org.apache.myrmidon.components.workspace.DefaultTaskContext;
   import org.apache.myrmidon.interfaces.property.PropertyResolver;
   
  @@ -20,28 +21,47 @@
    * General-purpose property resolver test cases.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.2 $ $Date: 2002/03/20 22:30:55 $
  + * @version $Revision: 1.3 $ $Date: 2002/03/21 10:29:15 $
    */
   public abstract class AbstractPropertyResolverTestCase
  -    extends AbstractMyrmidonTest
  +    extends AbstractComponentTest
   {
       protected final static Resources REZ = getResourcesForTested( AbstractPropertyResolverTestCase.class
);
   
       protected PropertyResolver m_resolver;
       protected DefaultTaskContext m_context;
   
  -    public AbstractPropertyResolverTestCase( String name )
  +    public AbstractPropertyResolverTestCase( final String name )
       {
           super( name );
       }
   
       protected void setUp() throws Exception
       {
  -        m_resolver = createResolver();
  +        m_resolver = (PropertyResolver)getServiceManager().lookup( PropertyResolver.ROLE
);
   
           m_context = new DefaultTaskContext( null, null, getLogger() );
           m_context.setProperty( "intProp", new Integer( 333 ) );
           m_context.setProperty( "stringProp", "String property" );
  +
  +        registerConverter( ObjectToStringConverter.class, Object.class, String.class );
  +    }
  +
  +    /**
  +     * Creates an instance of a component.  Sub-classes can override this
  +     * method to add a particular implementation to the set of test components.
  +     */
  +    protected Object createComponent( String role, Class defaultImpl )
  +        throws Exception
  +    {
  +        if( role.equals( PropertyResolver.ROLE) )
  +        {
  +            return createResolver();
  +        }
  +        else
  +        {
  +            return super.createComponent( role, defaultImpl );
  +        }
       }
   
       /**
  @@ -65,7 +85,7 @@
       /**
        * Simple tests with property on it's own, and accompanied by text.
        */
  -    private void testPropertyValue( Object propObject )
  +    private void testPropertyValue( final Object propObject )
           throws Exception
       {
           m_context.setProperty( "typedProp", propObject );
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/ObjectToStringConverter.java
  
  Index: ObjectToStringConverter.java
  ===================================================================
  /*
   * 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.txt file.
   */
  package org.apache.antlib.core;
  
  import org.apache.aut.converter.AbstractConverter;
  import org.apache.aut.converter.ConverterException;
  
  /**
   * A general-purpose converter that converts an Object to a String using
   * its toString() method.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/03/21 10:29:15 $
   *
   * @ant:converter source="java.lang.Object" destination="java.lang.String"
   */
  public class ObjectToStringConverter
      extends AbstractConverter
  {
      public ObjectToStringConverter()
      {
          super( Object.class, String.class );
      }
  
      /**
       * Converts an object.
       */
      protected Object convert( final Object original, final Object context )
          throws ConverterException
      {
          return original.toString();
      }
  }
  
  
  
  1.4       +41 -7     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java
  
  Index: DefaultPropertyResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/property/DefaultPropertyResolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultPropertyResolver.java	20 Mar 2002 22:30:55 -0000	1.3
  +++ DefaultPropertyResolver.java	21 Mar 2002 10:29:15 -0000	1.4
  @@ -7,10 +7,15 @@
    */
   package org.apache.myrmidon.components.property;
   
  +import org.apache.aut.converter.Converter;
  +import org.apache.aut.converter.ConverterException;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.myrmidon.api.TaskException;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.Serviceable;
   import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.property.PropertyResolver;
   
   /**
  @@ -18,14 +23,21 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.3 $ $Date: 2002/03/20 22:30:55 $
  + * @version $Revision: 1.4 $ $Date: 2002/03/21 10:29:15 $
    */
   public class DefaultPropertyResolver
  -    implements PropertyResolver
  +    implements PropertyResolver, Serviceable
   {
       private final static Resources REZ =
           ResourceManager.getPackageResources( DefaultPropertyResolver.class );
   
  +    private Converter m_converter;
  +
  +    public void service( final ServiceManager serviceManager ) throws ServiceException
  +    {
  +        m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
  +    }
  +
       /**
        * Resolve a string property. This evaluates all property
        * substitutions based on specified context.
  @@ -66,9 +78,9 @@
   
           while( true )
           {
  -            final Object propertyValue =
  -                getPropertyValue( content.substring( start + 2, end ),
  -                                  context );
  +            final String propertyValue =
  +                getPropertyStringValue( content.substring( start + 2, end ),
  +                                        context );
   
               sb.append( content.substring( lastPlace, start ) );
               sb.append( propertyValue );
  @@ -127,7 +139,7 @@
           {
               final String propertyName = content.substring( start + 2, end );
               final Object key = recursiveResolveProperty( propertyName, context );
  -            final Object value = getPropertyValue( key.toString(), context );
  +            final String value = getPropertyStringValue( key.toString(), context );
   
               sb.append( content.substring( lastPlace, start ) );
               sb.append( value );
  @@ -226,6 +238,28 @@
   
           final String message = REZ.getString( "prop.mismatched-braces.error" );
           throw new TaskException( message );
  +    }
  +
  +    /**
  +     * Returns a property's value, converted to a String.
  +     */
  +    private String getPropertyStringValue( final String propertyName,
  +                                           final TaskContext context )
  +        throws TaskException
  +    {
  +        final Object value = getPropertyValue( propertyName, context );
  +        if( value instanceof String )
  +        {
  +            return (String)value;
  +        }
  +        try
  +        {
  +            return (String)m_converter.convert( String.class, value, context );
  +        }
  +        catch( final ConverterException e )
  +        {
  +            throw new TaskException( e.getMessage(), e );
  +        }
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message