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 15:58:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 1f5a2ffd4 -> 3791ce7b4


[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/3791ce7b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3791ce7b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3791ce7b

Branch: refs/heads/master
Commit: 3791ce7b41abc72353d572536d5c9b3c6d60c616
Parents: 1f5a2ff
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 16:58:04 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/3791ce7b/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 de587dd..193097c 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
@@ -92,6 +92,7 @@ import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 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 {
     
@@ -102,7 +103,8 @@ public final class InjectionUtils {
     private static final String SERVLET_CONTEXT_CLASS_NAME = "javax.servlet.ServletContext";
     private static final String HTTP_SERVLET_REQUEST_CLASS_NAME = "javax.servlet.http.HttpServletRequest";
     private static final String HTTP_SERVLET_RESPONSE_CLASS_NAME = "javax.servlet.http.HttpServletResponse";
-        
+    private static final String ENUM_CONVERSION_CASE_SENSITIVE = "enum.conversion.case.sensitive";
   
+    
     private static final String IGNORE_MATRIX_PARAMETERS = "ignore.matrix.parameters";
     
     private InjectionUtils() {
@@ -1251,20 +1253,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});
@@ -1272,12 +1271,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