cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r739018 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: impl/RequestPreprocessor.java impl/UriBuilderImpl.java impl/UriInfoImpl.java utils/AnnotationUtils.java
Date Thu, 29 Jan 2009 21:15:50 GMT
Author: dkulp
Date: Thu Jan 29 21:15:50 2009
New Revision: 739018

URL: http://svn.apache.org/viewvc?rev=739018&view=rev
Log:
Cleanup some generics/annotation code

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java?rev=739018&r1=739017&r2=739018&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestPreprocessor.java
Thu Jan 29 21:15:50 2009
@@ -32,13 +32,12 @@
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
     
-    @SuppressWarnings("unchecked")
     public RequestPreprocessor(Map<Object, Object> languageMappings,
                            Map<Object, Object> extensionMappings) {
-        this.languageMappings = 
-            languageMappings == null ? Collections.EMPTY_MAP : languageMappings;
+        this.languageMappings =
+            languageMappings == null ? Collections.emptyMap() : languageMappings;
         this.extensionMappings = 
-            extensionMappings == null ? Collections.EMPTY_MAP : extensionMappings;
+            extensionMappings == null ? Collections.emptyMap() : extensionMappings;
     }
 
     public String preprocess(Message m, UriInfo u) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=739018&r1=739017&r2=739018&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Thu Jan 29 21:15:50 2009
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.jaxrs.impl;
 
-import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -164,22 +163,21 @@
         return this;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public UriBuilder path(Class resource) throws IllegalArgumentException {
         if (resource == null) {
             throw new IllegalArgumentException("resource is null");
         }
-        Annotation ann = resource.getAnnotation(Path.class);
+        Class<?> cls = resource;
+        Path ann = cls.getAnnotation(Path.class);
         if (ann == null) {
             throw new IllegalArgumentException("Class '" + resource.getCanonicalName()
                                                + "' is not annotated with Path");
         }
         // path(String) decomposes multi-segment path when necessary
-        return path(((Path)ann).value());
+        return path(ann.value());
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public UriBuilder path(Class resource, String method) throws IllegalArgumentException
{
         if (resource == null) {
@@ -188,10 +186,10 @@
         if (method == null) {
             throw new IllegalArgumentException("method is null");
         }
-        Annotation foundAnn = null;
+        Path foundAnn = null;
         for (Method meth : resource.getMethods()) {
             if (meth.getName().equals(method)) {
-                Annotation ann = meth.getAnnotation(Path.class);
+                Path ann = meth.getAnnotation(Path.class);
                 if (foundAnn != null && ann != null) {
                     throw new IllegalArgumentException("Multiple Path annotations for '"
+ method
                                                        + "' overloaded method");
@@ -203,7 +201,7 @@
             throw new IllegalArgumentException("No Path annotation for '" + method + "' method");
         }
         // path(String) decomposes multi-segment path when necessary
-        return path(((Path)foundAnn).value());
+        return path(foundAnn.value());
     }
 
     @Override
@@ -211,13 +209,13 @@
         if (method == null) {
             throw new IllegalArgumentException("method is null");
         }
-        Annotation ann = method.getAnnotation(Path.class);
+        Path ann = method.getAnnotation(Path.class);
         if (ann == null) {
             throw new IllegalArgumentException("Method '" + method.getClass().getCanonicalName()
+ "."
                                                + method.getName() + "' is not annotated with
Path");
         }
         // path(String) decomposes multi-segment path when necessary
-        return path(((Path)ann).value());
+        return path(ann.value());
     }
 
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=739018&r1=739017&r2=739018&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Thu
Jan 29 21:15:50 2009
@@ -152,9 +152,9 @@
             for (MethodInvocationInfo invocation : stack) {
                 OperationResourceInfo ori = invocation.getMethodInfo();
                 Path[] paths = {
-                    (Path)AnnotationUtils.getClassAnnotation(ori.getClassResourceInfo().getResourceClass(),
+                    AnnotationUtils.getClassAnnotation(ori.getClassResourceInfo().getResourceClass(),
                                                              Path.class),
-                    (Path)AnnotationUtils.getMethodAnnotation(ori.getAnnotatedMethod(), Path.class)
+                    AnnotationUtils.getMethodAnnotation(ori.getAnnotatedMethod(), Path.class)
                 };
                 for (Path p : paths) {
                     if (p != null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=739018&r1=739017&r2=739018&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Thu Jan 29 21:15:50 2009
@@ -149,14 +149,13 @@
         return value;
     }
     
-    @SuppressWarnings("unchecked")
     public static <T> T getAnnotation(Annotation[] anns, Class<T> type) { 
         if (anns == null) {
             return null;
         }
         for (Annotation a : anns) {    
             if (a.annotationType() == type) {
-                return (T)a;
+                return type.cast(a);
             }
         }
         return null;
@@ -221,17 +220,17 @@
         return null;
     }
     
-    public static Annotation getMethodAnnotation(Method m,
-                                                 Class<? extends Annotation> aClass)
{
+    public static <A extends Annotation> A getMethodAnnotation(Method m,
+                                                 Class<A> aClass) {
         return m == null ? null : m.getAnnotation(aClass);
     }
     
-    public static Annotation getClassAnnotation(Class<?> c, 
-                                                Class<? extends Annotation> aClass)
{
+    public static <A extends Annotation> A getClassAnnotation(Class<?> c,
+                                                              Class<A> aClass) { 
         if (c == null) {
             return null;
         }
-        Annotation p = c.getAnnotation(aClass);
+        A p = c.getAnnotation(aClass);
         if (p != null) {
             return p;
         }



Mime
View raw message