openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1606873 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/intercept/ webbeans-impl/src/main/java/org/apache/webbeans/portable/ webbeans-tck/
Date Mon, 30 Jun 2014 18:58:01 GMT
Author: rmannibucau
Date: Mon Jun 30 18:58:01 2014
New Revision: 1606873

URL: http://svn.apache.org/r1606873
Log:
@AroundConstruct context.proceed() returns null

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java?rev=1606873&r1=1606872&r2=1606873&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/AbstractInvocationContext.java
Mon Jun 30 18:58:01 2014
@@ -33,12 +33,11 @@ import org.apache.webbeans.util.Exceptio
 public abstract class AbstractInvocationContext<T> implements InvocationContext
 {
 
-    private Provider<T> target;
+    protected Provider<T> target;
     private AccessibleObject member;
-    private Object[] parameters;
+    protected Object[] parameters;
     private Map<String, Object> contextData;
     private Object timer;
-    private Object newInstance = null;
 
     public AbstractInvocationContext(Provider<T> target, AccessibleObject member, Object[]
parameters)
     {
@@ -104,19 +103,14 @@ public abstract class AbstractInvocation
     @Override
     public Object proceed() throws Exception
     {
-        if (newInstance != null) // already called
-        {
-            return newInstance;
-        }
+        return directProceed();
+    }
+
+    public Object directProceed() throws Exception
+    {
         try
         {
-            final Method m = getMethod();
-            if (m != null)
-            {
-                return m.invoke(target.get(), parameters);
-            }
-            newInstance = getConstructor().newInstance(parameters);
-            return newInstance;
+            return getMethod().invoke(target.get(), parameters);
         }
         catch (final InvocationTargetException ite)
         {
@@ -125,11 +119,6 @@ public abstract class AbstractInvocation
         }
     }
 
-    public Object getNewInstance()
-    {
-        return newInstance;
-    }
-
     // @Override
     public Constructor getConstructor()
     {

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java?rev=1606873&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ConstructorInterceptorInvocationContext.java
Mon Jun 30 18:58:01 2014
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.intercept;
+
+import org.apache.webbeans.util.ExceptionUtil;
+
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.inject.Provider;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+
+public class ConstructorInterceptorInvocationContext<T> extends InterceptorInvocationContext<T>
+{
+    protected Object newInstance = null;
+
+    public ConstructorInterceptorInvocationContext(final Provider<T> provider,
+                                                   final List<Interceptor<?>>
aroundConstructInterceptors,
+                                                   final Map<Interceptor<?>, ?>
interceptorInstances,
+                                                   final Constructor<T> cons, final
Object[] parameters)
+    {
+        super(provider, InterceptionType.AROUND_CONSTRUCT, aroundConstructInterceptors, interceptorInstances,
cons, parameters);
+    }
+
+    public Object getNewInstance()
+    {
+        return newInstance;
+    }
+
+    @Override
+    public Object directProceed() throws Exception
+    {
+        if (newInstance != null) // already called
+        {
+            return newInstance;
+        }
+        try
+        {
+            newInstance = getConstructor().newInstance(parameters);
+            return null;
+        }
+        catch (final InvocationTargetException ite)
+        {
+            // unpack the reflection Exception
+            throw ExceptionUtil.throwAsRuntimeException(ite.getCause());
+        }
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1606873&r1=1606872&r2=1606873&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Mon Jun 30 18:58:01 2014
@@ -26,8 +26,8 @@ import org.apache.webbeans.exception.Web
 import org.apache.webbeans.inject.InjectableConstructor;
 import org.apache.webbeans.inject.InjectableField;
 import org.apache.webbeans.inject.InjectableMethod;
+import org.apache.webbeans.intercept.ConstructorInterceptorInvocationContext;
 import org.apache.webbeans.intercept.DefaultInterceptorHandler;
-import org.apache.webbeans.intercept.InterceptorInvocationContext;
 import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
 import org.apache.webbeans.intercept.LifecycleInterceptorInvocationContext;
@@ -53,6 +53,7 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.inject.Inject;
+import javax.inject.Provider;
 import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
@@ -155,12 +156,10 @@ public class InjectionTargetImpl<T> exte
                 final Constructor<T> cons = getConstructor().getJavaMember();
                 final InjectableConstructor<T> injectableConstructor = new InjectableConstructor<T>(cons,
this, creationalContext);
                 final ConstructorInstanceProvider provider = new ConstructorInstanceProvider();
-                final InterceptorInvocationContext<T> invocationContext = new InterceptorInvocationContext<T>(
-                        provider,
-                        InterceptionType.AROUND_CONSTRUCT, aroundConstructInterceptors,
-                        interceptorInstances, cons, injectableConstructor.createParameters());
+                final ConstructorInterceptorInvocationContext<T> invocationContext
= new ConstructorInterceptorInvocationContext<T>(
+                        provider, aroundConstructInterceptors, interceptorInstances, cons,
injectableConstructor.createParameters());
                 provider.setContext(invocationContext);
-                final Object proceed = invocationContext.proceed();
+                invocationContext.proceed();
                 return (T) invocationContext.getNewInstance();
             }
             catch (final Exception e) // CDI 1.0
@@ -456,25 +455,18 @@ public class InjectionTargetImpl<T> exte
         return lifecycleInterceptors;
     }
 
-    private static class ConstructorInstanceProvider<T> implements javax.inject.Provider<T>
+    private static class ConstructorInstanceProvider<T> implements Provider<T>
     {
-        private InterceptorInvocationContext<T> context;
+        private ConstructorInterceptorInvocationContext<T> context;
 
         @Override
         public T get()
         {
-            try
-            {
-                return (T) context.getNewInstance();
-            }
-            catch (final Exception e)
-            {
-                throw new IllegalStateException(e);
-            }
+            return (T) context.getNewInstance();
         }
 
         // this dependency sucks, we should find something a bit more sexy
-        public void setContext(final InterceptorInvocationContext<T> context)
+        public void setContext(final ConstructorInterceptorInvocationContext<T> context)
         {
             this.context = context;
         }

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1606873&r1=1606872&r2=1606873&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Mon Jun 30 18:58:01 2014
@@ -19,7 +19,7 @@
   <test name="JSR-346 TCK">
     <classes>
       <class
-          name="org.jboss.cdi.tck.tests.deployment.exclude.ExcludeFiltersTest" />
+          name="org.jboss.cdi.tck.interceptors.tests.contract.aroundConstruct.AroundConstructTest"
/>
     </classes>
     <groups>
       <run>



Mime
View raw message