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/interfaces/type DefaultTypeFactory.java
Date Tue, 06 Nov 2001 08:04:40 GMT
donaldp     01/11/06 00:04:40

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/libs/ant1
                        Ant1TypeFactory.java
               proposal/myrmidon/src/java/org/apache/myrmidon/libs/runtime
                        ConverterDef.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/type
                        DefaultTypeFactory.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        DefaultTypeFactory.java
  Log:
  Move DefaultTypeFactory into interfaces hierarchy as it is used in many tasks.
  In the future a better abstraction should be found.
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/ant1/Ant1TypeFactory.java
  
  Index: Ant1TypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/ant1/Ant1TypeFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Ant1TypeFactory.java	2001/11/04 21:58:18	1.2
  +++ Ant1TypeFactory.java	2001/11/06 08:04:39	1.3
  @@ -8,7 +8,7 @@
   package org.apache.myrmidon.libs.ant1;
   
   import java.net.URL;
  -import org.apache.myrmidon.components.type.DefaultTypeFactory;
  +import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.tools.ant.Task;
   
  
  
  
  1.5       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/runtime/ConverterDef.java
  
  Index: ConverterDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/libs/runtime/ConverterDef.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConverterDef.java	2001/11/04 21:58:18	1.4
  +++ ConverterDef.java	2001/11/06 08:04:40	1.5
  @@ -18,7 +18,7 @@
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  -import org.apache.myrmidon.components.type.DefaultTypeFactory;
  +import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.converter.Converter;
   
  
  
  
  1.6       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultDeployer.java	2001/11/04 21:58:16	1.5
  +++ DefaultDeployer.java	2001/11/06 08:04:40	1.6
  @@ -25,7 +25,7 @@
   import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.myrmidon.api.Task;
  -import org.apache.myrmidon.components.type.DefaultTypeFactory;
  +import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.converter.Converter;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/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.interfaces.type;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.HashMap;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.interfaces.type.TypeException;
  import org.apache.myrmidon.interfaces.type.TypeFactory;
  
  /**
   * Create a type instance based on name.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/06 08:04:40 $
   */
  public class DefaultTypeFactory
      implements TypeFactory
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DefaultTypeFactory.class );
  
      ///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 url )
      {
          this( new URL[] { url } );
      }
  
      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 )
          {
              final String message = REZ.getString( "no-instantiate.error", name );
              throw new TypeException( message, e );
          }
      }
  
      private String getClassName( final String name )
          throws TypeException
      {
          final String className = (String)m_classNames.get( name );
  
          if( null == className )
          {
              final String message = REZ.getString( "no-mapping.error", name );
              throw new TypeException( message );
          }
  
          return className;
      }
  
      private ClassLoader getClassLoader()
      {
          if( null == m_classLoader )
          {
              m_classLoader = new URLClassLoader( m_urls, m_parent );
          }
  
          return m_classLoader;
      }
  }
  
  
  

--
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