deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1069 evaluate interceptors for producer-methods
Date Tue, 22 Mar 2016 20:58:38 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master f58e3259c -> 9fbb88be9


DELTASPIKE-1069 evaluate interceptors for producer-methods

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/9fbb88be
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/9fbb88be
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/9fbb88be

Branch: refs/heads/master
Commit: 9fbb88be997ddd8337d0de387eab0d98f1844c36
Parents: f58e325
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Tue Mar 22 21:58:28 2016 +0100
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Tue Mar 22 21:58:28 2016 +0100

----------------------------------------------------------------------
 .../proxy/api/DeltaSpikeProxyFactory.java       |  10 +-
 .../proxy/spi/DummyInvocationHandler.java       |  31 ------
 .../proxy/spi/EnableInterceptorsDelegate.java   |  42 --------
 .../spi/EnableInterceptorsInterceptor.java      |  43 --------
 .../spi/EnableInterceptorsProxyFactory.java     |  85 ---------------
 .../util/EnableInterceptorsInterceptor.java     |  43 ++++++++
 .../util/EnableInterceptorsProxyFactory.java    | 105 +++++++++++++++++++
 .../api/src/main/resources/META-INF/beans.xml   |   2 +-
 8 files changed, 158 insertions(+), 203 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
index e2db0e3..7721166 100644
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/api/DeltaSpikeProxyFactory.java
@@ -32,7 +32,6 @@ import javax.interceptor.InterceptorBinding;
 
 import org.apache.deltaspike.core.util.ClassUtils;
 import org.apache.deltaspike.core.util.ServiceUtils;
-import org.apache.deltaspike.proxy.spi.DummyInvocationHandler;
 import org.apache.deltaspike.proxy.spi.ProxyClassGenerator;
 
 public abstract class DeltaSpikeProxyFactory
@@ -78,6 +77,15 @@ public abstract class DeltaSpikeProxyFactory
         }
         return GeneratorHolder.generator;
     }
