cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5688] Optional support for case-sensitive enum conversion
Date Tue, 15 Apr 2014 16:13:13 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 8a9cd932d -> 991de80f7


[CXF-5688] Optional support for case-sensitive enum conversion


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/991de80f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/991de80f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/991de80f

Branch: refs/heads/2.7.x-fixes
Commit: 991de80f7667a5b9d13c25eba113d5c54c1726a3
Parents: 8a9cd93
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Apr 15 16:58:04 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Apr 15 17:12:59 2014 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/utils/InjectionUtils.java  | 34 +++++++++++---------
 1 file changed, 19 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/991de80f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
index 3b0f3cc..ed7a913 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
@@ -94,6 +94,7 @@ import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public final class InjectionUtils {
     
@@ -106,6 +107,8 @@ public final class InjectionUtils {
     private static final String HTTP_SERVLET_RESPONSE_CLASS_NAME = "javax.servlet.http.HttpServletResponse";
         
     private static final String PARAM_HANDLERS_FIRST = "check.parameter.handlers.first";
+    private static final String ENUM_CONVERSION_CASE_SENSITIVE = "enum.conversion.case.sensitive";
   
+    
     private static final String IGNORE_MATRIX_PARAMETERS = "ignore.matrix.parameters";
     
     private InjectionUtils() {
@@ -1246,20 +1249,17 @@ public final class InjectionUtils {
             } 
         }
     }
-    
-    public static <T> Object convertStringToPrimitive(String value, Class<?>
cls) {
+    public static Object convertStringToPrimitive(String value, Class<?> cls) {
         if (String.class == cls) {
             return value;
-        }
-        if (cls.isPrimitive()) {
+        } else if (cls.isPrimitive()) {
             return PrimitiveUtils.read(value, cls);
         } else if (cls.isEnum()) {
-            try {
-                Method m  = cls.getMethod("valueOf", new Class[]{String.class});
-                return m.invoke(null, value.toUpperCase());
-            } catch (Exception ex) {
-                throw new RuntimeException(ex);
+            Message m = PhaseInterceptorChain.getCurrentMessage();
+            if (m == null || !MessageUtils.getContextualBoolean(m, ENUM_CONVERSION_CASE_SENSITIVE,
false)) {
+                value = value.toUpperCase();
             }
+            return invokeValueOf(value, cls);
         } else {
             try {
                 Constructor<?> c = cls.getConstructor(new Class<?>[]{String.class});
@@ -1267,12 +1267,16 @@ public final class InjectionUtils {
             } catch (Throwable ex) {
                 // try valueOf
             }
-            try {
-                Method m = cls.getMethod("valueOf", new Class[]{String.class});
-                return cls.cast(m.invoke(null, value));
-            } catch (Exception ex) {
-                throw new RuntimeException(ex);
-            }
+            return invokeValueOf(value, cls);
+        }
+    }
+    
+    private static Object invokeValueOf(String value, Class<?> cls) {
+        try {
+            Method m  = cls.getMethod("valueOf", new Class[]{String.class});
+            return m.invoke(null, value);
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
         }
     }
     


Mime
View raw message