commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/java/org/apache/commons/beanutils ConvertUtils.java
Date Sat, 21 Dec 2002 19:53:24 GMT
craigmcc    2002/12/21 11:53:24

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        ConvertUtils.java
  Log:
  Make the implementation of ConvertUtils.convert(Object) use the registered
  Converter for java.lang.String instead of just doing a toString() operation.
  This allows applications to plug in custom Object->String conversion
  capabilities, although such a Converter would need to handle *all* required
  conversions, instead of just one.  The default implementation continues to
  use toString(), preserving backwards compatibility.
  
  PR: Bugzilla #14170
  Submitted by:	Brian Knorr <brian.knorr at nextjet.com>
  
  Revision  Changes    Path
  1.11      +15 -9     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ConvertUtils.java	20 Jul 2002 18:21:21 -0000	1.10
  +++ ConvertUtils.java	21 Dec 2002 19:53:24 -0000	1.11
  @@ -324,7 +324,10 @@
       /**
        * Convert the specified value into a String.  If the specified value
        * is an array, the first element (converted to a String) will be
  -     * returned.
  +     * returned.  The registered {@link Converter} for the
  +     * <code>java.lang.String</code> class will be used, which allows
  +     * applications to customize Object->String conversions (the default
  +     * implementation simply uses toString()).
        *
        * @param value Value to be converted (may be null)
        */
  @@ -337,12 +340,15 @@
                   return (null);
               }
               value = Array.get(value, 0);
  -            if (value == null)
  +            if (value == null) {
                   return ((String) null);
  -            else
  -                return (value.toString());
  +            } else {
  +                Converter converter = (Converter) converters.get(String.class);
  +                return ((String) converter.convert(String.class, value));
  +            }
           } else {
  -            return (value.toString());
  +            Converter converter = (Converter) converters.get(String.class);
  +            return ((String) converter.convert(String.class, value));
           }
   
       }
  
  
  

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


Mime
View raw message