[jboss-cvs] JBossAS SVN: r99925 - in projects/interceptors/trunk/jboss-interceptor/src: main/java/org/jboss/interceptor/proxy and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jan 25 22:33:37 EST 2010
Author: marius.bogoevici
Date: 2010-01-25 22:33:36 -0500 (Mon, 25 Jan 2010)
New Revision: 99925
Modified:
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/model/InterceptorClassMetadataImpl.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/AbstractClassInterceptionHandler.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionHandler.java
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/registry/InterceptorClassMetadataRegistry.java
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/InterceptionUtils.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTest.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/SimpleInheritanceParentInterceptor.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
Log:
JBINTER-5
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/model/InterceptorClassMetadataImpl.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/model/InterceptorClassMetadataImpl.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/model/InterceptorClassMetadataImpl.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -45,13 +45,22 @@
private Class<?> interceptorClass;
+ private boolean interceptionTargetClass;
+
private Map<InterceptionType, List<Method>> methodMap = new HashMap<InterceptionType, List<Method>>();
private boolean hasInterceptorMethods;
- public InterceptorClassMetadataImpl(Class<?> interceptorClass)
+ /**
+ * @param interceptorClass
+ * @param interceptionTargetClass - a flag indicating whether the inspected class is
+ * the interception target itself. Interceptor method signatures are different
+ * in this case
+ */
+ public InterceptorClassMetadataImpl(Class<?> interceptorClass, boolean interceptionTargetClass)
{
this.interceptorClass = interceptorClass;
+ this.interceptionTargetClass = interceptionTargetClass;
Class<?> currentClass = interceptorClass;
@@ -64,14 +73,20 @@
{
for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
{
- if (InterceptionUtils.isInterceptorMethod(interceptionType, method))
+ if (InterceptionUtils.isInterceptorMethod(interceptionType, method, interceptionTargetClass))
{
if (methodMap.get(interceptionType) == null)
+ {
methodMap.put(interceptionType, new LinkedList<Method>());
+ }
if (detectedInterceptorTypes.contains(interceptionType))
+ {
throw new InterceptorMetadataException("Same interception type cannot be specified twice on the same class");
+ }
else
+ {
detectedInterceptorTypes.add(interceptionType);
+ }
// add method in the list - if it is there already, it means that it has been added by a subclass
ReflectionUtils.ensureAccessible(method);
if (!foundMethods.contains(MethodHolder.of(method, false)))
@@ -84,9 +99,16 @@
foundMethods.add(MethodHolder.of(method, false));
}
currentClass = currentClass.getSuperclass();
- } while (!Object.class.equals(currentClass));
+ }
+ while (!Object.class.equals(currentClass));
}
+ public InterceptorClassMetadataImpl(Class<?> interceptorClass)
+ {
+ this(interceptorClass, false);
+ }
+
+
public Class<?> getInterceptorClass()
{
return interceptorClass;
@@ -97,7 +119,7 @@
List<Method> methods = methodMap.get(interceptionType);
return methods == null ? Collections.EMPTY_LIST : methods;
}
-
+
public boolean isInterceptor()
{
return hasInterceptorMethods;
@@ -105,23 +127,27 @@
private Object writeReplace()
{
- return new InterceptorClassMetadataSerializationProxy(getInterceptorClass().getName());
+ return new InterceptorClassMetadataSerializationProxy(getInterceptorClass().getName(), interceptionTargetClass);
}
static class InterceptorClassMetadataSerializationProxy implements Serializable
{
private String className;
- InterceptorClassMetadataSerializationProxy(String className)
+ private boolean interceptionTargetClass;
+
+ InterceptorClassMetadataSerializationProxy(String className, boolean interceptionTargetClass)
{
this.className = className;
+ this.interceptionTargetClass = interceptionTargetClass;
}
private Object readResolve()
{
try
{
- return InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(ReflectionUtils.classForName(className));
+ Class<?> interceptorClass = ReflectionUtils.classForName(className);
+ return InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(interceptorClass, interceptionTargetClass);
}
catch (ClassNotFoundException e)
{
@@ -130,6 +156,5 @@
}
}
-
-
+
}
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/AbstractClassInterceptionHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/AbstractClassInterceptionHandler.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/AbstractClassInterceptionHandler.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -39,16 +39,20 @@
public abstract class AbstractClassInterceptionHandler implements InterceptionHandler, Serializable
{
private InterceptorClassMetadata interceptorMetadata;
- private Class<?> clazz;
public abstract Object getInterceptorInstance();
protected AbstractClassInterceptionHandler(Class<?> clazz)
{
- this.clazz = clazz;
- this.interceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(this.clazz);
+ this.interceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(clazz);
}
+ public AbstractClassInterceptionHandler(InterceptorClassMetadata targetClassInterceptorMetadata)
+ {
+ this.interceptorMetadata = targetClassInterceptorMetadata;
+ }
+
+
public Object invoke(Object target, InterceptionType interceptionType, InvocationContext invocationContext) throws Exception
{
List<Method> methods = interceptorMetadata.getInterceptorMethods(interceptionType);
@@ -65,16 +69,6 @@
return interceptorMetadata;
}
- public Class<?> getClazz()
- {
- return clazz;
- }
-
- public boolean handles(Class<?> clazz)
- {
- return this.clazz.equals(clazz);
- }
-
public class DelegatingInvocationContext implements InvocationContext
{
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -17,6 +17,7 @@
package org.jboss.interceptor.proxy;
+import org.jboss.interceptor.model.InterceptorClassMetadata;
import org.jboss.interceptor.registry.InterceptorClassMetadataRegistry;
import org.jboss.interceptor.InterceptorException;
@@ -50,6 +51,13 @@
}
+ public DirectClassInterceptionHandler(Object targetInstance, InterceptorClassMetadata targetClassInterceptorMetadata)
+ {
+ super(targetClassInterceptorMetadata);
+ this.interceptorInstance = targetInstance;
+ }
+
+
public Object getInterceptorInstance()
{
return interceptorInstance;
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionHandler.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionHandler.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionHandler.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -28,6 +28,5 @@
{
public Object invoke(Object target, InterceptionType interceptionType, InvocationContext invocationContext) throws Exception;
- boolean handles(Class<?> clazz);
}
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-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptorMethodHandler.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -14,6 +14,7 @@
import org.jboss.interceptor.model.InterceptorClassMetadata;
import org.jboss.interceptor.model.InterceptionModel;
+import org.jboss.interceptor.model.InterceptorClassMetadataImpl;
import org.jboss.interceptor.model.MethodHolder;
import org.jboss.interceptor.model.InterceptionType;
import org.jboss.interceptor.model.InterceptionTypeRegistry;
@@ -62,7 +63,7 @@
interceptorHandlerInstances.put(interceptorReference, ((InterceptionHandlerFactory) interceptionHandlerFactories.get(i)).createFor((Object) interceptorReference));
}
}
- targetClassInterceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(getTargetClass());
+ targetClassInterceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(getTargetClass(), true);
}
public Object doInvoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
@@ -113,7 +114,7 @@
if (targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty())
{
- interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(getTargetInstance(), getTargetClass()));
+ interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(getTargetInstance(), targetClassInterceptorMetadata));
}
InterceptionChain chain = new InterceptionChain(interceptionHandlers, interceptionType, getTargetInstance(), thisMethod, args);
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/registry/InterceptorClassMetadataRegistry.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/registry/InterceptorClassMetadataRegistry.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/registry/InterceptorClassMetadataRegistry.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -33,7 +33,7 @@
{
private static InterceptorClassMetadataRegistry interceptorMetadataRegistry;
- private final Map<Class<?>, InterceptorClassMetadata> interceptorClassMetadataMap = new ConcurrentHashMap<Class<?>, InterceptorClassMetadata>();
+ private final Map<Key, InterceptorClassMetadata> interceptorClassMetadataMap = new ConcurrentHashMap<Key, InterceptorClassMetadata>();
private final Lock lock = new ReentrantLock();
@@ -49,15 +49,21 @@
public InterceptorClassMetadata getInterceptorClassMetadata(Class<?> interceptorClass)
{
- if (!interceptorClassMetadataMap.containsKey(interceptorClass))
+ return this.getInterceptorClassMetadata(interceptorClass, false);
+ }
+
+ public InterceptorClassMetadata getInterceptorClassMetadata(Class<?> interceptorClass, boolean isInterceptorTargetClass)
+ {
+ Key key = new Key(interceptorClass, isInterceptorTargetClass);
+ if (!interceptorClassMetadataMap.containsKey(key))
{
try
{
lock.lock();
- //verify that metadata hasn't been added while waiting for the lock
- if (!interceptorClassMetadataMap.containsKey(interceptorClass))
+ //verify that metadata hasn't been added while waiting for the lock
+ if (!interceptorClassMetadataMap.containsKey(key))
{
- interceptorClassMetadataMap.put(interceptorClass, new InterceptorClassMetadataImpl(interceptorClass));
+ interceptorClassMetadataMap.put(key, new InterceptorClassMetadataImpl(interceptorClass, isInterceptorTargetClass));
}
}
finally
@@ -66,8 +72,55 @@
}
}
- return interceptorClassMetadataMap.get(interceptorClass);
+ return interceptorClassMetadataMap.get(key);
}
+ private static class Key
+ {
+ private Class<?> clazz;
+
+ private boolean isInterceptorTargetClass;
+
+ private Key(Class<?> clazz, boolean interceptorTargetClass)
+ {
+ this.clazz = clazz;
+ isInterceptorTargetClass = interceptorTargetClass;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ Key key = (Key) o;
+
+ if (isInterceptorTargetClass != key.isInterceptorTargetClass)
+ {
+ return false;
+ }
+ if (clazz != null ? !clazz.equals(key.clazz) : key.clazz != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = clazz != null ? clazz.hashCode() : 0;
+ result = 31 * result + (isInterceptorTargetClass ? 1 : 0);
+ return result;
+ }
+ }
+
}
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/InterceptionUtils.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/InterceptionUtils.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/util/InterceptionUtils.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -109,9 +109,10 @@
/**
* @param interceptionType
* @param method
+ * @param forTargetClass
* @return
*/
- public static boolean isInterceptorMethod(InterceptionType interceptionType, Method method)
+ public static boolean isInterceptorMethod(InterceptionType interceptionType, Method method, boolean forTargetClass)
{
if (method.getAnnotation(InterceptionTypeRegistry.getAnnotationClass(interceptionType)) == null)
@@ -123,27 +124,39 @@
{
if (!Void.TYPE.equals(method.getReturnType()))
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but does not have a void return type");
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "does not have a void return type");
+ }
return false;
}
Class<?>[] parameterTypes = method.getParameterTypes();
- if (parameterTypes.length > 1)
+ if (forTargetClass && parameterTypes.length != 0)
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but has more than 1 parameter");
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "is defined on the target class and does not have 0 arguments");
+ }
return false;
}
+ if (!forTargetClass && parameterTypes.length != 1)
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "does not have exactly one parameter");
+ }
+ return false;
+ }
+
if (parameterTypes.length == 1 && !InvocationContext.class.equals(parameterTypes[0]))
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but does not have a " + InvocationContext.class.getName() + " parameter ");
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "its single argument is not a " + InvocationContext.class.getName());
+ }
return false;
}
@@ -153,9 +166,10 @@
{
if (!Object.class.equals(method.getReturnType()))
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but does not return a " + Object.class.getName());
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "does not return a " + Object.class.getName());
+ }
return false;
}
@@ -163,17 +177,19 @@
if (parameterTypes.length != 1)
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but does not have exactly 1 parameter");
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "does not have exactly 1 parameter");
+ }
return false;
}
if (!InvocationContext.class.equals(parameterTypes[0]))
{
- LOG.warn("Method " + method.getName() + " on class " + method.getDeclaringClass().getName()
- + " is annotated with " + interceptionType.getAnnotationClassName()
- + " but does not have a " + InvocationContext.class.getName() + " parameter ");
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug(getStandardIgnoredMessage(interceptionType, method) + "does not have a " + InvocationContext.class.getName() + " parameter ");
+ }
return false;
}
@@ -181,6 +197,13 @@
}
}
+ private static String getStandardIgnoredMessage(InterceptionType interceptionType, Method method)
+ {
+ return "Method " + method.getName() + " defined on class " + method.getDeclaringClass().getName()
+ + " will not be used for interception, since it is not defined according to the specification. It is annotated with @"
+ + interceptionType.getAnnotationClassName() + ", but ";
+ }
+
public static <T> T proxifyInstance(T instance, Class<?> superClass, List<InterceptorRegistry<Class<?>, ?>> interceptorRegistries, List<InterceptionHandlerFactory<?>> interceptionHandlerFactory)
{
try
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTest.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTest.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTest.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -94,7 +94,7 @@
InterceptorClassMetadata interceptorClassMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(SimpleInheritanceChildInterceptor.class);
List<Method> postConstructMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.POST_CONSTRUCT);
- assertEquals(true, postConstructMethods.size() == 1);
+ assertEquals(1, postConstructMethods.size());
assertEquals(postConstructMethods.get(0).getName(), "doPostConstruct");
List<Method> preDestroyMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.PRE_DESTROY);
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/SimpleInheritanceParentInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/SimpleInheritanceParentInterceptor.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/SimpleInheritanceParentInterceptor.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -18,6 +18,7 @@
package org.jboss.interceptors.metadata;
import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
@@ -25,7 +26,7 @@
public class SimpleInheritanceParentInterceptor
{
@PostConstruct
- public void doPostConstruct()
+ public void doPostConstruct(InvocationContext invocationContext)
{
}
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -21,6 +21,7 @@
import org.jboss.interceptors.proxy.InterceptorTestLogger;
+import javax.annotation.PostConstruct;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.ejb.PrePassivate;
@@ -34,6 +35,8 @@
private String teamName;
+ public static boolean postConstructed = false;
+
// an empty-argument constructor is required for proxifycation
public FootballTeam() {
@@ -102,4 +105,11 @@
InterceptorTestLogger.add(FootballTeam.class, "aroundInvokeAfter");
return result;
}
+
+ @PostConstruct
+ public void afterConstruction()
+ {
+ postConstructed = true;
+ }
}
+
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2010-01-25 23:11:03 UTC (rev 99924)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2010-01-26 03:33:36 UTC (rev 99925)
@@ -62,6 +62,7 @@
};
private String[] expectedLoggedValuesOnSerialization = {
+ "org.jboss.interceptors.proxy.FirstInterceptor_postConstruct",
"org.jboss.interceptors.proxy.FootballTeam_prePassivating",
"org.jboss.interceptors.proxy.FootballTeam_postActivating",
"org.jboss.interceptors.proxy.FirstInterceptor_aroundInvokeBefore",
@@ -85,9 +86,8 @@
public void resetLogAndSetupClassesForMethod() throws Exception
{
InterceptorTestLogger.reset();
-
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
-
+ FootballTeam.postConstructed = false;
builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(FirstInterceptor.class, SecondInterceptor.class);
builder.interceptPostConstruct().with(FirstInterceptor.class);
builder.interceptPreDestroy().with(SecondInterceptor.class);
@@ -100,6 +100,7 @@
public void resetLogAndSetupClassesGlobally() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -113,6 +114,7 @@
public void resetLogAndSetupClassesMixed() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
builder.interceptAll().with(FirstInterceptor.class);
@@ -127,6 +129,8 @@
public void resetLogAndSetupClassesWithGlobalsIgnored() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
+
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
builder.interceptAll().with(FirstInterceptor.class);
builder.interceptPreDestroy().with(SecondInterceptor.class);
@@ -195,6 +199,7 @@
{
resetLogAndSetupClassesForMethod();
FootballTeam proxy = InterceptionUtils.proxifyInstance(new FootballTeam(TEAM_NAME), FootballTeam.class, interceptorRegistry, new DirectClassInterceptionHandlerFactory());
+ InterceptionUtils.executePostConstruct(proxy);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(proxy);
proxy = (FootballTeam) new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
@@ -209,6 +214,7 @@
public void testMethodParameterOverriding() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -225,6 +231,7 @@
public void testMethodParameterOverridingWithPrimitive() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -241,6 +248,7 @@
public void testMethodParameterOverridingWithObject() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -257,6 +265,7 @@
public void testMethodParameterOverridingWithObjectSucceed() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -273,6 +282,7 @@
public void testMethodParameterOverridingWithPrimitiveWidening() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -289,6 +299,7 @@
public void testMethodParameterOverridingWithPrimitiveNarrowing() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -305,6 +316,7 @@
public void testMethodParameterOverridingWithArray() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -321,6 +333,7 @@
public void testMethodParameterOverridingWithArrayOnString() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
@@ -337,7 +350,9 @@
public void testMethodParameterOverridingWithSubclass() throws Exception
{
InterceptorTestLogger.reset();
+ FootballTeam.postConstructed = false;
+
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
builder.interceptAroundInvoke(FootballTeam.class.getMethod("echo2", ValueBearer.class)).with(ParameterOverridingInterceptor2.class);
@@ -357,6 +372,7 @@
Assert.assertEquals(TEAM_NAME, rawInstance.getName());
Object[] logValues = InterceptorTestLogger.getLog().toArray();
Assert.assertArrayEquals(iterateAndDisplay(logValues), expectedLoggedValuesWhenRaw, logValues);
+ Assert.assertTrue(FootballTeam.postConstructed);
}
private String iterateAndDisplay(Object[] logValues)
More information about the jboss-cvs-commits
mailing list