cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1404611 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
Date Thu, 01 Nov 2012 14:34:45 GMT
Author: sergeyb
Date: Thu Nov  1 14:34:45 2012
New Revision: 1404611

URL: http://svn.apache.org/viewvc?rev=1404611&view=rev
Log:
[CXF-4607] Adding RequestDispatcherProvider enumResources property

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java?rev=1404611&r1=1404610&r2=1404611&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProvider.java
Thu Nov  1 14:34:45 2012
@@ -75,6 +75,7 @@ public class RequestDispatcherProvider e
     private String resourcePath;
     private Map<String, String> resourcePaths = Collections.emptyMap();
     private Map<String, String> classResources = Collections.emptyMap();
+    private Map<? extends Enum<?>, String> enumResources = Collections.emptyMap();
     private boolean useClassNames;
     
     private String scope = REQUEST_SCOPE;
@@ -141,6 +142,11 @@ public class RequestDispatcherProvider e
     private boolean classResourceSupported(Class<?> type) {
         String typeName = type.getName();
         if (type.isEnum()) {
+            for (Object o : enumResources.keySet()) {
+                if (o.getClass().getName().equals(typeName)) {
+                    return true;
+                }
+            }
             for (String name : classResources.keySet()) {
                 if (name.startsWith(typeName)) {
                     return true;
@@ -200,6 +206,10 @@ public class RequestDispatcherProvider e
         
         String name = cls.getName();
         if (cls.isEnum()) {
+            String enumResource = enumResources.get(o);
+            if (enumResource != null) {
+                return enumResource;
+            }
             name += "." + o.toString();     
         }
         
@@ -338,6 +348,10 @@ public class RequestDispatcherProvider e
         this.saveParametersAsAttributes = saveParametersAsAttributes;
     }
 
+    public void setEnumResources(Map<? extends Enum<?>, String> enumResources)
{
+        this.enumResources = enumResources;
+    }
+
     protected static class HttpServletRequestFilter extends HttpServletRequestWrapper {
         
         private Map<String, String[]> params;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java?rev=1404611&r1=1404610&r2=1404611&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/RequestDispatcherProviderTest.java
Thu Nov  1 14:34:45 2012
@@ -36,6 +36,16 @@ public class RequestDispatcherProviderTe
         assertEquals("/test.jsp", p.getResourcePath(TestEnum.ONE.getClass(), TestEnum.ONE));
     }
     
+    @Test
+    public void testIsWriteableEnum2() {
+        
+        RequestDispatcherProvider p = new RequestDispatcherProvider();
+        p.setEnumResources(
+            Collections.singletonMap(TestEnum.ONE, "/test.jsp"));
+        assertTrue(p.isWriteable(TestEnum.ONE.getClass(), null, null, null));
+        assertEquals("/test.jsp", p.getResourcePath(TestEnum.ONE.getClass(), TestEnum.ONE));
+    }
+    
     private static enum TestEnum {
         ONE,
         TWO



Mime
View raw message