commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion ObjectToStringConversionFactory.java StringToIntegerConversion.java AbstractConversionFactory.java TimeZoneToStringConversionFactory.java NumberToIntegerConversionFactory.java AbstractConversion.java IdentityConversionFactory.java DefaultValueDecorator.java ClassToStringConversion.java
Date Sat, 20 Mar 2004 19:17:34 GMT
scolebourne    2004/03/20 11:17:34

  Added:       convert/src/java/org/apache/commons/convert Conversion.java
                        ConversionFactory.java Converter.java
                        ConvertUtils.java ConversionException.java
                        ConversionRegistry.java
               convert/src/java/org/apache/commons/convert/conversion
                        ObjectToStringConversionFactory.java
                        StringToIntegerConversion.java
                        AbstractConversionFactory.java
                        TimeZoneToStringConversionFactory.java
                        NumberToIntegerConversionFactory.java
                        AbstractConversion.java
                        IdentityConversionFactory.java
                        DefaultValueDecorator.java
                        ClassToStringConversion.java
  Log:
  Rename convert2 to convert
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/Conversion.java
  
  Index: Conversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  /**
   * Defines a class that can convert one object to an object of another type.
   * <p>
   * All configuration data for the conversion must be set on the converter
   * separately.
   *
   * @author Stephen Colebourne
   * @version $Id: Conversion.java,v 1.1 2004/03/20 19:17:33 scolebourne Exp $
   * @since 1.0
   */
  public interface Conversion {
  
      /**
       * Convert the specified input object into an output object
       * of the another type.
       *
       * @param value  the value to be converted, read only, may be null
       * @param converter  the converter being used, not null
       * @throws Exception if conversion fails, use ConversionException if creating
       *  a new exception, otherwise just allow exceptions to be thrown
       */
      public Object convert(Object value, Converter converter) throws Exception;
  
      /**
       * The type to convert from.
       *
       * @return the Class object representing the class to convert to
       */
      public Class getFromType();
  
      /**
       * The type to convert to.
       *
       * @return the Class object representing the class to convert from
       */
      public Class getToType();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/ConversionFactory.java
  
  Index: ConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  /**
   * Defines a factory for Conversion objects that will create a conversion on demand
   * or return a singleton.
   *
   * @author Stephen Colebourne
   * @version $Id: ConversionFactory.java,v 1.1 2004/03/20 19:17:33 scolebourne Exp $
   * @since 1.0
   */
  public interface ConversionFactory {
  
      /**
       * Checks if this factory supports the required conversion returning a
       * percentage match.
       * <p>
       * The returned <code>int</code> represents the percentage by which this
       * factory matches the required conversion. The percentage (ie 0-100) is used
       * to determine which conversion factory to use when a conflict arises.
       * 
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  th type to convert to, may be null
       * @return a value between 0 and 100 inclusive, 0 means no match, 100 perfact match
       */
      public int getMatchPercent(Object value, Class fromType, Class toType);
  
      /**
       * Create a conversion object for the conversion.
       * <p>
       * The returned conversion must not store the value. The conversion object
       * will be used repeatedly for all future conversions between these two types
       * without further reference to the factory.
       *
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  th type to convert to, may be null
       * @return a Conversion object for repeatedly performing conversions
       */
      public Conversion getInstance(Object value, Class fromType, Class toType);
  
  }
  
  
  
  1.5       +149 -17   jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/Converter.java
  
  
  
  
  1.6       +101 -60   jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/ConvertUtils.java
  
  
  
  
  1.5       +26 -39    jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/ConversionException.java
  
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/ConversionRegistry.java
  
  Index: ConversionRegistry.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.convert.conversion.ClassToStringConversion;
  import org.apache.commons.convert.conversion.ObjectToStringConversionFactory;
  import org.apache.commons.convert.conversion.TimeZoneToStringConversionFactory;
  
  /**
   * ConversionRegistry manages the <code>Conversion</code> and
   * <code>ConversionFactory</code> objects.
   * <p>
   * This class allows conversions to be added, removed and looked up.
   * This implementation is fully synchronized.
   * <pre>
   * Converter converter = new Converter();
   * converter.getRegistry().addDefaultConversions();
   * converter.getRegistry().addConversion(new MyNewConversion());
   * </pre>
   *
   * @author Stephen Colebourne
   * @version $Id: ConversionRegistry.java,v 1.1 2004/03/20 19:17:33 scolebourne Exp $
   * @since 1.0
   */
  public class ConversionRegistry {
  
      /** Map of from class to conversion */
      protected Map iConversions = new HashMap();
      /** Array of conversion factories */
      protected ConversionFactory[] iFactories = new ConversionFactory[0];
      /** Object to synchronize on for factories */
      protected final Object iFactoryLock = new Object();
  
      /**
       * Restricted constructor, use Converter.
       */
      protected ConversionRegistry() {
          super();
      }
  
      //-----------------------------------------------------------------------
      /**
       * Add the default set of conversions to the registry.
       */
      public void addDefaultConversions() {
          synchronized (iConversions) {
              addConversion(ClassToStringConversion.INSTANCE);
          }
          synchronized (iFactoryLock) {
              addConversionFactory(ObjectToStringConversionFactory.INSTANCE);
              addConversionFactory(TimeZoneToStringConversionFactory.INSTANCE);
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Adds a Conversion to the map of known conversions.
       * Any previous conversion for this from-to pair is replaced.
       * 
       * @param conv  the conversion to add
       */
      public void addConversion(Conversion conv) {
          if (conv != null) {
              synchronized (iConversions) {
                  Map map = (Map) iConversions.get(conv.getFromType());
                  if (map == null) {
                      map = new HashMap();
                      iConversions.put(conv.getFromType(), map);
                  }
                  map.put(conv.getToType(), conv);
              }
          }
      }
  
      /**
       * Adds a ConversionFactory to the set of known factories.
       * Any previous factory that matches by <code>equals()</code> is replaced.
       * 
       * @param factory  the factory to add
       */
      public void addConversionFactory(ConversionFactory factory) {
          if (factory != null) {
              synchronized (iFactoryLock) {
                  ConversionFactory[] oldFactories = iFactories;
                  for (int i = 0; i < oldFactories.length; i++) {
                      if (oldFactories[i].equals(factory)) {
                          iFactories[i] = factory;
                          return;
                      }
                  }
                  ConversionFactory[] newFactories = new ConversionFactory[oldFactories.length + 1];
                  System.arraycopy(oldFactories, 0, newFactories, 0, oldFactories.length);
                  newFactories[oldFactories.length] = factory;
                  iFactories = newFactories;
              }
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Gets the conversion object that best matches the from and to types.
       * <p>
       * The lookup first examines the known conversions. If none is found, the
       * factories are used to search for and create a conversion. If no suitable
       * factory is found then <code>null</code> is returned.
       * 
       * @param fromType  the type to convert from
       * @param toType  the type to convert to
       * @return the best matching conversion, null if no match
       */
      public Conversion getConversion(Object value, Class fromType, Class toType) {
          // try known conversions
          synchronized (iConversions) {
              Map map = (Map) iConversions.get(fromType);
              if (map != null) {
                  Conversion conv = (Conversion) map.get(toType);
                  if (conv != null) {
                      return conv;
                  }
              }
          }
  
          // try factories
          int max = 0;
          ConversionFactory maxFactory = null;
          synchronized (iFactoryLock) {
              ConversionFactory[] factories = iFactories;
              for (int i = 0; i < factories.length; i++) {
                  int match = factories[i].getMatchPercent(value, fromType, toType);
                  if (match > max) {
                      max = match;
                      maxFactory = factories[i];
                  }
              }
          }
          if (maxFactory != null) {
              Conversion conv = maxFactory.getInstance(value, fromType, toType);
              addConversion(conv);
              return conv;
          }
  
          // no match
          return null;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Returns a string describing this object.
       *
       * @return a string describing this object
       */
      public String toString() {
          return "ConverterRegistry";
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/ObjectToStringConversionFactory.java
  
  Index: ObjectToStringConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from Object to String using <code>toString()</code>.
   *
   * @author Stephen Colebourne
   * @version $Id: ObjectToStringConversionFactory.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class ObjectToStringConversionFactory extends AbstractConversionFactory {
  
      /** Singleton instance of this factory */
      public static final ConversionFactory INSTANCE = new ObjectToStringConversionFactory();
  
      /**
       * Restricted constructor.
       */
      protected ObjectToStringConversionFactory() {
          super(Object.class, STRING_CLASS);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Returns a low match percent to allow other conversions to replace this one.
       * 
       * @return 20
       */
      protected int getMatchPercent() {
          return 20;
      }
  
      /**
       * Convert the specified input object into an output object
       * of the another type.
       *
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @return the converted value
       */
      protected Object convertValue(Object value, Converter converter) {
          return value.toString();
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/StringToIntegerConversion.java
  
  Index: StringToIntegerConversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from String to Integer using <code>Integer.valueOf()</code>.
   *
   * @author Stephen Colebourne
   * @author Oliver Heger
   * @version $Id: StringToIntegerConversion.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class StringToIntegerConversion extends AbstractConversion {
  
      /** Singleton instance of this factory */
      public static final Conversion INSTANCE = new StringToIntegerConversion();
  
      /**
       * Constructor.
       */
      protected StringToIntegerConversion() {
          super(STRING_CLASS, Integer.class);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Convert the non-null String to an Integer using <code>Integer.valueOf()</code>.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @return the converted value
       * @throws RuntimeException if conversion fails
       */
      protected Object convertValue(Object value, Converter converter) {
          return Integer.valueOf((String) value);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/AbstractConversionFactory.java
  
  Index: AbstractConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Abstract base class for creating conversion factories.
   * <p>
   * This class is especially suited for creating factories as it minimises the effort
   * required in the subclass.
   * <p>
   * To implement a conversion from a class and all of it subclasses, simply extend
   * this class and implement the {@link #convertValue(Object, Converter)} method.
   *
   * @author Stephen Colebourne
   * @author Oliver Heger
   * @version $Id: AbstractConversionFactory.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public abstract class AbstractConversionFactory implements ConversionFactory {
  
      /** Useful constant for subclass constructors */
      protected static final Class STRING_CLASS = String.class;
  
      /** The base type to convert from */
      private final Class baseFromType;
      /** The type to convert to */
      private final Class toType;
  
      /**
       * Restricted constructor.
       */
      protected AbstractConversionFactory(Class baseFromType, Class toType) {
          super();
          this.baseFromType = baseFromType;
          this.toType = toType;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Checks if this factory matches the request conversion.
       * <p>
       * This implementation returns {@link #getMatchPercent()} if the specified
       * <code>fromType</code> is the same as, or a subclass of, the stored
       * <code>baseFromType</code> and the specified <code>toType</code> matches
       * the stored <code>toType</code>.
       * 
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  th type to convert to, may be null
       * @return 60 if baseFromType or subclass matches fromType and toType matches
       */
      public int getMatchPercent(Object value, Class fromType, Class toType) {
          if (toType == getToType() && getBaseFromType().isAssignableFrom(fromType)) {
              return getMatchPercent();
          }
          return 0;
      }
  
      /**
       * Gets the percentage to return if a match occurs.
       * <p>
       * This implementation returns <code>60</code>.
       * Subclasses may wish to override and return a different value.
       * 
       * @return 60
       */
      protected int getMatchPercent() {
          return 60;
      }
  
      /**
       * Create a new conversion object for the specified from and to types.
       * <p>
       * This implementation returns a <code>Conversion</code> instance that
       * refers back to this class for its implementation of the actual conversion
       * via {@link #convertValue(Object, Converter)}.
       *
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  the type to convert to, may be null
       * @return a Conversion object for repeatedly performing conversions
       */
      public Conversion getInstance(Object value, Class fromType, Class toType) {
          return new FactoryConversion(fromType, toType, this);
      }
  
      /**
       * Convert the non-null value to another type.
       * <p>
       * This method is implemented by subclases to perform the actual conversion.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @throws Exception if conversion fails, use ConversionException if creating
       *  a new exception, otherwise just allow exceptions to be thrown
       */
      protected abstract Object convertValue(Object value, Converter converter);
  
      //-----------------------------------------------------------------------
      /**
       * The base type to convert from.
       * This type and its subclasses will be matched by this factory.
       *
       * @return the Class object representing the class to convert to
       */
      public Class getBaseFromType() {
          return baseFromType;
      }
  
      /**
       * The type to convert to.
       *
       * @return the Class object representing the class to convert from
       */
      public Class getToType() {
          return toType;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Gets a suitable debugging string.
       * 
       * @return a debugging string
       */
      public String toString() {
          String from = convertClassToName(getBaseFromType());
          String to = convertClassToName(getToType());
          return "ConversionFactory[" + from + "->" + to + "]";
      }
  
      /**
       * Converts a class to a string name for debugging.
       * 
       * @param cls  the class to convert
       * @return the class name
       */
      private String convertClassToName(Class cls) {
          if (cls == null) {
              return "null";
          }
          String str = cls.getName();
          int pos = str.lastIndexOf('.');
          if (str.substring(0, pos).equals("java.lang")) {
              str = str.substring(pos + 1);
          }
          if (str.substring(0, pos).equals("java.util")) {
              str = str.substring(pos + 1);
          }
          return str;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Generic conversion implementation that delegates back to the factory.
       */
      class FactoryConversion extends AbstractConversion {
  
          /** The factory instance that has the actual conversion code */
          private final AbstractConversionFactory factory;
  
          /**
           * Constructs a Conversion.
           * 
           * @param fromType  the type to convert from
           * @param toType  the type to convert to
           * @param factory  the factory instance that actually performs the conversion
           */
          FactoryConversion(Class fromType, Class toType, AbstractConversionFactory factory) {
              super(fromType, toType);
              this.factory = factory;
          }
  
          /**
           * Convert the non-null value to another type.
           * <p>
           * This implementation delegates to the factory method
           * {@link AbstractConversionFactory#convertValue(Object, Converter)}.
           * 
           * @param value  the input value to be converted, pre-checked to not be null
           * @param converter  the converter being used, not null
           * @throws Exception if conversion fails, use ConversionException if creating
           *  a new exception, otherwise just allow exceptions to be thrown
           */
          protected Object convertValue(Object value, Converter converter) {
              return factory.convertValue(value, converter);
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/TimeZoneToStringConversionFactory.java
  
  Index: TimeZoneToStringConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import java.util.TimeZone;
  
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from TimeZone to String using <code>getID()</code>.
   *
   * @author Stephen Colebourne
   * @version $Id: TimeZoneToStringConversionFactory.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class TimeZoneToStringConversionFactory extends AbstractConversionFactory {
  
      /** Singleton instance of this factory */
      public static final ConversionFactory INSTANCE = new TimeZoneToStringConversionFactory();
  
      /**
       * Restricted constructor.
       */
      protected TimeZoneToStringConversionFactory() {
          super(TimeZone.class, STRING_CLASS);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Convert the non-null TimeZone to a String using <code>getID()</code>.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @return the converted value
       */
      protected Object convertValue(Object value, Converter converter) {
          return ((TimeZone) value).getID();
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/NumberToIntegerConversionFactory.java
  
  Index: NumberToIntegerConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from Number to Integer using <code>intValue()</code>.
   *
   * @author Stephen Colebourne
   * @version $Id: NumberToIntegerConversionFactory.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class NumberToIntegerConversionFactory extends AbstractConversionFactory {
  
      /** Singleton instance of this factory */
      public static final ConversionFactory INSTANCE = new NumberToIntegerConversionFactory();
  
      /**
       * Restricted constructor.
       */
      protected NumberToIntegerConversionFactory() {
          super(Number.class, Integer.class);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Convert the non-null Number to an Integer using <code>intValue()</code>.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @return the converted value
       * @throws RuntimeException if conversion fails
       */
      protected Object convertValue(Object value, Converter converter) {
          return new Integer(((Number) value).intValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/AbstractConversion.java
  
  Index: AbstractConversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.Converter;
  
  /**
   * Abstract base class for conversion objects that provides basic features.
   * <p>
   * Most Conversion implementations will extend this class. It provides convenient
   * implementations of the methods of the interface, and simplifies null-handling
   * in the subclass.
   * <p>
   * To implement a conversion from a single class, simply extend this class and
   * implement the {@link #convert(Object, Converter)} method. To implement a 
   * conversion from a class and its subclasses, use {@link AbstractConversionFactory}.
   *
   * @author Stephen Colebourne
   * @version $Id: AbstractConversion.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public abstract class AbstractConversion implements Conversion {
  
      /** Useful constant for subclass constructors */
      protected static final Class STRING_CLASS = String.class;
  
      /** The type to convert from */
      private final Class fromType;
      /** The type to convert to */
      private final Class toType;
  
      /**
       * Constructor that stores the from and to types.
       * 
       * @param fromType  the type to convert from
       * @param toType  the type to convert to
       */
      protected AbstractConversion(Class fromType, Class toType) {
          super();
          this.fromType = fromType;
          this.toType = toType;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Converts an object from one type to another.
       * <p>
       * This implementation delegates to <code>convertValue</code> after handling null.
       * If the null-safe behaviour is undesired, override this method.
       *
       * @param value  the input value to be converted, may be null
       * @param converter  the converter being used, not null
       * @throws Exception if conversion fails, use ConversionException if creating
       *  a new exception, otherwise just allow exceptions to be thrown
       */
      public Object convert(Object value, Converter converter) throws Exception {
          if (value == null) {
              return null;
          }
          return convertValue(value, converter);
      }
  
      /**
       * Convert the specified non-null value to another type.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @throws Exception if conversion fails, use ConversionException if creating
       *  a new exception, otherwise just allow exceptions to be thrown
       */
      protected Object convertValue(Object value, Converter converter) {
          throw new UnsupportedOperationException("Not implemented");
      }
  
      //-----------------------------------------------------------------------
      /**
       * The type to convert from.
       *
       * @return the Class object representing the class to convert to
       */
      public Class getFromType() {
          return fromType;
      }
  
      /**
       * The type to convert to.
       *
       * @return the Class object representing the class to convert from
       */
      public Class getToType() {
          return toType;
      }
  
      //-----------------------------------------------------------------------
      /**
       * Gets a suitable debugging string.
       * 
       * @return a debugging string
       */
      public String toString() {
          String from = convertClassToName(getFromType());
          String to = convertClassToName(getToType());
          return "Conversion[" + from + "->" + to + "]";
      }
  
      /**
       * Converts a class to a string name for debugging.
       * 
       * @param cls  the class to convert
       * @return the class name
       */
      private String convertClassToName(Class cls) {
          if (cls == null) {
              return "null";
          }
          String str = cls.getName();
          int pos = str.lastIndexOf('.');
          if (str.substring(0, pos).equals("java.lang")) {
              str = str.substring(pos + 1);
          }
          if (str.substring(0, pos).equals("java.util")) {
              str = str.substring(pos + 1);
          }
          return str;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/IdentityConversionFactory.java
  
  Index: IdentityConversionFactory.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from TimeZone to String using <code>getID()</code>.
   *
   * @author Stephen Colebourne
   * @version $Id: IdentityConversionFactory.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class IdentityConversionFactory implements ConversionFactory {
  
      /** Singleton instance of this factory */
      public static final ConversionFactory INSTANCE = new IdentityConversionFactory();
  
      /**
       * Restricted constructor.
       */
      protected IdentityConversionFactory() {
          super();
      }
  
      //-----------------------------------------------------------------------
      /**
       * Checks if the types are equal, if so return 80.
       * 
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  the type to convert to, may be null
       * @return 80 if types are equal
       */
      public int getMatchPercent(Object value, Class fromType, Class toType) {
          if (fromType == toType && fromType != null) {
              return 80;
          }
          return 0;
      }
  
      /**
       * Create a new conversion object for the specified from and to types.
       * <p>
       * This implementation returns the identity conversion.
       *
       * @param value  the value to be converted, read only, may be null
       * @param fromType  the type to convert from, may be null
       * @param toType  the type to convert to, may be null
       * @return a Conversion object for repeatedly performing conversions
       */
      public Conversion getInstance(Object value, Class fromType, Class toType) {
          return new IdentityConversion(fromType, toType);
      }
      
      /**
       * Gets a string suitable for debugging.
       * 
       * @return a debugging string
       */
      public String toString() {
          return "ConversionFactory[Identity]";
      }
  
      //-----------------------------------------------------------------------
      /**
       * Generic conversion implementation that returns the input value.
       */
      class IdentityConversion extends AbstractConversion {
  
          /**
           * Constructs a Conversion.
           * 
           * @param fromType  the type to convert from
           * @param toType  the type to convert to
           */
          IdentityConversion(Class fromType, Class toType) {
              super(fromType, toType);
          }
  
          /**
           * Converts the input value by returning it unchanged.
           * 
           * @param value  the input value to be converted, pre-checked to not be null
           * @param converter  the converter being used, not null
           * @return the input value
           */
          public Object convert(Object value, Converter converter) {
              return value;
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/DefaultValueDecorator.java
  
  Index: DefaultValueDecorator.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.ConversionFactory;
  import org.apache.commons.convert.Converter;
  
  /**
   * A utility class for decorating conversions and factories with default value behaviour.
   * <p>
   * Each public static method on this class will decorate the input conversion/factory
   * with additional behaviour. Depending on the method it may return a default value in
   * the case of an exception or null value
   * <p>
   * To use this facility, create an instance of the conversion/factory as normal.
   * Then pass it to one of the static methods on this class.
   * Finally add it as per normal to the <code>ConverterRegistry</code>.
   * 
   * @author Stephen Colebourne
   * @author Oliver Heger
   * @version $Id: DefaultValueDecorator.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class DefaultValueDecorator {
  
      /**
       * Restricted constructor.
       */
      protected DefaultValueDecorator() {
      }
  
      //-----------------------------------------------------------------------
      /**
       * Creates a Conversion that decorates the original and adds behaviour to
       * return a default value when the conversion results in null.
       * 
       * @param conversion  the conversion to decorate, not null
       * @param defaultValue  the value to return if conversion result is null
       * @return the decorated conversion
       */
      public static Conversion defaultNullResult(Conversion conversion, Object defaultValue) {
          checkNotNull(conversion);
          return new DefaultNullResultConversion(conversion, defaultValue);
      }
  
      /**
       * Creates a Conversion that decorates the original and adds behaviour to
       * return a default value when the conversion input is null.
       * 
       * @param conversion  the conversion to decorate, not null
       * @param defaultValue  the value to return if conversion input is null
       * @return the decorated conversion
       */
      public static Conversion defaultNullInput(Conversion conversion, Object defaultValue) {
          checkNotNull(conversion);
          return new DefaultNullInputConversion(conversion, defaultValue);
      }
  
      /**
       * Creates a Conversion that decorates the original and adds behaviour to
       * return a default value when the conversion throws an exception.
       * 
       * @param conversion  the conversion to decorate, not null
       * @param defaultValue  the value to return if conversion throws an exception
       * @return the decorated conversion
       */
      public static Conversion defaultException(Conversion conversion, Object defaultValue) {
          checkNotNull(conversion);
          return new DefaultExceptionConversion(conversion, defaultValue);
      }
  
      /**
       * Creates a Conversion that decorates the original and adds behaviour to
       * return a default value for null input, null result and when an exception occurs.
       * 
       * @param conversion  the conversion to decorate, not null
       * @param defaultValue  the default value to return
       * @return the decorated conversion
       */
      public static Conversion defaultNullAndException(Conversion conversion, Object defaultValue) {
          checkNotNull(conversion);
          return new DefaultNullExceptionConversion(conversion, defaultValue);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Creates a ConversionFactory that decorates the original and adds behaviour to
       * return a default value when the conversion results in null.
       * 
       * @param factory  the factory to decorate, not null
       * @param defaultValue  the value to return if conversion result is null
       * @return the decorated factory
       */
      public static ConversionFactory defaultNullResult(ConversionFactory factory, Object defaultValue) {
          checkNotNull(factory);
          return new DefaultNullResultConversionFactory(factory, defaultValue);
      }
  
      /**
       * Creates a ConversionFactory that decorates the original and adds behaviour to
       * return a default value when the conversion input is null.
       * 
       * @param factory  the factory to decorate, not null
       * @param defaultValue  the value to return if conversion input is null
       * @return the decorated factory
       */
      public static ConversionFactory defaultNullInput(ConversionFactory factory, Object defaultValue) {
          checkNotNull(factory);
          return new DefaultNullInputConversionFactory(factory, defaultValue);
      }
  
      /**
       * Creates a ConversionFactory that decorates the original and adds behaviour to
       * return a default value when the conversion throws an exception.
       * 
       * @param factory  the factory to decorate, not null
       * @param defaultValue  the value to return if conversion throws an exception
       * @return the decorated factory
       */
      public static ConversionFactory defaultException(ConversionFactory factory, Object defaultValue) {
          checkNotNull(factory);
          return new DefaultExceptionConversionFactory(factory, defaultValue);
      }
  
      /**
       * Creates a ConversionFactory that decorates the original and adds behaviour to
       * return a default value for null input, null result and when an exception occurs.
       * 
       * @param factory  the factory to decorate, not null
       * @param defaultValue  the default value to return
       * @return the decorated factory
       */
      public static ConversionFactory defaultNullAndException(ConversionFactory factory, Object defaultValue) {
          checkNotNull(factory);
          return new DefaultNullExceptionConversionFactory(factory, defaultValue);
      }
  
      //-----------------------------------------------------------------------    
      /**
       * Checks whether the input conversion is null and throws an exception.
       * 
       * @param conversion  the conversion to check
       */
      private static void checkNotNull(Conversion conversion) {
          if (conversion == null) {
              throw new IllegalArgumentException("Conversion must not be null");
          }
      }
  
      /**
       * Checks whether the input factory is null and throws an exception.
       * 
       * @param factory  the factory to check
       */
      private static void checkNotNull(ConversionFactory factory) {
          if (factory == null) {
              throw new IllegalArgumentException("ConversionFactory must not be null");
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Abstract base class for default value decorators.
       */
      static abstract class AbstractDefaultConversion implements Conversion {
  
          /** The decorated conversion */
          private final Conversion conversion;
          /** The default value to return */
          private final Object defaultValue;
  
          /**
           * Constructor.
           * 
           * @param conversion  the conversion to decorate, not null
           * @param defaultValue  the default value to return
           */
          AbstractDefaultConversion(Conversion conversion, Object defaultValue) {
              super();
              this.conversion = conversion;
              this.defaultValue = defaultValue;
          }
  
          /**
           * Returns the type to convert from.
           * 
           * @return the Class object representing the class to convert from
           */
          public Class getFromType() {
              return getDecoratedConversion().getFromType();
          }
  
          /**
           * Returns the type to convert to.
           * 
           * @return the Class object representing the class to convert to
           */
          public Class getToType() {
              return getDecoratedConversion().getToType();
          }
  
          /**
           * Gets the conversion being decorated.
           * 
           * @return the decorated conversion
           */
          public Conversion getDecoratedConversion() {
              return conversion;
          }
  
          /**
           * Gets the default value to be returned.
           * 
           * @return the default value
           */
          public Object getDefaultValue() {
              return defaultValue;
          }
  
          /**
           * Gets a suitable debugging string.
           * 
           * @return a debugging string
           */
          public String toString() {
              String str = getDecoratedConversion().toString();
              return str.substring(0, str.length() - 1) + ",default=" + getDefaultValue() + "]";
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default null result behaviour.
       */
      static class DefaultNullResultConversion extends AbstractDefaultConversion {
  
          /**
           * Constructs a null result conversion.
           * 
           * @param conversion  the conversion to decorate, not null
           * @param defaultValue  the value to return if conversion result is null
           */
          DefaultNullResultConversion(Conversion conversion, Object defaultValue) {
              super(conversion, defaultValue);
          }
  
          /**
           * Performs the conversion by delegating to the original conversion and
           * then handling the default value.
           * 
           * @param value  the object to be converted
           * @param converter  the associated converter
           * @return the result of the conversion
           */
          public Object convert(Object value, Converter converter) throws Exception {
              Object result = getDecoratedConversion().convert(value, converter);
              if (result == null) {
                  return getDefaultValue();
              }
              return result;
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default null input behaviour.
       */
      static class DefaultNullInputConversion extends AbstractDefaultConversion {
  
          /**
           * Constructs a null input conversion.
           * 
           * @param conversion  the conversion to decorate, not null
           * @param defaultValue  the value to return if conversion input is null
           */
          DefaultNullInputConversion(Conversion conversion, Object defaultValue) {
              super(conversion, defaultValue);
          }
  
          /**
           * Performs the conversion by checking for null, then delegating to the
           * original conversion.
           * 
           * @param value  the object to be converted
           * @param converter  the associated converter
           * @return the result of the conversion
           */
          public Object convert(Object value, Converter converter) throws Exception {
              if (value == null) {
                  return getDefaultValue();
              }
              return getDecoratedConversion().convert(value, converter);
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default on exception behaviour.
       */
      static class DefaultExceptionConversion extends AbstractDefaultConversion {
  
          /**
           * Constructs a default on exception conversion.
           * 
           * @param conversion  the conversion to decorate, not null
           * @param defaultValue  the value to return if conversion throws an exception
           */
          DefaultExceptionConversion(Conversion conversion, Object defaultValue) {
              super(conversion, defaultValue);
          }
  
          /**
           * Performs the conversion by delegating to the original conversion and
           * handling the default value.
           * 
           * @param value  the object to be converted
           * @param converter  the associated converter
           * @return the result of the conversion
           */
          public Object convert(Object value, Converter converter) {
              try {
                  return getDecoratedConversion().convert(value, converter);
              } catch (Exception ex) {
                  return getDefaultValue();
              }
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default on exception behaviour.
       */
      static class DefaultNullExceptionConversion extends AbstractDefaultConversion {
  
          /**
           * Constructs a default on nulls and exception conversion.
           * 
           * @param conversion  the conversion to decorate, not null
           * @param defaultValue  the default value to return
           */
          DefaultNullExceptionConversion(Conversion conversion, Object defaultValue) {
              super(conversion, defaultValue);
          }
  
          /**
           * Performs the conversion by delegating to the original conversion and
           * handling the default value.
           * 
           * @param value  the object to be converted
           * @param converter  the associated converter
           * @return the result of the conversion
           */
          public Object convert(Object value, Converter converter) {
              if (value == null) {
                  return getDefaultValue();
              }
              try {
                  Object result = getDecoratedConversion().convert(value, converter);
                  if (result == null) {
                      return getDefaultValue();
                  }
                  return result;
              } catch (Exception ex) {
                  return getDefaultValue();
              }
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default null result behaviour.
       */
      static abstract class AbstractDefaultConversionFactory implements ConversionFactory {
  
          /** The decorated factory */
          private final ConversionFactory factory;
          /** The default value to return */
          private final Object defaultValue;
  
          /**
           * Constructor.
           * 
           * @param factory  the factory to decorate, not null
           * @param defaultValue  the default value to return
           */
          AbstractDefaultConversionFactory(ConversionFactory factory, Object defaultValue) {
              super();
              this.factory = factory;
              this.defaultValue = defaultValue;
          }
  
          /**
           * Gets an indicator as to how well the factory matches.
           * 
           * @param value  the value to be converted
           * @param fromType  the type to be converted from
           * @param toType  the type to be converted to
           * @return a percentage value for the appropriateness of this class
           */
          public int getMatchPercent(Object value, Class fromType, Class toType) {
              return getDecoratedConversionFactory().getMatchPercent(value, fromType, toType);
          }
  
          /**
           * Creates a conversion instance for the specified conversion.
           * This implementation lets the decorated factory create an instance.
           * This instance is then decorated with defaulting behaviour.
           * 
           * @param value  the value to be converted
           * @param fromType  the type to convert from
           * @param toType  the type to convert to
           * @return a conversion instance
           */
          public Conversion getInstance(Object value, Class fromType, Class toType) {
              Conversion conversion = getDecoratedConversionFactory().getInstance(value, fromType, toType);
              return createConversion(conversion, getDefaultValue());
          }
  
          /**
           * Creates a new decorated conversion.
           * 
           * @param conversion  the conversion to decorate
           * @param object  the default value
           * @return a new decorated conversion
           */
          protected abstract Conversion createConversion(Conversion conversion, Object defaultValue);
  
          /**
           * Gets the factory being decorated.
           * 
           * @return the decorated factory
           */
          public ConversionFactory getDecoratedConversionFactory() {
              return factory;
          }
  
          /**
           * Gets the default value to be returned.
           * 
           * @return the default value
           */
          public Object getDefaultValue() {
              return defaultValue;
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default null result behaviour.
       */
      static class DefaultNullResultConversionFactory extends AbstractDefaultConversionFactory {
  
          /**
           * Constructs a null result factory.
           * 
           * @param factory  the factory to decorate, not null
           * @param defaultValue  the default value to return
           */
          DefaultNullResultConversionFactory(ConversionFactory factory, Object defaultValue) {
              super(factory, defaultValue);
          }
  
          /**
           * Creates a new decorated conversion.
           * 
           * @param conversion  the conversion to decorate
           * @param object  the default value
           * @return a new decorated conversion
           */
          protected Conversion createConversion(Conversion conversion, Object defaultValue) {
              return new DefaultNullResultConversion(conversion, defaultValue);
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default null input behaviour.
       */
      static class DefaultNullInputConversionFactory extends AbstractDefaultConversionFactory {
  
          /**
           * Constructs a null input factory.
           * 
           * @param factory  the factory to decorate, not null
           * @param defaultValue  the default value to return
           */
          DefaultNullInputConversionFactory(ConversionFactory factory, Object defaultValue) {
              super(factory, defaultValue);
          }
  
          /**
           * Creates a new decorated conversion.
           * 
           * @param conversion  the conversion to decorate
           * @param object  the default value
           * @return a new decorated conversion
           */
          protected Conversion createConversion(Conversion conversion, Object defaultValue) {
              return new DefaultNullInputConversion(conversion, defaultValue);
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default on exception behaviour.
       */
      static class DefaultExceptionConversionFactory extends AbstractDefaultConversionFactory {
  
          /**
           * Constructs a null result factory.
           * 
           * @param factory  the factory to decorate, not null
           * @param defaultValue  the default value to return
           */
          DefaultExceptionConversionFactory(ConversionFactory factory, Object defaultValue) {
              super(factory, defaultValue);
          }
  
          /**
           * Creates a new decorated conversion.
           * 
           * @param conversion  the conversion to decorate
           * @param object  the default value
           * @return a new decorated conversion
           */
          protected Conversion createConversion(Conversion conversion, Object defaultValue) {
              return new DefaultExceptionConversion(conversion, defaultValue);
          }
      }
  
      //-----------------------------------------------------------------------
      /**
       * Implement the default on nulls and exceptions behaviour.
       */
      static class DefaultNullExceptionConversionFactory extends AbstractDefaultConversionFactory {
  
          /**
           * Constructs a null result factory.
           * 
           * @param factory  the factory to decorate, not null
           * @param defaultValue  the default value to return
           */
          DefaultNullExceptionConversionFactory(ConversionFactory factory, Object defaultValue) {
              super(factory, defaultValue);
          }
  
          /**
           * Creates a new decorated conversion.
           * 
           * @param conversion  the conversion to decorate
           * @param object  the default value
           * @return a new decorated conversion
           */
          protected Conversion createConversion(Conversion conversion, Object defaultValue) {
              return new DefaultNullExceptionConversion(conversion, defaultValue);
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/convert/src/java/org/apache/commons/convert/conversion/ClassToStringConversion.java
  
  Index: ClassToStringConversion.java
  ===================================================================
  /*
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.commons.convert.conversion;
  
  import org.apache.commons.convert.Conversion;
  import org.apache.commons.convert.Converter;
  
  /**
   * Conversion from Class to String using <code>getName()</code>.
   *
   * @author Stephen Colebourne
   * @version $Id: ClassToStringConversion.java,v 1.1 2004/03/20 19:17:34 scolebourne Exp $
   * @since 1.0
   */
  public class ClassToStringConversion extends AbstractConversion {
  
      /** Singleton instance of this factory */
      public static final Conversion INSTANCE = new ClassToStringConversion();
  
      /**
       * Constructor.
       */
      protected ClassToStringConversion() {
          super(Class.class, STRING_CLASS);
      }
  
      //-----------------------------------------------------------------------
      /**
       * Convert the non-null Class to a String using <code>getName()</code>.
       * 
       * @param value  the input value to be converted, pre-checked to not be null
       * @param converter  the converter being used, not null
       * @return the converted value
       */
      protected Object convertValue(Object value, Converter converter) {
          return ((Class) value).getName();
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message