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/main/org/apache/tools/ant/util/mappers Mapper.java MapperType.java
Date Sun, 13 Jan 2002 05:23:18 GMT
donaldp     02/01/12 21:23:18

  Added:       proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers
                        Mapper.java MapperType.java
  Log:
  Move Mapper adaptor and friends to mapper package
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/Mapper.java
  
  Index: Mapper.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.tools.ant.util.mappers;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.tools.ant.ProjectComponent;
  import org.apache.tools.ant.types.Path;
  
  /**
   * Element to define a FileNameMapper.
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
   */
  public class Mapper
      extends ProjectComponent
      implements Cloneable
  {
      private MapperType m_type;
      private String m_classname;
      private Path m_classpath;
      private String m_from;
      private String m_to;
  
      /**
       * Set the class name of the FileNameMapper to use.
       *
       * @param classname The new Classname value
       */
      public void setClassname( final String classname )
      {
          m_classname = classname;
      }
  
      /**
       * Set the classpath to load the FileNameMapper through (attribute).
       *
       * @param classpath The new Classpath value
       */
      public void setClasspath( Path classpath )
          throws TaskException
      {
          if( m_classpath == null )
          {
              m_classpath = classpath;
          }
          else
          {
              m_classpath.append( classpath );
          }
      }
  
      /**
       * Set the argument to FileNameMapper.setFrom
       */
      public void setFrom( final String from )
      {
          m_from = from;
      }
  
      /**
       * Set the argument to FileNameMapper.setTo
       */
      public void setTo( final String to )
      {
          m_to = to;
      }
  
      /**
       * Set the type of FileNameMapper to use.
       */
      public void setType( MapperType type )
      {
          m_type = type;
      }
  
      /**
       * Returns a fully configured FileNameMapper implementation.
       *
       * @return The Implementation value
       * @exception TaskException Description of Exception
       */
      public FileNameMapper getImplementation()
          throws TaskException
      {
          if( m_type == null && m_classname == null )
          {
              throw new TaskException( "one of the attributes type or classname is required"
);
          }
  
          if( m_type != null && m_classname != null )
          {
              throw new TaskException( "must not specify both type and classname attribute"
);
          }
  
          try
          {
              if( m_type != null )
              {
                  m_classname = m_type.getImplementation();
              }
  
              Class c = null;
              if( m_classpath == null )
              {
                  c = Class.forName( m_classname );
              }
              else
              {
                  final URL[] urls = m_classpath.toURLs();
                  final URLClassLoader classLoader = new URLClassLoader( urls );
                  c = classLoader.loadClass( m_classname );
              }
  
              FileNameMapper m = (FileNameMapper)c.newInstance();
              m.setFrom( m_from );
              m.setTo( m_to );
              return m;
          }
          catch( TaskException be )
          {
              throw be;
          }
          catch( Throwable t )
          {
              throw new TaskException( "Error", t );
          }
          finally
          {
              if( m_type != null )
              {
                  m_classname = null;
              }
          }
      }
  
      /**
       * Set the classpath to load the FileNameMapper through (nested element).
       *
       * @return Description of the Returned Value
       */
      public Path createClasspath()
          throws TaskException
      {
          if( m_classpath == null )
          {
              m_classpath = new Path();
          }
          return m_classpath.createPath();
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/util/mappers/MapperType.java
  
  Index: MapperType.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.tools.ant.util.mappers;
  
  import java.util.Properties;
  import org.apache.tools.ant.types.EnumeratedAttribute;
  
  /**
   * Class as Argument to FileNameMapper.setType.
   */
  public class MapperType
      extends EnumeratedAttribute
  {
      private final Properties c_implementations;
  
      public MapperType()
      {
          c_implementations = new Properties();
          c_implementations.put( "identity",
                                 "org.apache.tools.ant.util.IdentityMapper" );
          c_implementations.put( "flatten",
                                 "org.apache.tools.ant.util.FlatFileNameMapper" );
          c_implementations.put( "glob",
                                 "org.apache.tools.ant.util.GlobPatternMapper" );
          c_implementations.put( "merge",
                                 "org.apache.tools.ant.util.MergingMapper" );
          c_implementations.put( "regexp",
                                 "org.apache.tools.ant.util.RegexpPatternMapper" );
      }
  
      public String getImplementation()
      {
          return c_implementations.getProperty( getValue() );
      }
  
      public String[] getValues()
      {
          return new String[]{"identity", "flatten", "glob", "merge", "regexp"};
      }
  }
  
  
  

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