diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java index 2b91c588df..d3f0839d9b 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/ConversionFailedException.java @@ -40,7 +40,7 @@ public final class ConversionFailedException extends ConversionException { * @param cause the cause of the conversion failure */ public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) { - super("Unable to convert value " + value + " from type '" + sourceType.getName() + + super("Unable to convert value \"" + value + "\" from type '" + sourceType.getName() + "' to type '" + targetType.getName() + "'", cause); this.sourceType = sourceType; this.targetType = targetType; diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java index 3a0bfa150a..87a11716e3 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,37 +54,27 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { Class> sourceClass = sourceType.getObjectType(); Class> targetClass = targetType.getObjectType(); - Object target; Method method = getValueOfMethodOn(targetClass, sourceClass); - if (method != null) { - ReflectionUtils.makeAccessible(method); - target = ReflectionUtils.invokeMethod(method, null, source); - } - else { - Constructor> constructor = getConstructor(targetClass, sourceClass); - if (constructor != null) { - try { - target = constructor.newInstance(source); - } - catch (IllegalArgumentException ex) { - throw new ConversionFailedException(sourceType, targetType, source, ex); - } - catch (InstantiationException ex) { - throw new ConversionFailedException(sourceType, targetType, source, ex); - } - catch (IllegalAccessException ex) { - throw new ConversionFailedException(sourceType, targetType, source, ex); - } - catch (InvocationTargetException ex) { - throw new ConversionFailedException(sourceType, targetType, source, ex); - } + try { + if (method != null) { + ReflectionUtils.makeAccessible(method); + return method.invoke(null, source); } else { - throw new IllegalStateException("No static valueOf(" + sourceClass.getName() + - ") method or Constructor(" + sourceClass.getName() + ") exists on " + targetClass.getName()); + Constructor> constructor = getConstructor(targetClass, sourceClass); + if (constructor != null) { + return constructor.newInstance(source); + } } } - return target; + catch (InvocationTargetException ex) { + throw new ConversionFailedException(sourceType, targetType, source, ex.getTargetException()); + } + catch (Throwable ex) { + throw new ConversionFailedException(sourceType, targetType, source, ex); + } + throw new IllegalStateException("No static valueOf(" + sourceClass.getName() + + ") method or Constructor(" + sourceClass.getName() + ") exists on " + targetClass.getName()); } diff --git a/org.springframework.web/src/main/java/org/springframework/http/MediaType.java b/org.springframework.web/src/main/java/org/springframework/http/MediaType.java index 24d36aee1a..83715d8ff9 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/MediaType.java +++ b/org.springframework.web/src/main/java/org/springframework/http/MediaType.java @@ -37,14 +37,14 @@ import org.springframework.util.StringUtils; /** * Represents an Internet Media Type, as defined in the HTTP specification. * - *
Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}. Also has functionality to - * parse media types from a string using {@link #parseMediaType(String)}, or multiple comma-separated media types using - * {@link #parseMediaTypes(String)}. + *
Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}.
+ * Also has functionality to parse media types from a string using {@link #parseMediaType(String)},
+ * or multiple comma-separated media types using {@link #parseMediaTypes(String)}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
- * @see HTTP 1.1, section 3.7
* @since 3.0
+ * @see HTTP 1.1, section 3.7
*/
public class MediaType implements Comparable The {@linkplain #getSubtype() subtype} is set to The parameters are empty.
- *
+ * Create a new {@link MediaType} for the given primary type and subtype.
+ * The parameters are empty.
* @param type the primary type
* @param subtype the subtype
* @throws IllegalArgumentException if any of the parameters contain illegal characters
@@ -209,7 +209,6 @@ public class MediaType implements Comparable For instance, {@code text/*} includes {@code text/plain}, {@code text/html}, and {@code application/*+xml}
* includes {@code application/soap+xml}, etc. This method is non-symmetic.
- *
* @param other the reference media type with which to compare
* @return For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa. In
- * effect, this method is similar to {@link #includes(MediaType)}, except that it's symmetric.
- *
+ * For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa.
+ * In effect, this method is similar to {@link #includes(MediaType)}, except that it's symmetric.
* @param other the reference media type with which to compare
* @return This method can be used to
- * parse an Accept or Content-Type header.
- *
+ * Parse the given, comma-seperated string into a list of {@link MediaType} objects.
+ * This method can be used to parse an Accept or Content-Type header.
* @param mediaTypes the string to parse
* @return the list of media types
* @throws IllegalArgumentException if the string cannot be parsed
@@ -602,9 +606,7 @@ public class MediaType implements Comparable This method can be used to for an {@code Accept} or {@code Content-Type} header.
- *
* @param mediaTypes the string to parse
* @return the list of media types
* @throws IllegalArgumentException if the String cannot be parsed
@@ -623,7 +625,6 @@ public class MediaType implements Comparable Given two media types:
* For example:
* Given two media types:
* *
, parameters empty.
- *
* @param type the primary type
* @throws IllegalArgumentException if any of the parameters contain illegal characters
*/
@@ -197,8 +197,8 @@ public class MediaType implements Comparablenull
* @throws IllegalArgumentException if any of the parameters contain illegal characters
@@ -245,7 +243,6 @@ public class MediaType implements Comparablenull
@@ -275,7 +272,6 @@ public class MediaType implements Comparable*
or not. */
+ /**
+ * Indicate whether the {@linkplain #getType() type} is the wildcard character *
or not.
+ */
public boolean isWildcardType() {
return WILDCARD_TYPE.equals(type);
}
- /** Return the subtype. */
+ /**
+ * Return the subtype.
+ */
public String getSubtype() {
return this.subtype;
}
/**
* Indicate whether the {@linkplain #getSubtype() subtype} is the wildcard character *
or not.
- *
* @return whether the subtype is *
*/
public boolean isWildcardSubtype() {
@@ -343,7 +345,6 @@ public class MediaType implements Comparablecharset
parameter, if any.
- *
* @return the character set; or null
if not available
*/
public Charset getCharSet() {
@@ -352,8 +353,8 @@ public class MediaType implements Comparableq
parameter, if any. Defaults to 1.0
.
- *
+ * Return the quality value, as indicated by a q
parameter, if any.
+ * Defaults to 1.0
.
* @return the quality factory
*/
public double getQualityValue() {
@@ -363,7 +364,6 @@ public class MediaType implements Comparablenull
if not present
*/
@@ -373,10 +373,8 @@ public class MediaType implements Comparabletrue
if this media type includes the given media type; false
otherwise
*/
@@ -410,10 +408,8 @@ public class MediaType implements Comparabletrue
if this media type is compatible with the given media type; false
otherwise
*/
@@ -449,7 +445,6 @@ public class MediaType implements Comparable
*
- *
* audio/basic < audio/* < */*
* audio/* < audio/*;q=0.7; audio/*;q=0.3
* audio/basic;level=1 < audio/basic
* audio/basic == text/html
* audio/basic == audio/wave
- *
* @param mediaTypes the list of media types to be sorted
* @see HTTP 1.1, section 14.1
*/
@@ -659,7 +658,6 @@ public class MediaType implements Comparable
*
- *
* @param mediaTypes the list of media types to be sorted
* @see #getQualityValue()
*/
@@ -686,6 +683,7 @@ public class MediaType implements Comparable