donaldp     2002/07/15 17:15:59

  Modified:    converter/src/java/org/apache/excalibur/converter/lib
                        Resources.properties SimpleMasterConverter.java
  Added:       converter/src/java/org/apache/excalibur/converter/lib
                        StringToBigDecimalConverter.java
                        StringToBigIntegerConverter.java
                        StringToTimeConverter.java
                        StringToTimestampConverter.java
  Log:
  Add a few more converters to lib
  
  Revision  Changes    Path
  1.2       +4 -0      
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties      27 Apr 2002 05:23:01 -0000      1.1
  +++ Resources.properties      16 Jul 2002 00:15:59 -0000      1.2
  @@ -7,3 +7,7 @@
   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.
  +convert.bad-bigdecimal.error=Error converting object ({0}) to BigDecimal.
  +convert.bad-biginteger.error=Error converting object ({0}) to BigInteger.
  +convert.bad-time.error=Error converting object ({0}) to Time.
  +convert.bad-timestamp.error=Error converting object ({0}) to Timestamp.
  
  
  
  1.3       +13 -1     
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/SimpleMasterConverter.java
  
  Index: SimpleMasterConverter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/SimpleMasterConverter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleMasterConverter.java        9 Jun 2002 05:12:38 -0000       1.2
  +++ SimpleMasterConverter.java        16 Jul 2002 00:15:59 -0000      1.3
  @@ -58,5 +58,17 @@
           registerConverter( new SimpleConverterFactory( StringToDateConverter.class 
),
                              "java.lang.String",
                              "java.util.Date" );
  +        registerConverter( new SimpleConverterFactory( 
StringToBigDecimalConverter.class ),
  +                           "java.lang.String",
  +                           "java.math.BigDecimal" );
  +        registerConverter( new SimpleConverterFactory( 
StringToBigIntegerConverter.class ),
  +                           "java.lang.String",
  +                           "java.math.BigInteger" );
  +        registerConverter( new SimpleConverterFactory( StringToTimeConverter.class 
),
  +                           "java.lang.String",
  +                           "java.sql.Time" );
  +        registerConverter( new SimpleConverterFactory( 
StringToTimestampConverter.class ),
  +                           "java.lang.String",
  +                           "java.sql.Timestamp" );
       }
   }
  
  
  
  1.1                  
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/StringToBigDecimalConverter.java
  
  Index: StringToBigDecimalConverter.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.excalibur.converter.lib;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.converter.AbstractConverter;
  import org.apache.excalibur.converter.ConverterException;
  import java.math.BigDecimal;
  
  /**
   * String to {@link BigDecimal} converter.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Donald</a>
   * @ant.converter source="java.lang.String" destination="java.math.BigDecimal"
   */
  public class StringToBigDecimalConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToBigDecimalConverter.class );
  
      /**
       * Construct the converter.
       */
      public StringToBigDecimalConverter()
      {
          super( String.class, BigDecimal.class );
      }
  
      /**
       * Converts a string to a BigDecimal.
       *
       * @param object the original object to convert
       * @param context the context in which to convert object (unused)
       * @return the converted object
       * @throws ConverterException if error converting object
       */
      public Object convert( final Object object, final Object context )
          throws ConverterException
      {
          try
          {
              return new BigDecimal( object.toString() );
          }
          catch( final NumberFormatException nfe )
          {
              final String message =
                  REZ.getString( "convert.bad-bigdecimal.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/StringToBigIntegerConverter.java
  
  Index: StringToBigIntegerConverter.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.excalibur.converter.lib;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.converter.AbstractConverter;
  import org.apache.excalibur.converter.ConverterException;
  import java.math.BigInteger;
  
  /**
   * String to {@link BigInteger} converter.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Donald</a>
   * @ant.converter source="java.lang.String" destination="java.math.BigInteger"
   */
  public class StringToBigIntegerConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToBigIntegerConverter.class );
  
      /**
       * Construct the converter.
       */
      public StringToBigIntegerConverter()
      {
          super( String.class, BigInteger.class );
      }
  
      /**
       * Converts a string to a BigInteger.
       *
       * @param object the original object to convert
       * @param context the context in which to convert object (unused)
       * @return the converted object
       * @throws ConverterException if error converting object
       */
      public Object convert( final Object object, final Object context )
          throws ConverterException
      {
          try
          {
              return new BigInteger( object.toString() );
          }
          catch( final NumberFormatException nfe )
          {
              final String message =
                  REZ.getString( "convert.bad-biginteger.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/StringToTimeConverter.java
  
  Index: StringToTimeConverter.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.excalibur.converter.lib;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.converter.AbstractConverter;
  import org.apache.excalibur.converter.ConverterException;
  import java.sql.Time;
  
  /**
   * String to {@link Time} converter.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Donald</a>
   * @ant.converter source="java.lang.String" destination="java.sql.Time"
   */
  public class StringToTimeConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToTimeConverter.class );
  
      /**
       * Construct the converter.
       */
      public StringToTimeConverter()
      {
          super( String.class, Time.class );
      }
  
      /**
       * Converts a string to a BigInteger.
       *
       * @param object the original object to convert
       * @param context the context in which to convert object (unused)
       * @return the converted object
       * @throws ConverterException if error converting object
       */
      public Object convert( final Object object, final Object context )
          throws ConverterException
      {
          try
          {
              return Time.valueOf( object.toString() );
          }
          catch( final NumberFormatException nfe )
          {
              final String message =
                  REZ.getString( "convert.bad-time.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  
  1.1                  
jakarta-avalon-excalibur/converter/src/java/org/apache/excalibur/converter/lib/StringToTimestampConverter.java
  
  Index: StringToTimestampConverter.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.excalibur.converter.lib;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.excalibur.converter.AbstractConverter;
  import org.apache.excalibur.converter.ConverterException;
  import java.sql.Timestamp;
  
  /**
   * String to {@link Timestamp} converter.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Peter Donald</a>
   * @ant.converter source="java.lang.String" destination="java.sql.Time"
   */
  public class StringToTimestampConverter
      extends AbstractConverter
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( StringToTimestampConverter.class );
  
      /**
       * Construct the converter.
       */
      public StringToTimestampConverter()
      {
          super( String.class, Timestamp.class );
      }
  
      /**
       * Converts a string to a Timestamp.
       *
       * @param object the original object to convert
       * @param context the context in which to convert object (unused)
       * @return the converted object
       * @throws ConverterException if error converting object
       */
      public Object convert( final Object object, final Object context )
          throws ConverterException
      {
          try
          {
              return Timestamp.valueOf( object.toString() );
          }
          catch( final NumberFormatException nfe )
          {
              final String message =
                  REZ.getString( "convert.bad-timestamp.error", object );
              throw new ConverterException( message, nfe );
          }
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to