mirror of https://github.com/apache/activemq.git
AMQ-4011: Do not use java bean property editors for type conversion. Marked stuff as @deprecated.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1386596 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2d88395073
commit
b749228112
|
@ -18,6 +18,7 @@ package org.apache.activemq.util;
|
|||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
|
||||
@Deprecated
|
||||
public class BooleanEditor extends PropertyEditorSupport {
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
|
|||
* Used to serialize lists of ActiveMQDestinations.
|
||||
* @see org.apache.activemq.util.IntrospectionSupport
|
||||
*/
|
||||
@Deprecated
|
||||
public class ListEditor extends PropertyEditorSupport {
|
||||
|
||||
public static final String DEFAULT_SEPARATOR = ",";
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.regex.Pattern;
|
|||
* Converts string values like "20 Mb", "1024kb", and "1g" to int values in
|
||||
* bytes.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MemoryIntPropertyEditor extends PropertyEditorSupport {
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.regex.Pattern;
|
|||
* Converts string values like "20 Mb", "1024kb", and "1g" to long values in
|
||||
* bytes.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MemoryPropertyEditor extends PropertyEditorSupport {
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ import java.util.StringTokenizer;
|
|||
*/
|
||||
public class StringArrayConverter {
|
||||
|
||||
// TODO: Remove System.out
|
||||
|
||||
public static String[] convertToStringArray(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
|
|
|
@ -18,12 +18,13 @@ package org.apache.activemq.util;
|
|||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
|
||||
public final class TypeConversionSupport {
|
||||
|
||||
static class ConversionKey {
|
||||
private static class ConversionKey {
|
||||
final Class from;
|
||||
final Class to;
|
||||
final int hashCode;
|
||||
|
@ -48,7 +49,7 @@ public final class TypeConversionSupport {
|
|||
Object convert(Object value);
|
||||
}
|
||||
|
||||
private static final HashMap<ConversionKey, Converter> CONVERSION_MAP = new HashMap<ConversionKey, Converter>();
|
||||
private static final Map<ConversionKey, Converter> CONVERSION_MAP = new HashMap<ConversionKey, Converter>();
|
||||
static {
|
||||
Converter toStringConverter = new Converter() {
|
||||
public Object convert(Object value) {
|
||||
|
@ -142,20 +143,29 @@ public final class TypeConversionSupport {
|
|||
private TypeConversionSupport() {
|
||||
}
|
||||
|
||||
public static Object convert(Object value, Class clazz) {
|
||||
public static Object convert(Object value, Class type) {
|
||||
|
||||
assert value != null && clazz != null;
|
||||
|
||||
if (value.getClass() == clazz) {
|
||||
return value;
|
||||
}
|
||||
|
||||
Converter c = CONVERSION_MAP.get(new ConversionKey(value.getClass(), clazz));
|
||||
if (c == null) {
|
||||
if (value == null) {
|
||||
// lets avoid NullPointerException when converting to boolean for null values
|
||||
if (boolean.class.isAssignableFrom(type)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return c.convert(value);
|
||||
|
||||
// eager same instance type test to avoid the overhead of invoking the type converter
|
||||
// if already same type
|
||||
if (type.isInstance(value)) {
|
||||
return type.cast(value);
|
||||
}
|
||||
|
||||
// lookup converter
|
||||
Converter c = CONVERSION_MAP.get(new ConversionKey(value.getClass(), type));
|
||||
if (c != null) {
|
||||
return c.convert(value);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue