ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type DefaultTypeFactory.java TypeException.java TypeFactory.java DefaultTypeManager.java TypeManager.java TypedComponentSelector.java ComponentFactory.java DefaultComponentFactory.java
Date Sun, 03 Jun 2001 05:31:18 GMT
donaldp     01/06/02 22:31:18

  Modified:    proposal/myrmidon/src/java/org/apache/ant/modules/core
                        RegisterConverter.java RegisterDataType.java
                        RegisterTasklet.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultTskDeployer.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        DefaultTypeManager.java TypeManager.java
                        TypedComponentSelector.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        DefaultTypeFactory.java TypeException.java
                        TypeFactory.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        ComponentFactory.java DefaultComponentFactory.java
  Log:
  Started converting runtime so type instances don't have to implement Avalons Component interface.
  
  Revision  Changes    Path
  1.13      +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java
  
  Index: RegisterConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RegisterConverter.java	2001/06/03 05:14:47	1.12
  +++ RegisterConverter.java	2001/06/03 05:31:16	1.13
  @@ -18,7 +18,7 @@
   import org.apache.myrmidon.components.converter.ConverterRegistry;
   import org.apache.myrmidon.components.deployer.DeploymentException;
   import org.apache.myrmidon.components.deployer.TskDeployer;
  -import org.apache.myrmidon.components.type.DefaultComponentFactory;
  +import org.apache.myrmidon.components.type.DefaultTypeFactory;
   import org.apache.myrmidon.components.type.TypeManager;
   import org.apache.myrmidon.converter.Converter;
   
  @@ -111,7 +111,7 @@
           {
               m_converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType
);
   
  -            final DefaultComponentFactory factory = new DefaultComponentFactory( new URL[]
{ url } );
  +            final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url
} );
               factory.addNameClassMapping( m_classname, m_classname );
   
               try { m_typeManager.registerType( Converter.ROLE, m_classname, factory ); }
  
  
  
  1.8       +2 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java
  
  Index: RegisterDataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RegisterDataType.java	2001/06/03 05:03:14	1.7
  +++ RegisterDataType.java	2001/06/03 05:31:17	1.8
  @@ -11,7 +11,7 @@
   import org.apache.myrmidon.api.DataType;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.components.deployer.DeploymentException;
  -import org.apache.myrmidon.components.type.DefaultComponentFactory;
  +import org.apache.myrmidon.components.type.DefaultTypeFactory;
   
   /**
    * Method to register a single datatype.
  @@ -36,8 +36,7 @@
           }
           else
           {
  -            final DefaultComponentFactory factory =
  -                new DefaultComponentFactory( new URL[] { url } );
  +            final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url
} );
               factory.addNameClassMapping( name, className );
               try { getTypeManager().registerType( DataType.ROLE, name, factory ); }
               catch( final Exception e )
  
  
  
  1.9       +2 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java
  
  Index: RegisterTasklet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RegisterTasklet.java	2001/06/03 05:03:14	1.8
  +++ RegisterTasklet.java	2001/06/03 05:31:17	1.9
  @@ -11,7 +11,7 @@
   import org.apache.myrmidon.api.Task;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.components.deployer.DeploymentException;
  -import org.apache.myrmidon.components.type.DefaultComponentFactory;
  +import org.apache.myrmidon.components.type.DefaultTypeFactory;
   
   /**
    * Method to register a single tasklet.
  @@ -36,8 +36,7 @@
           }
           else
           {
  -            final DefaultComponentFactory factory =
  -                new DefaultComponentFactory( new URL[] { url } );
  +            final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url
} );
               factory.addNameClassMapping( name, className );
               try { getTypeManager().registerType( Task.ROLE, name, factory ); }
               catch( final Exception e )
  
  
  
  1.10      +8 -14     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java
  
  Index: DefaultTskDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultTskDeployer.java	2001/06/03 05:14:48	1.9
  +++ DefaultTskDeployer.java	2001/06/03 05:31:17	1.10
  @@ -28,8 +28,7 @@
   import org.apache.myrmidon.api.DataType;
   import org.apache.myrmidon.components.converter.ConverterRegistry;
   import org.apache.myrmidon.components.executor.Executor;
  -import org.apache.myrmidon.components.type.ComponentFactory;
  -import org.apache.myrmidon.components.type.DefaultComponentFactory;
  +import org.apache.myrmidon.components.type.DefaultTypeFactory;
   import org.apache.myrmidon.components.type.TypeManager;
   import org.apache.myrmidon.converter.Converter;
   import org.xml.sax.SAXException;
  @@ -116,10 +115,8 @@
           throws DeploymentException
       {
           final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE );
  +        final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url } );
   
  -        final DefaultComponentFactory factory =
  -            new DefaultComponentFactory( new URL[] { url } );
  -
           try
           {
               final Configuration[] tasks = taskdefs.getChildren( "task" );
  @@ -164,8 +161,7 @@
               {
                   if( converters[ i ].getAttribute( "classname" ).equals( name ) )
                   {
  -                    final DefaultComponentFactory factory =
  -                        new DefaultComponentFactory( new URL[] { url } );
  +                    final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[]
{ url } );
                       handleConverter( converters[ i ], url, factory );
                       break;
                   }
  @@ -196,8 +192,7 @@
               {
                   if( datatypes[ i ].getAttribute( "name" ).equals( name ) )
                   {
  -                    final DefaultComponentFactory factory =
  -                        new DefaultComponentFactory( new URL[] { url } );
  +                    final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[]
{ url } );
                       handleDataType( datatypes[ i ], url, factory );
                       break;
                   }
  @@ -227,8 +222,7 @@
               {
                   if( tasks[ i ].getAttribute( "name" ).equals( name ) )
                   {
  -                    final DefaultComponentFactory factory =
  -                        new DefaultComponentFactory( new URL[] { url } );
  +                    final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[]
{ url } );
                       handleTask( tasks[ i ], url, factory );
                       break;
                   }
  @@ -336,7 +330,7 @@
   
       private void handleConverter( final Configuration converter,
                                     final URL url,
  -                                  final DefaultComponentFactory factory )
  +                                  final DefaultTypeFactory factory )
           throws Exception
       {
           final String name = converter.getAttribute( "classname" );
  @@ -354,7 +348,7 @@
   
       private void handleTask( final Configuration task,
                                final URL url,
  -                             final DefaultComponentFactory factory )
  +                             final DefaultTypeFactory factory )
           throws Exception
       {
           final String name = task.getAttribute( "name" );
  @@ -369,7 +363,7 @@
   
       private void handleDataType( final Configuration datatype,
                                    final URL url,
  -                                 final DefaultComponentFactory factory )
  +                                 final DefaultTypeFactory factory )
           throws Exception
       {
           final String name = datatype.getAttribute( "name" );
  
  
  
  1.4       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java
  
  Index: DefaultTypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultTypeManager.java	2001/06/02 08:26:54	1.3
  +++ DefaultTypeManager.java	2001/06/03 05:31:17	1.4
  @@ -56,7 +56,7 @@
   
       public void registerType( final String role, 
                                 final String shorthandName, 
  -                              final ComponentFactory factory ) 
  +                              final TypeFactory factory ) 
           throws Exception
       {
           final TypedComponentSelector selector = createSelector( role + "Selector" );
  
  
  
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TypeManager.java	2001/06/02 06:58:12	1.2
  +++ TypeManager.java	2001/06/03 05:31:17	1.3
  @@ -20,6 +20,6 @@
   {
       String ROLE = "org.apache.myrmidon.components.type.TypeManager";
   
  -    void registerType( String role, String shorthandName, ComponentFactory factory )
  +    void registerType( String role, String shorthandName, TypeFactory factory )
           throws Exception;
   }
  
  
  
  1.4       +7 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypedComponentSelector.java
  
  Index: TypedComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypedComponentSelector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypedComponentSelector.java	2001/06/02 08:26:54	1.3
  +++ TypedComponentSelector.java	2001/06/03 05:31:17	1.4
  @@ -90,7 +90,7 @@
       /**
        * Populate the ComponentSelector.
        */
  -    public void register( final String name, final ComponentFactory factory )
  +    public void register( final String name, final TypeFactory factory )
       {
           m_factorys.put( name, factory );
       }
  @@ -114,12 +114,16 @@
       private Component createComponent( final String name )
           throws ComponentException
       {
  -        final ComponentFactory factory = (ComponentFactory)m_factorys.get( name );
  +        final TypeFactory factory = (TypeFactory)m_factorys.get( name );
           
           if( null == factory ) return null;
           else
           {
  -            return factory.create( name );
  +            try { return (Component)factory.create( name ); }
  +            catch( final TypeException te )
  +            {
  +                throw new ComponentException( "Failed to create type " + name, te );
  +            }
           }
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeFactory.java
  
  Index: DefaultTypeFactory.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 file.
   */
  package org.apache.myrmidon.components.type;
  
  import java.net.URL;
  import java.util.HashMap;
  import java.net.URLClassLoader;
  
  /**
   * Create a type instance based on name.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/06/03 05:31:17 $
   */
  public class DefaultTypeFactory
      implements TypeFactory
  {
      ///A Map of shortnames to classnames
      private final HashMap        m_classNames = new HashMap();
  
      ///A list of URLs from which classLoader is constructed
      private final URL[]          m_urls;
  
      ///The parent classLoader (if any)
      private final ClassLoader    m_parent;
  
      ///The parent classLoader (if any)
      private ClassLoader          m_classLoader;
  
      public DefaultTypeFactory( final URL[] urls )
      {
          this( urls, Thread.currentThread().getContextClassLoader() );
      }
  
      public DefaultTypeFactory( final URL[] urls, final ClassLoader parent )
      {
          m_urls = urls;
          m_parent = parent;
      }
  
      public DefaultTypeFactory( final ClassLoader classLoader )
      {
          this( null, null );
          m_classLoader = classLoader;
      }
  
      public void addNameClassMapping( final String name, final String className )
      {
          m_classNames.put( name, className );
      }
  
      /**
       * Create a type instance with appropriate name.
       *
       * @param name the name
       * @return the created instance
       * @exception TypeException if an error occurs
       */
      public Object create( final String name )
          throws TypeException
      {
          final String className = getClassName( name );
  
          try
          {
              return getClassLoader().loadClass( className ).newInstance();
          }
          catch( final Exception e )
          {
              throw new TypeException( "Unable to instantiate '" + name + "'", e );
          }
      }
  
      private String getClassName( final String name )
          throws TypeException
      {
          final String className = (String)m_classNames.get( name );
  
          if( null == className )
          {
              throw new TypeException( "Malconfigured factory, no clasname for '" + 
                                       name + "'" );
          }
          
          return className;
      }
  
      private ClassLoader getClassLoader()
      {
          if( null == m_classLoader )
          {
              m_classLoader = new URLClassLoader( m_urls, m_parent );
          }
          
          return m_classLoader;
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeException.java
  
  Index: TypeException.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 file.
   */
  package org.apache.myrmidon.components.type;
  
  import org.apache.avalon.framework.CascadingException;
  
  /**
   * Exception to indicate problem with type instantiating.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public final class TypeException
      extends CascadingException
  {
      /**
       * Construct a new <code>TypeException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public TypeException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>TypeException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public TypeException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeFactory.java
  
  Index: TypeFactory.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 file.
   */
  package org.apache.myrmidon.components.type;
  
  /**
   * Create a component based on role and hint.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/06/03 05:31:17 $
   */
  public interface TypeFactory
  {
      /**
       * Create a Component with appropriate name.
       *
       * @param name the name
       * @return the created component
       * @exception ComponentException if an error occurs
       */
      Object create( String name )
          throws TypeException;
  }
  
  
  

Mime
View raw message