wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1023975 - in /incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal: providers/entity/xml/AbstractJAXBProvider.java registry/metadata/ResourceMetadataCollector.java
Date Mon, 18 Oct 2010 20:11:31 GMT
Author: rott
Date: Mon Oct 18 20:11:31 2010
New Revision: 1023975

URL: http://svn.apache.org/viewvc?rev=1023975&view=rev
Log:
move @XmlElement annotation scanning to ResourceMetadataCollector from AbstractJAXBProvider
to improve performance, simplify JAXB path

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java?rev=1023975&r1=1023974&r2=1023975&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
Mon Oct 18 20:11:31 2010
@@ -44,7 +44,6 @@ import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRegistry;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
@@ -85,8 +84,6 @@ public abstract class AbstractJAXBProvid
     private static final SoftConcurrentMap<Class<?>, Boolean>        jaxbIsXMLTypeCache
            =
                                                                                         
               new SoftConcurrentMap<Class<?>, Boolean>();
 
-    private static final SoftConcurrentMap<Class<?>, Class<?>>       xmlElementConcreteClassCache
  =
-                                                                                        
               new SoftConcurrentMap<Class<?>, Class<?>>();
 
     // if JAXB objects implement an interface where that interface has
     // @XmlJavaTypeAdapter annotation, or
@@ -485,31 +482,11 @@ public abstract class AbstractJAXBProvid
         return type;
     }
     
-    private Class<?> getConcreteTypeFromXmlElementAnno(Class<?> type, Annotation[]
annotations) {
-        Class<?> ret = xmlElementConcreteClassCache.get(type);
-        if (ret == null) {
-            XmlElement xmlElement = getXmlElementAnno(type, annotations);
-            if (xmlElement != null) {
-                Type xmlElementType = xmlElement.type();
-                if (xmlElementType != null) {
-                    ret = (Class<?>)xmlElementType;
-                }
-            }
-            if (ret == null)
-                ret = type;
-            xmlElementConcreteClassCache.put(type, ret);
-        }
-        return ret;
-    }
 
     public Class<?> getConcreteTypeFromTypeMap(Class<?> type, Annotation[] annotations)
{
         Class<?> concreteType = jaxbTypeMapCache.get(type);
         if (concreteType == null) {
             concreteType = getConcreteTypeFromAdapter(type, annotations);
-            // @XmlJavaTypeAdapter takes priority over XmlElement
-            if (concreteType == type) {
-                concreteType = getConcreteTypeFromXmlElementAnno(type, annotations);
-            }
             jaxbTypeMapCache.put(type, concreteType);
         }
         return concreteType;
@@ -569,22 +546,6 @@ public abstract class AbstractJAXBProvid
         return xmlJavaTypeAdapter;
     }
     
-    /**
-     * @param type
-     * @param annotations
-     * @return
-     */
-    private XmlElement getXmlElementAnno(Type type,
-            Annotation[] annotations) {
-        XmlElement xmlElement = null;
-        for (int i = 0; (annotations != null) && i < annotations.length; i++)
{
-            if (annotations[i].annotationType() == XmlElement.class) {
-                xmlElement = (XmlElement)annotations[i];
-                break;
-            }
-        }
-        return xmlElement;
-    }
     
     @SuppressWarnings("unchecked")
     protected Object unmarshalWithXmlAdapter(Object obj, Type type, Annotation[] annotations)
{

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java?rev=1023975&r1=1023974&r2=1023975&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/registry/metadata/ResourceMetadataCollector.java
Mon Oct 18 20:11:31 2010
@@ -37,6 +37,7 @@ import javax.ws.rs.HttpMethod;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
+import javax.xml.bind.annotation.XmlElement;
 
 import org.apache.wink.common.DynamicResource;
 import org.apache.wink.common.annotations.Parent;
@@ -470,7 +471,7 @@ public class ResourceMetadataCollector e
 
     private void parseMethodParameters(Method method, MethodMetadata methodMetadata) {
         Annotation[][] parameterAnnotations = method.getParameterAnnotations();
-        Type[] paramTypes = method.getGenericParameterTypes();
+        Type[] paramTypes = getParamTypesFilterByXmlElementAnnotation(method);
         boolean entityParamExists = false;
         for (int pos = 0, limit = paramTypes.length; pos < limit; pos++) {
             Injectable fp =
@@ -494,6 +495,25 @@ public class ResourceMetadataCollector e
         }
     }
 
+    private Type[] getParamTypesFilterByXmlElementAnnotation(Method method) {
+        int index = 0;
+        Type[] paramTypes = method.getGenericParameterTypes();
+        Annotation[][] paramAnnotations = method.getParameterAnnotations();
+        for(Annotation[] annos: paramAnnotations) {
+            for(Annotation anno: annos) {
+                if (anno.annotationType().equals(XmlElement.class)) {
+                    XmlElement xmlElement = (XmlElement)anno;
+                    Type type = xmlElement.type();
+                    if (type != null) {
+                        paramTypes[index] = type;
+                    }
+                }
+            }
+            index++;
+        }
+        return paramTypes;
+    }
+
     private void mergeFormalParameterMetadata(MethodMetadata metadata, Method method) {
         logger.trace("mergeFormalParameterMetadata({})", new Object[] {metadata, method});
         Type[] parameterTypes = method.getGenericParameterTypes();



Mime
View raw message