+    
+    private static class DummyInvocationHandler implements InvocationHandler
+    {
+        @Override
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+        {
+            return null;
+        }
+    }
 
     public <T> Class<T> resolveAlreadyDefinedProxyClass(Class<T> targetClass)
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/DummyInvocationHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/DummyInvocationHandler.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/DummyInvocationHandler.java
deleted file mode 100644
index a8c9b53..0000000
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/DummyInvocationHandler.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.deltaspike.proxy.spi;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-public class DummyInvocationHandler implements InvocationHandler
-{
-    @Override
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
-    {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsDelegate.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsDelegate.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsDelegate.java
deleted file mode 100644
index d736340..0000000
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsDelegate.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.deltaspike.proxy.spi;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-/**
- * {@link InvocationHandler} to delegate every method call to an provided object instance.
- */
-public class EnableInterceptorsDelegate implements InvocationHandler, Serializable
-{
-    private final Object instance;
-    
-    public EnableInterceptorsDelegate(Object instance)
-    {
-        this.instance = instance;
-    }
-    
-    @Override
-    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
-    {
-        return method.invoke(instance, args);
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsInterceptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsInterceptor.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsInterceptor.java
deleted file mode 100644
index 5ffa4e7..0000000
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsInterceptor.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.deltaspike.proxy.spi;
-
-import java.io.Serializable;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import org.apache.deltaspike.proxy.api.EnableInterceptors;
-
-@Interceptor
-@EnableInterceptors
-public class EnableInterceptorsInterceptor implements Serializable
-{
-    @Inject
-    private BeanManager beanManager;
-    
-    @AroundInvoke
-    public Object wrapBeanCandidate(InvocationContext invocationContext) throws Exception
-    {
-        Object producerResult = invocationContext.proceed();
-        
-        return EnableInterceptorsProxyFactory.wrap(producerResult, beanManager);
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsProxyFactory.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsProxyFactory.java
deleted file mode 100644
index 508be8b..0000000
--- a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/spi/EnableInterceptorsProxyFactory.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.deltaspike.proxy.spi;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import javax.enterprise.inject.spi.BeanManager;
-import org.apache.deltaspike.proxy.api.DeltaSpikeProxyFactory;
-
-public class EnableInterceptorsProxyFactory extends DeltaSpikeProxyFactory
-{
-    private static final EnableInterceptorsProxyFactory INSTANCE = new EnableInterceptorsProxyFactory();
-    
-    public static EnableInterceptorsProxyFactory getInstance()
-    {
-        return INSTANCE;
-    }
-   
-    public static <T> T wrap(T obj, BeanManager beanManager)
-    {
-        if (obj == null)
-        {
-            throw new IllegalArgumentException("obj must not be null!");
-        }
-        
-        // generate proxy
-        Class proxyClass = EnableInterceptorsProxyFactory.getInstance().getProxyClass(beanManager,
-                obj.getClass(), EnableInterceptorsDelegate.class);
-
-        // delegate method calls to our original instance from the wrapped producer method
-        EnableInterceptorsDelegate delegate = new EnableInterceptorsDelegate(obj);
-
-        try
-        {
-            // instantiate proxy
-            Constructor constructor = proxyClass.getConstructor(EnableInterceptorsDelegate.class);
-            return (T) constructor.newInstance(delegate);
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException("Could not create proxy instance by class " + obj.getClass(),
e);
-        }
-    }
-    
-    @Override
-    protected ArrayList<Method> getDelegateMethods(Class<?> targetClass, ArrayList<Method>
allMethods)
-    {
-        // the default #filterInterceptMethods filters all non-public, final and abstract
methods
-        // which means actually every publich proxyable method
-        // as we need to delegate method call to the original object instance -> proxy
all public methods
-        ArrayList<Method> delegateMethods = super.filterInterceptMethods(targetClass,
allMethods);
-        return delegateMethods;
-    }
-
-    @Override
-    protected ArrayList<Method> filterInterceptMethods(Class<?> targetClass,
ArrayList<Method> allMethods)
-    {
-        // we don't need to overwrite methods to just execute interceptors
-        // all method call are delegated to our EnableInterceptorsDelegate, to delegate to
the original object instance
-        return null;
-    }
-
-    @Override
-    protected String getProxyClassSuffix()
-    {
-        return "$$DSInterceptorProxy";
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsInterceptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsInterceptor.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsInterceptor.java
new file mode 100644
index 0000000..7990201
--- /dev/null
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsInterceptor.java
@@ -0,0 +1,43 @@
+/*
+ * 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.deltaspike.proxy.util;
+
+import java.io.Serializable;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import org.apache.deltaspike.proxy.api.EnableInterceptors;
+
+@Interceptor
+@EnableInterceptors
+public class EnableInterceptorsInterceptor implements Serializable
+{
+    @Inject
+    private BeanManager beanManager;
+    
+    @AroundInvoke
+    public Object wrapBeanCandidate(InvocationContext invocationContext) throws Exception
+    {
+        Object producerResult = invocationContext.proceed();
+        
+        return EnableInterceptorsProxyFactory.wrap(producerResult, beanManager);
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsProxyFactory.java
b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsProxyFactory.java
new file mode 100644
index 0000000..c39f95c
--- /dev/null
+++ b/deltaspike/modules/proxy/api/src/main/java/org/apache/deltaspike/proxy/util/EnableInterceptorsProxyFactory.java
@@ -0,0 +1,105 @@
+/*
+ * 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.deltaspike.proxy.util;
+
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import javax.enterprise.inject.spi.BeanManager;
+import org.apache.deltaspike.proxy.api.DeltaSpikeProxyFactory;
+
+public class EnableInterceptorsProxyFactory extends DeltaSpikeProxyFactory
+{
+    private static final EnableInterceptorsProxyFactory INSTANCE = new EnableInterceptorsProxyFactory();
+
+    private EnableInterceptorsProxyFactory()
+    {
+        
+    }
+
+    public static <T> T wrap(T obj, BeanManager beanManager)
+    {
+        if (obj == null)
+        {
+            throw new IllegalArgumentException("obj must not be null!");
+        }
+        
+        // generate proxy
+        Class proxyClass = INSTANCE.getProxyClass(beanManager, obj.getClass(), EnableInterceptorsDelegate.class);
+
+        // delegate method calls to our original instance from the wrapped producer method
+        EnableInterceptorsDelegate delegate = new EnableInterceptorsDelegate(obj);
+
+        try
+        {
+            // instantiate proxy
+            Constructor constructor = proxyClass.getConstructor(EnableInterceptorsDelegate.class);
+            return (T) constructor.newInstance(delegate);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException("Could not create proxy instance by class " + obj.getClass(),
e);
+        }
+    }
+    
+    @Override
+    protected ArrayList<Method> getDelegateMethods(Class<?> targetClass, ArrayList<Method>
allMethods)
+    {
+        // the default #filterInterceptMethods filters all non-public, final and abstract
methods
+        // which means actually every publich proxyable method
+        // as we need to delegate method call to the original object instance -> proxy
all public methods
+        ArrayList<Method> delegateMethods = super.filterInterceptMethods(targetClass,
allMethods);
+        return delegateMethods;
+    }
+
+    @Override
+    protected ArrayList<Method> filterInterceptMethods(Class<?> targetClass,
ArrayList<Method> allMethods)
+    {
+        // we don't need to overwrite methods to just execute interceptors
+        // all method call are delegated to our EnableInterceptorsDelegate, to delegate to
the original object instance
+        return null;
+    }
+
+    @Override
+    protected String getProxyClassSuffix()
+    {
+        return "$$DSInterceptorProxy";
+    }
+    
+    /**
+     * {@link InvocationHandler} to delegate every method call to an provided object instance.
+     */
+    private static class EnableInterceptorsDelegate implements InvocationHandler, Serializable
+    {
+        private final Object instance;
+
+        public EnableInterceptorsDelegate(Object instance)
+        {
+            this.instance = instance;
+        }
+
+        @Override
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+        {
+            return method.invoke(instance, args);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/9fbb88be/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml b/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
index 682d4c9..0d2c152 100644
--- a/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
+++ b/deltaspike/modules/proxy/api/src/main/resources/META-INF/beans.xml
@@ -21,6 +21,6 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
     <interceptors>
-        <class>org.apache.deltaspike.proxy.spi.EnableInterceptorsInterceptor</class>
+        <class>org.apache.deltaspike.proxy.util.EnableInterceptorsInterceptor</class>
     </interceptors>
 </beans>


Mime
View raw message