activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1386596 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util: BooleanEditor.java ListEditor.java MemoryIntPropertyEditor.java MemoryPropertyEditor.java StringArrayConverter.java TypeConversionSupport.java
Date Mon, 17 Sep 2012 13:10:51 GMT
Author: davsclaus
Date: Mon Sep 17 13:10:50 2012
New Revision: 1386596

URL: http://svn.apache.org/viewvc?rev=1386596&view=rev
Log:
AMQ-4011: Do not use java bean property editors for type conversion. Marked stuff as @deprecated.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ListEditor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/StringArrayConverter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/BooleanEditor.java
Mon Sep 17 13:10:50 2012
@@ -18,6 +18,7 @@ package org.apache.activemq.util;
 
 import java.beans.PropertyEditorSupport;
 
+@Deprecated
 public class BooleanEditor extends PropertyEditorSupport {
 
     public String getJavaInitializationString() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ListEditor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ListEditor.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ListEditor.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ListEditor.java Mon
Sep 17 13:10:50 2012
@@ -26,6 +26,7 @@ import org.springframework.util.StringUt
  * Used to serialize lists of ActiveMQDestinations. 
  * @see org.apache.activemq.util.IntrospectionSupport
  */
+@Deprecated
 public class ListEditor extends PropertyEditorSupport {
 	
 	public static final String DEFAULT_SEPARATOR = ",";

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryIntPropertyEditor.java
Mon Sep 17 13:10:50 2012
@@ -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 {
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/MemoryPropertyEditor.java
Mon Sep 17 13:10:50 2012
@@ -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 {
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/StringArrayConverter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/StringArrayConverter.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/StringArrayConverter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/StringArrayConverter.java
Mon Sep 17 13:10:50 2012
@@ -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;

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java?rev=1386596&r1=1386595&r2=1386596&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/TypeConversionSupport.java
Mon Sep 17 13:10:50 2012
@@ -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 == null) {
+            // lets avoid NullPointerException when converting to boolean for null values
+            if (boolean.class.isAssignableFrom(type)) {
+                return Boolean.FALSE;
+            }
+            return null;
+        }
 
-        if (value.getClass() == clazz) {
-            return 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);
         }
 
-        Converter c = CONVERSION_MAP.get(new ConversionKey(value.getClass(), clazz));
-        if (c == null) {
+        // lookup converter
+        Converter c = CONVERSION_MAP.get(new ConversionKey(value.getClass(), type));
+        if (c != null) {
+            return c.convert(value);
+        } else {
             return null;
         }
-        return c.convert(value);
-
     }
 
 }



Mime
View raw message