commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r540383 - /jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java
Date Tue, 22 May 2007 01:01:07 GMT
Author: niallp
Date: Mon May 21 18:01:07 2007
New Revision: 540383

URL: http://svn.apache.org/viewvc?view=rev&rev=540383
Log:
BEANUTILS-258 - switch StringConverter to be based on the new AbstractConveter - provides
only limmited advantage, but StringConverter didn't have the usual ConversionException and
default logic - which it now has

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java?view=diff&rev=540383&r1=540382&r2=540383
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/converters/StringConverter.java
Mon May 21 18:01:07 2007
@@ -14,15 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */ 
-
-
 package org.apache.commons.beanutils.converters;
 
-
-import org.apache.commons.beanutils.ConversionException;
 import org.apache.commons.beanutils.Converter;
 
-
 /**
  * Standard {@link Converter} implementation that converts an incoming
  * object into a <code>java.lang.String</code> object.
@@ -48,31 +43,40 @@
  * @version $Revision$ $Date$
  * @since 1.3
  */
+public final class StringConverter extends AbstractConverter {
 
-public final class StringConverter implements Converter {
 
+    /**
+     * Construct a <b>java.lang.String</b> <i>Converter</i> that
throws
+     * a <code>ConversionException</code> if an error occurs.
+     */
+    public StringConverter() {
+        super(String.class);
+    }
 
-    // --------------------------------------------------------- Public Methods
-
+    /**
+     * Construct a <b>java.lang.String</b> <i>Converter</i> that
returns
+     * a default value if an error occurs.
+     *
+     * @param defaultValue The default value to be returned
+     * if the value to be converted is missing or an error
+     * occurs converting the value.
+     */
+    public StringConverter(Object defaultValue) {
+        super(String.class, defaultValue);
+    }
 
     /**
      * Convert the specified input object into an output object of the
      * specified type.
      *
-     * @param type Data type to which this value should be converted
-     * @param value The input value to be converted
-     *
-     * @exception ConversionException if conversion cannot be performed
-     *  successfully
+     * @param type Data type to which this value should be converted.
+     * @param value The input value to be converted.
+     * @return The converted value.
+     * @throws Throwable if an error occurs converting to the specified type
      */
-    public Object convert(Class type, Object value) {
-
-        if (value == null) {
-            return ((String) null);
-        } else {
-            return (value.toString());
-        }
-
+    protected Object convertToType(Class type, Object value) throws Throwable {
+        return value.toString();
     }
 
 



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