[jboss-cvs] JBossAS SVN: r107168 - in projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor: util/proxy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 28 13:23:18 EDT 2010
Author: marius.bogoevici
Date: 2010-07-28 13:23:17 -0400 (Wed, 28 Jul 2010)
New Revision: 107168
Removed:
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/SubclassingInterceptorMethodHandler.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/proxy/TargetInstanceProxyMethodHandler.java
Modified:
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorMethodHandler.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java
Log:
removed SubclassingInterceptorMethodHandler
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorMethodHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorMethodHandler.java 2010-07-28 17:07:50 UTC (rev 107167)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorMethodHandler.java 2010-07-28 17:23:17 UTC (rev 107168)
@@ -11,8 +11,9 @@
import java.util.List;
import java.util.Map;
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyObject;
import org.jboss.interceptor.reader.InterceptorMetadataUtils;
-import org.jboss.interceptor.reader.ReflectiveClassMetadata;
import org.jboss.interceptor.spi.instance.InterceptorInstantiator;
import org.jboss.interceptor.spi.metadata.ClassMetadata;
import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
@@ -21,21 +22,35 @@
import org.jboss.interceptor.util.InterceptionTypeRegistry;
import org.jboss.interceptor.util.InterceptionUtils;
import org.jboss.interceptor.util.ReflectionUtils;
-import org.jboss.interceptor.util.proxy.TargetInstanceProxyMethodHandler;
/**
* @author Marius Bogoevici
*/
-public class InterceptorMethodHandler extends TargetInstanceProxyMethodHandler implements Serializable
+public class InterceptorMethodHandler implements MethodHandler, Serializable
{
private Map<ClassMetadata<?>, Object> interceptorHandlerInstances = new HashMap<ClassMetadata<?>, Object>();
private InterceptorMetadata targetClassInterceptorMetadata;
private InterceptionModel<ClassMetadata<?>, ClassMetadata> interceptionModel;
+ private Object targetInstance;
- public InterceptorMethodHandler(Object target, ClassMetadata<?> targetClass, InterceptionModel<ClassMetadata<?>, ClassMetadata> interceptionModel, InterceptorInstantiator<ClassMetadata<?>, ?> interceptorInstantiator, InterceptorMetadata targetClassMetadata)
+ private static MethodHandler DEFAULT_METHOD_HANDLER = new MethodHandler()
{
- super(target, targetClass != null ? targetClass : ReflectiveClassMetadata.of(target.getClass()));
+
+ public Object invoke(Object self, Method m,
+ Method proceed, Object[] args)
+ throws Exception
+ {
+ return proceed.invoke(self, args);
+ }
+ };
+
+ private boolean proxy;
+
+ public InterceptorMethodHandler(Object targetInstance, InterceptionModel<ClassMetadata<?>, ClassMetadata> interceptionModel, InterceptorInstantiator<ClassMetadata<?>, ?> interceptorInstantiator, InterceptorMetadata targetClassMetadata, boolean proxy)
+ {
+ this.targetInstance = targetInstance;
+
if (interceptionModel == null)
{
throw new IllegalArgumentException("Interception model must not be null");
@@ -44,51 +59,56 @@
{
throw new IllegalArgumentException("Interception handler factory must not be null");
}
-
-
this.interceptionModel = interceptionModel;
-
for (ClassMetadata<?> interceptorReference : this.interceptionModel.getAllInterceptors())
{
- interceptorHandlerInstances.put(interceptorReference, ((InterceptorInstantiator) interceptorInstantiator).createFor(interceptorReference));
+ interceptorHandlerInstances.put(interceptorReference, interceptorInstantiator.createFor(interceptorReference));
}
targetClassInterceptorMetadata = targetClassMetadata;
+ this.proxy = proxy;
}
- public Object doInvoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
+ public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
{
ReflectionUtils.ensureAccessible(thisMethod);
if (null != proceed)
{
- if (!org.jboss.interceptor.util.InterceptionUtils.isInterceptionCandidate(thisMethod))
+ if (!InterceptionUtils.isInterceptionCandidate(thisMethod))
{
- return thisMethod.invoke(getTargetInstance(), args);
+ if (isProxy())
+ {
+ return thisMethod.invoke(targetInstance, args);
+ }
+ else
+ {
+ return proceed.invoke(self, args);
+ }
}
if (InterceptionTypeRegistry.isSupported(InterceptionType.AROUND_TIMEOUT) && thisMethod.isAnnotationPresent(InterceptionTypeRegistry.getAnnotationClass(InterceptionType.AROUND_TIMEOUT)))
{
- return executeInterception(thisMethod, args, InterceptionType.AROUND_TIMEOUT);
+ return executeInterception(isProxy() ? null : self, thisMethod, thisMethod, args, InterceptionType.AROUND_TIMEOUT);
}
else
{
- return executeInterception(thisMethod, args, InterceptionType.AROUND_INVOKE);
+ return executeInterception(isProxy() ? null : self, thisMethod, thisMethod, args, InterceptionType.AROUND_INVOKE);
}
}
else
{
if (thisMethod.getName().equals(InterceptionUtils.POST_CONSTRUCT))
{
- return executeInterception(null, null, InterceptionType.POST_CONSTRUCT);
+ return executeInterception(isProxy() ? null : self, null, null, null, InterceptionType.POST_CONSTRUCT);
}
else if (thisMethod.getName().equals(InterceptionUtils.PRE_DESTROY))
{
- return executeInterception(null, null, InterceptionType.PRE_DESTROY);
+ return executeInterception(isProxy() ? null : self, null, null, null, InterceptionType.PRE_DESTROY);
}
}
return null;
}
- private Object executeInterception(Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable
+ private Object executeInterception(Object self, Method proceedingMethod, Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable
{
List<ClassMetadata> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod);
@@ -101,18 +121,25 @@
if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty())
{
- interceptorInvocations.add(new InterceptorInvocation(getTargetInstance(), InterceptorMetadataUtils.readMetadataForTargetClass(getTargetClass()), interceptionType));
+ interceptorInvocations.add(new InterceptorInvocation(isProxy() ? targetInstance : self, targetClassInterceptorMetadata, interceptionType));
}
- InterceptionChain chain = new InterceptionChain(interceptorInvocations, interceptionType, getTargetInstance(), thisMethod);
- return chain.invokeNext(new InterceptorInvocationContext(chain, getTargetInstance(), thisMethod, args));
+ InterceptionChain chain = new InterceptionChain(interceptorInvocations, interceptionType, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod);
+ return chain.invokeNext(new InterceptorInvocationContext(chain, isProxy() ? targetInstance : self, isProxy() ? thisMethod : proceedingMethod, args));
+
}
+ protected boolean isProxy()
+ {
+ return proxy;
+ }
+
+
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException
{
try
{
- executeInterception(null, null, InterceptionType.PRE_PASSIVATE);
+ executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.PRE_PASSIVATE);
objectOutputStream.defaultWriteObject();
}
catch (Throwable throwable)
@@ -126,7 +153,11 @@
try
{
objectInputStream.defaultReadObject();
- executeInterception(null, null, InterceptionType.POST_ACTIVATE);
+ if (isProxy() && ((ProxyObject) targetInstance).getHandler() == null)
+ {
+ ((ProxyObject) targetInstance).setHandler(DEFAULT_METHOD_HANDLER);
+ }
+ executeInterception(isProxy() ? targetInstance : null, null, null, null, InterceptionType.POST_ACTIVATE);
}
catch (Throwable throwable)
{
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java 2010-07-28 17:07:50 UTC (rev 107167)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java 2010-07-28 17:23:17 UTC (rev 107168)
@@ -47,12 +47,6 @@
}
- public <T> T createProxyFromInstance(final Object target, ClassMetadata<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments, InterceptorMetadata interceptorClassMetadata)
- {
- MethodHandler interceptorMethodHandler = createMethodHandler(target, proxifiedClass, interceptorClassMetadata);
- return createProxyInstance(InterceptionUtils.createProxyClassWithHandler(proxifiedClass, interceptorMethodHandler), interceptorMethodHandler);
- }
-
public <T> T createProxyFromClass(ClassMetadata<T> proxifiedClass, Class<?>[] constructorTypes, Object[] constructorArguments, InterceptorMetadata interceptorClassMetadata)
{
T instance = createAdvisedSubclassInstance(proxifiedClass, constructorTypes, constructorArguments);
@@ -111,12 +105,12 @@
public <T> MethodHandler createMethodHandler(Object target, ClassMetadata<T> proxyClass, InterceptorMetadata interceptorMetadata)
{
- return new InterceptorMethodHandler(target, proxyClass, interceptionModel, interceptorInstantiator, interceptorMetadata);
+ return new InterceptorMethodHandler(target, interceptionModel, interceptorInstantiator, interceptorMetadata, true);
}
public <T> MethodHandler createSubclassingMethodHandler(Object targetInstance, ClassMetadata<T> proxyClass, InterceptorMetadata interceptorMetadata)
{
- return new SubclassingInterceptorMethodHandler(targetInstance, proxyClass, interceptionModel, interceptorInstantiator, interceptorMetadata);
+ return new InterceptorMethodHandler(targetInstance, interceptionModel, interceptorInstantiator, interceptorMetadata, false);
}
Deleted: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/SubclassingInterceptorMethodHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/SubclassingInterceptorMethodHandler.java 2010-07-28 17:07:50 UTC (rev 107167)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/SubclassingInterceptorMethodHandler.java 2010-07-28 17:23:17 UTC (rev 107168)
@@ -1,153 +0,0 @@
-package org.jboss.interceptor.proxy;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javassist.util.proxy.MethodHandler;
-import javassist.util.proxy.ProxyObject;
-import org.jboss.interceptor.reader.InterceptorMetadataUtils;
-import org.jboss.interceptor.spi.instance.InterceptorInstantiator;
-import org.jboss.interceptor.spi.metadata.ClassMetadata;
-import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
-import org.jboss.interceptor.spi.model.InterceptionModel;
-import org.jboss.interceptor.spi.model.InterceptionType;
-import org.jboss.interceptor.util.InterceptionTypeRegistry;
-import org.jboss.interceptor.util.InterceptionUtils;
-import org.jboss.interceptor.util.ReflectionUtils;
-
-/**
- * @author Marius Bogoevici
- */
-public class SubclassingInterceptorMethodHandler implements MethodHandler,Serializable
-{
-
- private Map<ClassMetadata<?>, Object> interceptorHandlerInstances = new HashMap<ClassMetadata<?>, Object>();
- private InterceptorMetadata targetClassInterceptorMetadata;
- private InterceptionModel<ClassMetadata<?>, ClassMetadata> interceptionModel;
- private Object targetInstance;
-
- private static MethodHandler DEFAULT_METHOD_HANDLER = new MethodHandler() {
-
- public Object invoke(Object self, Method m,
- Method proceed, Object[] args)
- throws Exception
- {
- return proceed.invoke(self, args);
- }
- };
-
- public SubclassingInterceptorMethodHandler(Object target, ClassMetadata<?> targetClass, InterceptionModel<ClassMetadata<?>, ClassMetadata> interceptionModel, InterceptorInstantiator<ClassMetadata<?>, ?> interceptorInstantiator, InterceptorMetadata targetClassMetadata)
- {
- this.targetInstance = target;
- if (interceptionModel == null)
- {
- throw new IllegalArgumentException("Interception model must not be null");
- }
-
- if (interceptorInstantiator == null)
- {
- throw new IllegalArgumentException("Interception handler factory must not be null");
- }
-
- this.interceptionModel = interceptionModel;
-
- for (ClassMetadata<?> interceptorReference : this.interceptionModel.getAllInterceptors())
- {
- interceptorHandlerInstances.put(interceptorReference, (interceptorInstantiator).createFor(interceptorReference));
- }
- targetClassInterceptorMetadata = targetClassMetadata;
- }
-
- public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
- {
- ReflectionUtils.ensureAccessible(thisMethod);
- if (thisMethod.getDeclaringClass().equals(LifecycleMixin.class))
- {
- if (thisMethod.getName().equals(InterceptionUtils.POST_CONSTRUCT))
- {
- return executeInterception(self, null, null, null, InterceptionType.POST_CONSTRUCT);
- }
- else if (thisMethod.getName().equals(InterceptionUtils.PRE_DESTROY))
- {
- return executeInterception(self, null, null, null, InterceptionType.PRE_DESTROY);
- }
- }
- else
- {
- if (!InterceptionUtils.isInterceptionCandidate(thisMethod))
- {
- return proceed.invoke(self, args);
- }
- if (InterceptionTypeRegistry.isSupported(InterceptionType.AROUND_TIMEOUT) && thisMethod.isAnnotationPresent(InterceptionTypeRegistry.getAnnotationClass(InterceptionType.AROUND_TIMEOUT)))
- {
- return executeInterception(self, thisMethod, thisMethod, args, InterceptionType.AROUND_TIMEOUT);
- }
- else
- {
- return executeInterception(self, thisMethod, thisMethod, args, InterceptionType.AROUND_INVOKE);
- }
- }
- return null;
-
- }
-
- private Object executeInterception(Object self, Method proceedingMethod, Method thisMethod, Object[] args, InterceptionType interceptionType) throws Throwable
- {
-
- List<ClassMetadata> interceptorList = interceptionModel.getInterceptors(interceptionType, thisMethod);
- Collection<InterceptorInvocation<?>> interceptorInvocations = new ArrayList<InterceptorInvocation<?>>();
-
- for (ClassMetadata<?> interceptorReference : interceptorList)
- {
- interceptorInvocations.add(new InterceptorInvocation(interceptorHandlerInstances.get(interceptorReference), InterceptorMetadataUtils.readMetadataForInterceptorClass(interceptorReference), interceptionType));
- }
-
- if (targetClassInterceptorMetadata != null && targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty())
- {
- interceptorInvocations.add(new InterceptorInvocation(self, targetClassInterceptorMetadata, interceptionType));
- }
-
- InterceptionChain chain = new InterceptionChain(interceptorInvocations, interceptionType, self,proceedingMethod);
- return chain.invokeNext(new InterceptorInvocationContext(chain, self, thisMethod, args));
-
- }
-
- private void writeObject(ObjectOutputStream objectOutputStream) throws IOException
- {
- try
- {
- executeInterception(targetInstance, null, null, null, InterceptionType.PRE_PASSIVATE);
- objectOutputStream.defaultWriteObject();
- }
- catch (Throwable throwable)
- {
- throw new IOException("Error while serializing class", throwable);
- }
- }
-
- private void readObject(ObjectInputStream objectInputStream) throws IOException
- {
- try
- {
- objectInputStream.defaultReadObject();
- if (((ProxyObject)targetInstance).getHandler() == null)
- {
- ((ProxyObject)targetInstance).setHandler(DEFAULT_METHOD_HANDLER);
- }
- executeInterception(targetInstance, null, null, null, InterceptionType.POST_ACTIVATE);
- }
- catch (Throwable throwable)
- {
- throw new IOException("Error while deserializing class", throwable);
- }
- }
-
-}
\ No newline at end of file
Deleted: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/proxy/TargetInstanceProxyMethodHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/proxy/TargetInstanceProxyMethodHandler.java 2010-07-28 17:07:50 UTC (rev 107167)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/proxy/TargetInstanceProxyMethodHandler.java 2010-07-28 17:23:17 UTC (rev 107168)
@@ -1,78 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
- * contributors by the @authors tag. See the copyright.txt in the
- * distribution for a full listing of individual contributors.
- *
- * Licensed 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.jboss.interceptor.util.proxy;
-
-import java.lang.reflect.Method;
-import java.io.Serializable;
-
-import javassist.util.proxy.MethodHandler;
-import org.jboss.interceptor.spi.metadata.ClassMetadata;
-
-/**
- * @author Marius Bogoevici
- */
-public abstract class TargetInstanceProxyMethodHandler<T> implements MethodHandler, Serializable
-{
- private T targetInstance;
-
- private ClassMetadata<?> targetClass;
-
- public TargetInstanceProxyMethodHandler(T targetInstance, ClassMetadata<?> targetClass)
- {
- this.targetInstance = targetInstance;
- this.targetClass = targetClass;
- }
-
- public final Object invoke(Object proxyInstance, Method interceptedMethod, Method proceed, Object[] args) throws Throwable
- {
- if (interceptedMethod.getDeclaringClass().equals(TargetInstanceProxy.class))
- {
- if (interceptedMethod.getName().equals("getTargetInstance"))
- {
- return this.getTargetInstance();
- }
- else if (interceptedMethod.getName().equals("getTargetClass"))
- {
- return this.getTargetClass();
- }
- else
- {
- // we shouldn't arrive here
- return null;
- }
- }
- else
- {
- return doInvoke(proxyInstance, interceptedMethod, proceed, args);
- }
- }
-
- /**/
- protected abstract Object doInvoke(Object proxyInstance, Method interceptedMethod, Method proceedingMethod, Object[] invocationArguments) throws Throwable;
-
- public T getTargetInstance()
- {
- return targetInstance;
- }
-
- public ClassMetadata getTargetClass()
- {
- return targetClass;
- }
-}
-
More information about the jboss-cvs-commits
mailing list