openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1607040 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java webbeans-tck/testng-dev.xml
Date Tue, 01 Jul 2014 10:58:45 GMT
Author: rmannibucau
Date: Tue Jul  1 10:58:44 2014
New Revision: 1607040

URL: http://svn.apache.org/r1607040
Log:
InjectionPoint injection references the real type even if that's from an Instance

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java?rev=1607040&r1=1607039&r2=1607040&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointImpl.java
Tue Jul  1 10:58:44 2014
@@ -19,10 +19,8 @@
 package org.apache.webbeans.inject.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
@@ -51,6 +49,7 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.event.EventUtil;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.OwbCustomObjectInputStream;
 import org.apache.webbeans.util.WebBeansUtil;
 
 class InjectionPointImpl implements InjectionPoint, Serializable
@@ -215,28 +214,11 @@ class InjectionPointImpl implements Inje
         
     }
     
-    public class CustomObjectInputStream extends ObjectInputStream
-    {
-        private ClassLoader classLoader;
-
-        public CustomObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException
-        {
-            super(in);
-            this.classLoader = classLoader;
-        }
-        
-        @Override
-        protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException
-        {
-            return Class.forName(desc.getName(), false, classLoader);
-        }
-    }
-
     @SuppressWarnings("unchecked")
     private void readObject(java.io.ObjectInputStream inp) throws IOException, ClassNotFoundException
     {
 
-        ObjectInputStream in = new CustomObjectInputStream(inp, WebBeansUtil.getCurrentClassLoader());
+        ObjectInputStream in = new OwbCustomObjectInputStream(inp, WebBeansUtil.getCurrentClassLoader());
 
         Class<?> beanClass = (Class<?>)in.readObject();
         Set<Annotation> anns = new HashSet<Annotation>();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java?rev=1607040&r1=1607039&r2=1607040&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
Tue Jul  1 10:58:44 2014
@@ -18,13 +18,27 @@
  */
 package org.apache.webbeans.portable;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.Map;
+import java.util.Set;
 
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.OwbCustomObjectInputStream;
+import org.apache.webbeans.util.WebBeansUtil;
 
 public class InjectionPointProducer extends AbstractProducer<InjectionPoint>
 {
@@ -48,7 +62,25 @@ public class InjectionPointProducer exte
         }
         try
         {
-            return creationalContextImpl.getInjectionPoint();
+            final InjectionPoint injectionPoint = creationalContextImpl.getInjectionPoint();
+            if (injectionPoint == null)
+            {
+                return null;
+            }
+
+            final Type type = injectionPoint.getType();
+            if (ParameterizedType.class.isInstance(type))
+            {
+                final ParameterizedType parameterizedType = ParameterizedType.class.cast(type);
+                if (parameterizedType.getRawType() == Instance.class)
+                {
+                    final Bean<InjectionPoint> bean = creationalContextImpl.getBean();
+                    return new InjectionPointDelegate(
+                            injectionPoint,
+                            bean.getBeanClass() != null ? bean.getBeanClass() : parameterizedType.getActualTypeArguments()[0]);
+                }
+            }
+            return injectionPoint;
         }
         finally
         {
@@ -61,4 +93,72 @@ public class InjectionPointProducer exte
     {
         // nothing to do
     }
+
+    private class InjectionPointDelegate implements InjectionPoint, Serializable
+    {
+        private InjectionPoint ip;
+        private Type type;
+
+        public InjectionPointDelegate(final InjectionPoint injectionPoint, final Type type)
+        {
+            this.ip = injectionPoint;
+            this.type = type;
+        }
+
+        @Override
+        public Type getType()
+        {
+            return type;
+        }
+
+        @Override
+        public Set<Annotation> getQualifiers()
+        {
+            return ip.getQualifiers();
+        }
+
+        @Override
+        public Bean<?> getBean()
+        {
+            return ip.getBean();
+        }
+
+        @Override
+        public Member getMember()
+        {
+            return ip.getMember();
+        }
+
+        @Override
+        public Annotated getAnnotated()
+        {
+            return ip.getAnnotated();
+        }
+
+        @Override
+        public boolean isDelegate()
+        {
+            return ip.isDelegate();
+        }
+
+        @Override
+        public boolean isTransient()
+        {
+            return ip.isTransient();
+        }
+
+        private void readObject(final ObjectInputStream inp) throws IOException, ClassNotFoundException
+        {
+            final OwbCustomObjectInputStream owbCustomObjectInputStream = new OwbCustomObjectInputStream(inp,
WebBeansUtil.getCurrentClassLoader());
+            type = Type.class.cast(owbCustomObjectInputStream.readObject());
+            ip = InjectionPoint.class.cast(owbCustomObjectInputStream.readObject());
+        }
+
+        private void writeObject(final ObjectOutputStream op) throws IOException
+        {
+            final ObjectOutputStream out = new ObjectOutputStream(op);
+            out.writeObject(type);
+            out.writeObject(ip);
+        }
+    }
 }

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1607040&r1=1607039&r2=1607040&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Tue Jul  1 10:58:44 2014
@@ -19,7 +19,7 @@
   <test name="JSR-346 TCK">
     <classes>
       <class
-          name="org.jboss.cdi.tck.tests.extensions.beanManager.producer.SyntheticProducerTest"
/>
+          name="org.jboss.cdi.tck.tests.lookup.injectionpoint.dynamic.DynamicInjectionPointTest"
/>
     </classes>
     <groups>
       <run>



Mime
View raw message