cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <sbery...@progress.com>
Subject Re: svn commit: r785866
Date Thu, 18 Jun 2009 08:58:47 GMT
Thanks Benson :-)

----- Original Message ----- 
From: <bimargulies@apache.org>
To: <commits@cxf.apache.org>
Sent: Thursday, June 18, 2009 1:31 AM
Subject: svn commit: r785866 - in /cxf/trunk/rt/frontend/jaxrs/src: 
main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java


> Author: bimargulies
> Date: Thu Jun 18 00:31:35 2009
> New Revision: 785866
>
> URL: http://svn.apache.org/viewvc?rev=785866&view=rev
> Log:
> Fix Aegis support for JAX-RS to deal with generics.
>
> Modified:
>    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
>    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
>
> Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
> URL: 
> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java?rev=785866&r1=785865&r2=785866&view=diff
> ==============================================================================
> --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
(original)
> +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractAegisProvider.java
Thu Jun 18 00:31:35 2009
> @@ -20,6 +20,9 @@
> package org.apache.cxf.jaxrs.provider;
>
> import java.lang.annotation.Annotation;
> +import java.lang.reflect.Array;
> +import java.lang.reflect.GenericArrayType;
> +import java.lang.reflect.ParameterizedType;
> import java.lang.reflect.Type;
> import java.util.HashSet;
> import java.util.Map;
> @@ -63,10 +66,30 @@
>             }
>         }
>
> -        return getClassContext(type);
> +        return getClassContext(type, genericType);
>     }
>
> -    private AegisContext getClassContext(Class<?> type) {
> +
> +    private void addType(Set<Class<?>> rootClasses, Type cls, boolean allowArray)
{
> +        if (cls instanceof Class) {
> +            if (((Class)cls).isArray() && !allowArray) {
> +                rootClasses.add(((Class)cls).getComponentType());
> +            } else {
> +                rootClasses.add((Class)cls);
> +            }
> +        } else if (cls instanceof ParameterizedType) {
> +            for (Type t2 : ((ParameterizedType)cls).getActualTypeArguments()) {
> +                addType(rootClasses, t2, false);
> +            }
> +        } else if (cls instanceof GenericArrayType) {
> +            GenericArrayType gt = (GenericArrayType)cls;
> +            Class ct = (Class) gt.getGenericComponentType();
> +            ct = Array.newInstance(ct, 0).getClass();
> +
> +            rootClasses.add(ct);
> +        }
> +    }
> +    private AegisContext getClassContext(Class<?> type, Type genericType) {
>         synchronized (classContexts) {
>             AegisContext context = classContexts.get(type);
>             if (context == null) {
> @@ -75,6 +98,9 @@
>                 context.setReadXsiTypes(true);
>                 Set<Class<?>> rootClasses = new HashSet<Class<?>>();
>                 rootClasses.add(type);
> +                if (!(genericType instanceof Class)) {
> +                    addType(rootClasses, genericType, true);
> +                }
>                 context.setRootClasses(rootClasses);
>                 context.initialize();
>                 classContexts.put(type, context);
>
> Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
> URL: 
> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java?rev=785866&r1=785865&r2=785866&view=diff
> ==============================================================================
> --- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
(original)
> +++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Thu Jun 18 00:31:35 2009
> @@ -21,6 +21,8 @@
>
> import java.io.ByteArrayInputStream;
> import java.io.ByteArrayOutputStream;
> +import java.lang.reflect.Method;
> +import java.lang.reflect.Type;
> import java.util.HashMap;
> import java.util.Map;
>
> @@ -30,7 +32,6 @@
> import org.apache.cxf.jaxrs.fortest.AegisTestBean;
>
> import org.junit.Assert;
> -import org.junit.Ignore;
> import org.junit.Test;
>
> public class AegisProviderTest extends Assert {
> @@ -79,9 +80,13 @@
>         assertEquals(SIMPLE_BEAN_XML, xml);
>     }
>
> +    private static interface InterfaceWithMap {
> +        Map<AegisTestBean, String> mapFunction();
> +    }
> +
>     @SuppressWarnings("unchecked")
>     @Test
> -    @Ignore
> +    @org.junit.Ignore
>     public void testReadWriteComplexMap() throws Exception {
>         Map<AegisTestBean, String> map = new HashMap<AegisTestBean, String>();
>         AegisTestBean bean = new AegisTestBean();
> @@ -98,7 +103,12 @@
>
>         MessageBodyReader<Object> reader = new AegisElementProvider();
>         byte[] simpleBytes = xml.getBytes("utf-8");
> -        Object beanObject = reader.readFrom((Class)Map.class, null, null,
> +
> +        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
> +        Method method = iwithMapClass.getMethod("mapFunction");
> +        Type mapType = method.getGenericReturnType();
> +
> +        Object beanObject = reader.readFrom((Class)Map.class, mapType, null,
>                                           null, null, new ByteArrayInputStream(simpleBytes));
>         Map<AegisTestBean, String> map2 = (Map)beanObject;
>         AegisTestBean bean2 = map2.keySet().iterator().next();
>
>
> 


Mime
View raw message