You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2001/12/16 12:56:21 UTC

cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core Echo.java Property.java Resources.properties StringToByteConverter.java StringToClassConverter.java StringToDoubleConverter.java StringToFileConverter.java StringToFloatConverter.java StringToIntegerConverter.java StringToLongConverter.java StringToShortConverter.java StringToURLConverter.java

donaldp     01/12/16 03:56:21

  Added:       proposal/myrmidon/src/java/org/apache/antlib/core Echo.java
                        Property.java Resources.properties
                        StringToByteConverter.java
                        StringToClassConverter.java
                        StringToDoubleConverter.java
                        StringToFileConverter.java
                        StringToFloatConverter.java
                        StringToIntegerConverter.java
                        StringToLongConverter.java
                        StringToShortConverter.java
                        StringToURLConverter.java
  Log:
  Move core ant library into new package hierarchy
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Echo.java
  
  Index: Echo.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.antlib.core;
  
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * This is the echo task to display a message.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class Echo
      extends AbstractTask
  {
      private String      m_message;
  
      public void setMessage( final String message )
      {
          m_message = message;
      }
  
      public void execute()
          throws TaskException
      {
          getLogger().warn( m_message );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java
  
  Index: Property.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.antlib.core;
  
  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;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.interfaces.type.TypeException;
  import org.apache.myrmidon.interfaces.type.TypeFactory;
  import org.apache.myrmidon.interfaces.type.TypeManager;
  import org.apache.myrmidon.framework.AbstractContainerTask;
  import org.apache.myrmidon.framework.DataType;
  
  /**
   * This is the property "task" to declare a binding of a datatype to a name.
   *
   * TODO: Determine final format of property task.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class Property
      extends AbstractContainerTask
      implements Configurable
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( Property.class );
  
      private String              m_name;
      private Object              m_value;
      private boolean             m_localScope     = true;
      private TypeFactory         m_factory;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          super.compose( componentManager );
  
          final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
          try { m_factory = typeManager.getFactory( DataType.ROLE ); }
          catch( final TypeException te )
          {
              final String message = REZ.getString( "property.bad-factory.error" );
              throw new ComponentException( message, te );
          }
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final String[] attributes = configuration.getAttributeNames();
          for( int i = 0; i < attributes.length; i++ )
          {
              final String name = attributes[ i ];
              final String value = configuration.getAttribute( name );
              configure( this, name, value );
          }
  
          final Configuration[] children = configuration.getChildren();
          for( int i = 0; i < children.length; i++ )
          {
              try
              {
                  final DataType value = (DataType)m_factory.create( children[ i ].getName() );
                  configure( value, children[ i ] );
                  setValue( value );
              }
              catch( final Exception e )
              {
                  final String message = REZ.getString( "property.no-set.error" );
                  throw new ConfigurationException( message, e );
              }
          }
      }
  
      public void setName( final String name )
      {
          m_name = name;
      }
  
      public void setValue( final Object value )
          throws TaskException
      {
          if( null != m_value )
          {
              final String message = REZ.getString( "property.multi-set.error" );
              throw new TaskException( message );
          }
  
          m_value = value;
      }
  
      public void setLocalScope( final boolean localScope )
      {
          m_localScope = localScope;
      }
  
      public void execute()
          throws TaskException
      {
          if( null == m_name )
          {
              final String message = REZ.getString( "property.no-name.error" );
              throw new TaskException( message );
          }
  
          if( null == m_value )
          {
              final String message = REZ.getString( "property.no-value.error" );
              throw new TaskException( message );
          }
  
          if( m_localScope )
          {
              getContext().setProperty( m_name, m_value );
          }
          else
          {
              getContext().setProperty( m_name, m_value, TaskContext.PARENT );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  property.bad-factory.error=Unable to retrieve DataType factory from TypeManager.
  property.no-set.error=Unable to set datatype.
  property.multi-set.error=Value can not be set multiple times.
  property.no-name.error=Name must be specified.
  property.no-value.error=Value must be specified.
  
  convert.bad-byte.error=Error converting object ({0}) to Byte.
  convert.bad-class.error=Error converting object ({0}) to Class.
  convert.bad-double.error=Error converting object ({0}) to Double.
  convert.bad-file.error=Error converting object ({0}) to File.
  convert.bad-float.error=Error converting object ({0}) to Float.
  convert.bad-integer.error=Error converting object ({0}) to Integer.
  convert.bad-long.error=Error converting object ({0}) to Long.
  convert.bad-short.error=Error converting object ({0}) to Short.
  convert.bad-url.error=Error converting object ({0}) to URL.
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToByteConverter.java
  
  Index: StringToByteConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to byte converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToByteConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToByteConverter.class );
  
      public StringToByteConverter()
      {
          super( String.class, Byte.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Byte( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-byte.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToClassConverter.java
  
  Index: StringToClassConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to class converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToClassConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToClassConverter.class );
  
      public StringToClassConverter()
      {
          super( String.class, Class.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          //TODO: Should we use ContextClassLoader here???
          try { return Class.forName( (String)object ); }
          catch( final Exception e )
          {
              final String message = REZ.getString( "convert.bad-class.error", object );
              throw new ConverterException( message, e );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToDoubleConverter.java
  
  Index: StringToDoubleConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to double converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToDoubleConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToDoubleConverter.class );
  
      public StringToDoubleConverter()
      {
          super( String.class, Double.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Double( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-double.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToFileConverter.java
  
  Index: StringToFileConverter.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.antlib.core;
  
  import java.io.File;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to file converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToFileConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToFileConverter.class );
  
      public StringToFileConverter()
      {
          super( String.class, File.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try
          {
              final TaskContext taskContext = (TaskContext)context;
              return taskContext.resolveFile( (String)object );
          }
          catch( final TaskException te )
          {
              final String message = REZ.getString( "convert.bad-file.error", object );
              throw new ConverterException( message, te );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToFloatConverter.java
  
  Index: StringToFloatConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to float converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToFloatConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToFloatConverter.class );
  
      public StringToFloatConverter()
      {
          super( String.class, Float.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Float( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-float.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToIntegerConverter.java
  
  Index: StringToIntegerConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to integer converter.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToIntegerConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToFloatConverter.class );
  
      public StringToIntegerConverter()
      {
          super( String.class, Integer.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Integer( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-integer.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToLongConverter.java
  
  Index: StringToLongConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to long converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToLongConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToLongConverter.class );
  
      public StringToLongConverter()
      {
          super( String.class, Long.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Long( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-long.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToShortConverter.java
  
  Index: StringToShortConverter.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.antlib.core;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to short converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToShortConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToShortConverter.class );
  
      public StringToShortConverter()
      {
          super( String.class, Short.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new Short( (String)object ); }
          catch( final NumberFormatException nfe )
          {
              final String message = REZ.getString( "convert.bad-short.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/core/StringToURLConverter.java
  
  Index: StringToURLConverter.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.antlib.core;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.Context;
  import org.apache.myrmidon.converter.AbstractConverter;
  import org.apache.myrmidon.converter.ConverterException;
  
  /**
   * String to url converter
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class StringToURLConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToURLConverter.class );
  
      public StringToURLConverter()
      {
          super( String.class, URL.class );
      }
  
      public Object convert( final Object object, final Context context )
          throws ConverterException
      {
          try { return new URL( (String)object ); }
          catch( final MalformedURLException mue )
          {
              final String message = REZ.getString( "convert.bad-url.error", object );
              throw new ConverterException( message, mue );
          }
  
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>