[jboss-cvs] JBossAS SVN: r94312 - in projects/interceptors/trunk/src: main/java/org/jboss/interceptor/proxy and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Oct 4 04:56:13 EDT 2009
Author: marius.bogoevici
Date: 2009-10-04 04:56:13 -0400 (Sun, 04 Oct 2009)
New Revision: 94312
Added:
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptorReference.java
Removed:
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionProxyFactory.java
Modified:
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModel.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelBuilder.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelImpl.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandlerFactory.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionHandlerFactory.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java
projects/interceptors/trunk/src/main/java/org/jboss/interceptor/registry/InterceptorRegistry.java
projects/interceptors/trunk/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
Log:
Making the API more generic. Interceptions are not re-entrant (interceptors will not be applied if the same business method is already being intercepted)
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModel.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModel.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModel.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -24,7 +24,7 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public interface InterceptionModel<T>
+public interface InterceptionModel<T, I>
{
/**
@@ -36,13 +36,13 @@
* @throws IllegalArgumentException if interceptionType is business method or around timeout
* but method is null, as well as if interceptionType is callback and method is not null
*/
- public List<Class<?>> getInterceptors(InterceptionType interceptionType, Method method);
+ public List<I> getInterceptors(InterceptionType interceptionType, Method method);
/**
* Returns all interceptor classes that are applicable to the given intercepted entity
* @return
*/
- public Set<Class<?>> getAllInterceptors();
+ public Set<I> getAllInterceptors();
public T getInterceptedEntity();
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelBuilder.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelBuilder.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelBuilder.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -24,22 +24,22 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class InterceptionModelBuilder<T>
+public class InterceptionModelBuilder<T, I>
{
- private InterceptionModelImpl<T> interceptionModel;
+ private InterceptionModelImpl<T, I> interceptionModel;
private T interceptedEntity;
private InterceptionModelBuilder(T interceptedEntity)
{
this.interceptedEntity = interceptedEntity;
- this.interceptionModel = new InterceptionModelImpl<T>(interceptedEntity);
+ this.interceptionModel = new InterceptionModelImpl<T, I>(interceptedEntity);
}
- public static <T> InterceptionModelBuilder<T> newBuilderFor(T entity)
+ public static <T, I> InterceptionModelBuilder<T, I> newBuilderFor(T entity, Class<I> clazz)
{
- return new InterceptionModelBuilder<T>(entity);
+ return new InterceptionModelBuilder<T, I>(entity);
}
public T getInterceptedEntity()
@@ -47,7 +47,7 @@
return interceptedEntity;
}
- public InterceptionModel<T> build()
+ public InterceptionModel<T, I> build()
{
return interceptionModel;
}
@@ -89,7 +89,7 @@
this.interceptionType = interceptionType;
}
- public void with(Class<?>... clazzes)
+ public void with(I... clazzes)
{
InterceptionModelBuilder.this.interceptionModel.appendInterceptors(interceptionType, method, clazzes);
}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelImpl.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelImpl.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptionModelImpl.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -25,14 +25,14 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class InterceptionModelImpl<T> implements InterceptionModel<T>
+public class InterceptionModelImpl<T, I> implements InterceptionModel<T, I>
{
- private Map<InterceptionType, List<Class<?>>> lifecycleInterceptors = new HashMap<InterceptionType, List<Class<?>>>();
+ private Map<InterceptionType, List<I>> lifecycleInterceptors = new HashMap<InterceptionType, List<I>>();
- private Map<InterceptionType, Map<Method, List<Class<?>>>> methodBoundInterceptors = new HashMap<InterceptionType, Map<Method, List<Class<?>>>>();
+ private Map<InterceptionType, Map<Method, List<I>>> methodBoundInterceptors = new HashMap<InterceptionType, Map<Method, List<I>>>();
- private Set<Class<?>> allInterceptors = new LinkedHashSet<Class<?>>();
+ private Set<I> allInterceptors = new LinkedHashSet<I>();
private T interceptedEntity;
@@ -41,7 +41,7 @@
this.interceptedEntity = interceptedEntity;
}
- public List<Class<?>> getInterceptors(InterceptionType interceptionType, Method method)
+ public List<I> getInterceptors(InterceptionType interceptionType, Method method)
{
if (interceptionType.isLifecycleCallback() && method != null)
throw new IllegalArgumentException("On a lifecycle callback, associated metod must be null");
@@ -51,17 +51,18 @@
if (interceptionType.isLifecycleCallback())
{
- return lifecycleInterceptors.get(interceptionType);
- } else
+ if (lifecycleInterceptors.containsKey(interceptionType))
+ return lifecycleInterceptors.get(interceptionType);
+ }
+ else
{
- if (methodBoundInterceptors.containsKey(interceptionType))
+ if (methodBoundInterceptors.containsKey(interceptionType) && methodBoundInterceptors.get(interceptionType).containsKey(method))
return methodBoundInterceptors.get(interceptionType).get(method);
- else
- return null;
}
+ return Collections.EMPTY_LIST;
}
- public Set<Class<?>> getAllInterceptors()
+ public Set<I> getAllInterceptors()
{
return Collections.unmodifiableSet(allInterceptors);
}
@@ -71,14 +72,14 @@
return this.interceptedEntity;
}
- public void appendInterceptors(InterceptionType interceptionType, Method method, Class<?>... interceptors)
+ public void appendInterceptors(InterceptionType interceptionType, Method method, I... interceptors)
{
if (interceptionType.isLifecycleCallback())
{
- List<Class<?>> interceptorsList = lifecycleInterceptors.get(interceptionType);
+ List<I> interceptorsList = lifecycleInterceptors.get(interceptionType);
if (interceptorsList == null)
{
- interceptorsList = new ArrayList<Class<?>>();
+ interceptorsList = new ArrayList<I>();
lifecycleInterceptors.put(interceptionType, interceptorsList);
}
appendInterceptorClassesToList(interceptionType, interceptorsList, interceptors);
@@ -86,12 +87,12 @@
{
if (null == methodBoundInterceptors.get(interceptionType))
{
- methodBoundInterceptors.put(interceptionType, new HashMap<Method, List<Class<?>>>());
+ methodBoundInterceptors.put(interceptionType, new HashMap<Method, List<I>>());
}
- List<Class<?>> interceptorsList = methodBoundInterceptors.get(interceptionType).get(method);
+ List<I> interceptorsList = methodBoundInterceptors.get(interceptionType).get(method);
if (interceptorsList == null)
{
- interceptorsList = new ArrayList<Class<?>>();
+ interceptorsList = new ArrayList<I>();
methodBoundInterceptors.get(interceptionType).put(method, interceptorsList);
}
appendInterceptorClassesToList(interceptionType, interceptorsList, interceptors);
@@ -99,16 +100,16 @@
allInterceptors.addAll(Arrays.asList(interceptors));
}
- private void appendInterceptorClassesToList(InterceptionType interceptionType, List<Class<?>> interceptorsList, Class<?>... interceptors)
+ private void appendInterceptorClassesToList(InterceptionType interceptionType, List<I> interceptorsList, I... interceptors)
{
- for (Class<?> clazz: interceptors)
- if (interceptorsList.contains(clazz))
+ for (I interceptor: interceptors)
+ if (interceptorsList.contains(interceptor))
if (interceptionType != null)
- throw new InterceptorException("Duplicate interceptor class definition when binding" + clazz.getName() + " on " + interceptionType.name());
+ throw new InterceptorException("Duplicate interceptor class definition when binding" + interceptor + " on " + interceptionType.name());
else
- throw new InterceptorException("Duplicate interceptor class definition when binding" + clazz.getName() + " as general interceptor");
+ throw new InterceptorException("Duplicate interceptor class definition when binding" + interceptor + " as general interceptor");
else
- interceptorsList.add(clazz);
+ interceptorsList.add(interceptor);
}
}
Added: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptorReference.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptorReference.java (rev 0)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/model/InterceptorReference.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -0,0 +1,30 @@
+/*
+ * 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.model;
+
+import org.jboss.interceptor.proxy.InterceptionHandler;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public interface InterceptorReference<T>
+{
+ T getReferredInterceptor();
+
+ InterceptionHandler getInterceptionHandler();
+}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandler.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -32,7 +32,7 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class DirectClassInterceptionHandler implements InterceptionHandler
+public class DirectClassInterceptionHandler<I> implements InterceptionHandler
{
private final Object interceptorInstance;
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandlerFactory.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandlerFactory.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptionHandlerFactory.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -20,9 +20,9 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class DirectClassInterceptionHandlerFactory implements InterceptionHandlerFactory {
+public class DirectClassInterceptionHandlerFactory implements InterceptionHandlerFactory<Class<?>> {
- public InterceptionHandler createForClass(Class<?> clazz) {
+ public InterceptionHandler createFor(Class<?> clazz) {
return new DirectClassInterceptionHandler(clazz);
}
}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -30,7 +30,7 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class InterceptionChain
+public class InterceptionChain<I>
{
private final Log log = LogFactory.getLog(InterceptionChain.class);
@@ -40,21 +40,19 @@
private Object[] parameters;
private Method targetMethod;
- private Map<Class<?>, InterceptionHandler> interceptionHandlerMap;
private int currentPosition;
- private List<Class<?>> interceptorClasses;
+ private List<InterceptionHandler> interceptorHandlers;
private final InterceptionType interceptionType;
- public InterceptionChain(List<Class<?>> interceptorClasses, InterceptionType interceptionType, Object target, Method targetMethod, Object[] parameters, Map<Class<?>, InterceptionHandler> interceptionHandlerMap)
+ public InterceptionChain(List<InterceptionHandler> interceptorHandlers, InterceptionType interceptionType, Object target, Method targetMethod, Object[] parameters)
{
- this.interceptorClasses = interceptorClasses;
+ this.interceptorHandlers = interceptorHandlers;
this.interceptionType = interceptionType;
this.parameters = parameters;
this.target = target;
this.targetMethod = targetMethod;
- this.interceptionHandlerMap = interceptionHandlerMap;
this.currentPosition = 0;
}
@@ -62,7 +60,7 @@
if (hasNext())
{
- InterceptionHandler nextInterceptorHandler = interceptionHandlerMap.get(interceptorClasses.get(currentPosition++));
+ InterceptionHandler nextInterceptorHandler = interceptorHandlers.get(currentPosition++);
log.debug("Invoking next interceptor in chain:" + nextInterceptorHandler.getClass().getName());
return nextInterceptorHandler.invoke(target, interceptionType, invocationContext);
}
@@ -86,7 +84,7 @@
public boolean hasNext()
{
- return currentPosition < interceptorClasses.size();
+ return currentPosition < interceptorHandlers.size();
}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionHandlerFactory.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionHandlerFactory.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionHandlerFactory.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -20,7 +20,7 @@
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public interface InterceptionHandlerFactory {
+public interface InterceptionHandlerFactory<I> {
- InterceptionHandler createForClass(Class<?> clazz);
+ InterceptionHandler createFor(I clazz);
}
Deleted: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionProxyFactory.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionProxyFactory.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptionProxyFactory.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -1,29 +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.proxy;
-
-import org.jboss.interceptor.registry.InterceptorRegistry;
-
-/**
- * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
- */
-public interface InterceptionProxyFactory<C> {
-
- <T> T createInterceptedProxy(T instance, Class<T> expectedProxyClass, InterceptorRegistry<C> interceptorRegistry);
-
-}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/proxy/InterceptorProxyCreatorImpl.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -28,24 +28,21 @@
import javax.interceptor.AroundInvoke;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class InterceptorProxyCreatorImpl implements InterceptorProxyCreator
+public class InterceptorProxyCreatorImpl<I> implements InterceptorProxyCreator
{
public static final String POST_CONSTRUCT = "lifecycle_mixin_$$_postConstruct";
public static final String PRE_DESTROY = "lifecycle_mixin_$$_preDestroy";
- private InterceptorRegistry<Class<?>> interceptorRegistry;
+ private InterceptorRegistry<Class<?>, I> interceptorRegistry;
- private InterceptionHandlerFactory interceptionHandlerFactory;
+ private InterceptionHandlerFactory<I> interceptionHandlerFactory;
- public InterceptorProxyCreatorImpl(InterceptorRegistry<Class<?>> interceptorRegistry, InterceptionHandlerFactory interceptionHandlerFactory)
+ public InterceptorProxyCreatorImpl(InterceptorRegistry<Class<?>, I> interceptorRegistry, InterceptionHandlerFactory<I> interceptionHandlerFactory)
{
this.interceptorRegistry = interceptorRegistry;
this.interceptionHandlerFactory = interceptionHandlerFactory;
@@ -113,17 +110,25 @@
return createProxyFromInstance(target, proxyClass, new Class[0], new Object[0]);
}
+ public MethodHandler createInstanceProxifyingMethodHandler(final Object target, Class<?> proxyClass)
+ {
+ return new InstanceProxifyingMethodHandler(target, proxyClass, interceptorRegistry);
+ }
+
+ private static ThreadLocal<Stack<Method>> interceptionStack = new ThreadLocal<Stack<Method>>();
+
private class InstanceProxifyingMethodHandler implements MethodHandler
{
private final Object target;
- private InterceptorRegistry registry;
- private Map<Class<?>, InterceptionHandler> interceptorHandlerInstances = new HashMap<Class<?>, InterceptionHandler>();
+ private InterceptorRegistry<Class<?>, I> registry;
+ private Map<I, InterceptionHandler> interceptorHandlerInstances = new HashMap<I, InterceptionHandler>();
private Class<?> targetClazz;
private InterceptorClassMetadata targetClassInterceptorMetadata;
- public InstanceProxifyingMethodHandler(Object target, Class<?> targetClass, InterceptorRegistry<Class<?>> registry)
+
+ public InstanceProxifyingMethodHandler(Object target, Class<?> targetClass, InterceptorRegistry<Class<?>, I> registry)
{
if (target == null)
this.target = this;
@@ -137,61 +142,85 @@
this.registry = registry;
- for (Class<?> interceptorClazz : registry.getInterceptionModel(this.targetClazz).getAllInterceptors())
+ for (I interceptorClazz : registry.getInterceptionModel(this.targetClazz).getAllInterceptors())
{
- interceptorHandlerInstances.put(interceptorClazz, interceptionHandlerFactory.createForClass(interceptorClazz));
+ interceptorHandlerInstances.put(interceptorClazz, interceptionHandlerFactory.createFor(interceptorClazz));
}
targetClassInterceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(targetClazz);
- interceptorHandlerInstances.put(targetClazz, new DirectClassInterceptionHandler(target, targetClazz));
+ //interceptorHandlerInstances.put(targetClazz, interceptionHandlerFactory.createFor(i));
}
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
{
- if (!thisMethod.getDeclaringClass().equals(LifecycleMixin.class))
+ if (getInterceptionStack().contains(thisMethod))
+ return thisMethod.invoke(target, args);
+ try
{
- if (!isAroundInvokeInterceptionCandidate(thisMethod))
- return proceed.invoke(self, args);
- return executeInterception(thisMethod, args, InterceptionType.AROUND_INVOKE);
- } else
- {
- if (thisMethod.getName().equals(POST_CONSTRUCT))
+ getInterceptionStack().push(thisMethod);
+
+ if (!thisMethod.getDeclaringClass().equals(LifecycleMixin.class))
{
- return executeInterception(null, null, InterceptionType.POST_CONSTRUCT);
- } else if (thisMethod.getName().equals(PRE_DESTROY))
+ if (!isAroundInvokeInterceptionCandidate(thisMethod))
+ return proceed.invoke(self, args);
+ return executeInterception(thisMethod, args, InterceptionType.AROUND_INVOKE);
+ } else
{
- return executeInterception(null, null, InterceptionType.PRE_DESTROY);
+ if (thisMethod.getName().equals(POST_CONSTRUCT))
+ {
+ return executeInterception(null, null, InterceptionType.POST_CONSTRUCT);
+ } else if (thisMethod.getName().equals(PRE_DESTROY))
+ {
+ return executeInterception(null, null, InterceptionType.PRE_DESTROY);
+ }
}
+ return null;
+ } finally
+ {
+ getInterceptionStack().remove(thisMethod);
}
- return null;
+
}
+ private Stack<Method> getInterceptionStack()
+ {
+ if (interceptionStack.get() == null)
+ interceptionStack.set(new Stack<Method>());
+ return interceptionStack.get();
+ }
+
private Object executeInterception(Method thisMethod, Object[] args, InterceptionType interceptionType) throws Exception
{
- List<Class<?>> interceptorClasses = registry.getInterceptionModel(targetClazz).getInterceptors(interceptionType, thisMethod);
- List<Class<?>> interceptorClassesForMethod = interceptorClasses == null ? new ArrayList<Class<?>>() : interceptorClasses;
+ List<I> interceptorClasses = registry.getInterceptionModel(targetClazz).getInterceptors(interceptionType, thisMethod);
//assume the list is immutable
+
+ List<InterceptionHandler> interceptionHandlers = new ArrayList<InterceptionHandler>();
+ for (I interceptorReference : interceptorClasses)
+ {
+ interceptionHandlers.add(interceptorHandlerInstances.get(interceptorReference));
+ }
+
if (targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty())
{
- interceptorClassesForMethod = new ArrayList(interceptorClassesForMethod);
- interceptorClassesForMethod.add(targetClazz);
+ interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(targetClazz));
}
- InterceptionChain chain = new InterceptionChain(interceptorClassesForMethod, interceptionType, target, thisMethod, args, interceptorHandlerInstances);
+
+ InterceptionChain chain = new InterceptionChain(interceptionHandlers, interceptionType, target, thisMethod, args);
return chain.invokeNext(new InterceptorInvocationContext(chain, target, thisMethod, args));
}
}
- private static class AutoProxifiedMethodHandler implements MethodHandler
+ private class AutoProxifiedMethodHandler implements MethodHandler
{
- private InterceptorRegistry registry;
- private Map<Class<?>, InterceptionHandler> interceptorHandlerInstances = new HashMap<Class<?>, InterceptionHandler>();
+ private InterceptorRegistry<Class<?>, I> registry;
+ private Map<I, InterceptionHandler> interceptorHandlerInstances = new HashMap<I, InterceptionHandler>();
private Class<?> targetClazz;
private InterceptorClassMetadata targetClassInterceptorMetadata;
- public AutoProxifiedMethodHandler(Class<?> targetClazz, InterceptorRegistry<Class<?>> registry)
+ public AutoProxifiedMethodHandler(Class<?> targetClazz, InterceptorRegistry<Class<?>, I> registry)
{
if (targetClazz == null)
throw new IllegalArgumentException("Target class must not be null");
@@ -199,9 +228,9 @@
this.targetClazz = targetClazz;
this.registry = registry;
- for (Class<?> interceptorClazz : registry.getInterceptionModel(this.targetClazz).getAllInterceptors())
+ for (I interceptorClazz : registry.getInterceptionModel(this.targetClazz).getAllInterceptors())
{
- interceptorHandlerInstances.put(interceptorClazz, new DirectClassInterceptionHandler(interceptorClazz));
+ interceptorHandlerInstances.put(interceptorClazz, interceptionHandlerFactory.createFor(interceptorClazz));
}
targetClassInterceptorMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(targetClazz);
}
@@ -230,23 +259,22 @@
private Object executeInterception(Object self, Method thisMethod, Method proceed, Object[] args, InterceptionType interceptionType) throws Exception
{
- addSelfAsInterceptorHandler(self);
- List<Class<?>> interceptorClasses = registry.getInterceptionModel(targetClazz).getInterceptors(interceptionType, thisMethod);
- List<Class<?>> interceptorClassesForMethod = interceptorClasses == null ? new ArrayList<Class<?>>() : interceptorClasses;
+
+ List<I> interceptorClasses = registry.getInterceptionModel(targetClazz).getInterceptors(interceptionType, thisMethod);
+ List<InterceptionHandler> interceptionHandlers = new ArrayList<InterceptionHandler>();
+ for (I interceptorReference : interceptorClasses)
+ {
+ interceptionHandlers.add(interceptorHandlerInstances.get(interceptorReference));
+ }
+
if (targetClassInterceptorMetadata.getInterceptorMethods(interceptionType) != null && !targetClassInterceptorMetadata.getInterceptorMethods(interceptionType).isEmpty())
{
- interceptorClassesForMethod = new ArrayList(interceptorClassesForMethod);
- interceptorClassesForMethod.add(targetClazz);
+ interceptionHandlers.add(new DirectClassInterceptionHandler<Class<?>>(targetClazz));
}
- InterceptionChain chain = new InterceptionChain(interceptorClassesForMethod, interceptionType, self, proceed, args, interceptorHandlerInstances);
+ InterceptionChain chain = new InterceptionChain(interceptionHandlers, interceptionType, self, proceed, args);
return chain.invokeNext(new InterceptorInvocationContext(chain, self, proceed, args));
}
- private void addSelfAsInterceptorHandler(Object self)
- {
- if (!interceptorHandlerInstances.containsKey(targetClazz))
- interceptorHandlerInstances.put(targetClazz, new DirectClassInterceptionHandler(self, targetClazz));
- }
}
Modified: projects/interceptors/trunk/src/main/java/org/jboss/interceptor/registry/InterceptorRegistry.java
===================================================================
--- projects/interceptors/trunk/src/main/java/org/jboss/interceptor/registry/InterceptorRegistry.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/main/java/org/jboss/interceptor/registry/InterceptorRegistry.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -27,16 +27,16 @@
*
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
-public class InterceptorRegistry<T>
+public class InterceptorRegistry<T, I>
{
- private Map<T, InterceptionModel<T>> interceptionModelMap = new HashMap<T, InterceptionModel<T>>();
+ private Map<T, InterceptionModel<T, I>> interceptionModelMap = new HashMap<T, InterceptionModel<T, I>>();
- public void registerInterceptionModel(T interceptedEntity, InterceptionModel<T> interceptionModel)
+ public void registerInterceptionModel(T interceptedEntity, InterceptionModel<T, I> interceptionModel)
{
this.interceptionModelMap.put(interceptedEntity, interceptionModel);
}
- public InterceptionModel<T> getInterceptionModel(T interceptedEntity)
+ public InterceptionModel<T, I> getInterceptionModel(T interceptedEntity)
{
return this.interceptionModelMap.get(interceptedEntity);
}
Modified: projects/interceptors/trunk/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
===================================================================
--- projects/interceptors/trunk/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-10-03 15:38:04 UTC (rev 94311)
+++ projects/interceptors/trunk/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-10-04 08:56:13 UTC (rev 94312)
@@ -59,9 +59,9 @@
public void resetLogAndSetupClasses() throws Exception
{
InterceptorTestLogger.reset();
- InterceptorRegistry<Class<?>> interceptorRegistry = new InterceptorRegistry<Class<?>>();
+ InterceptorRegistry<Class<?>, Class<?>> interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
- InterceptionModelBuilder<Class<?>> builder = InterceptionModelBuilder.<Class<?>>newBuilderFor(FootballTeam.class);
+ InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class)Class.class);
builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(MyFirstInterceptor.class, MySecondInterceptor.class);
builder.interceptPostConstruct().with(MyFirstInterceptor.class);
@@ -87,6 +87,7 @@
public void testInterceptionWithProxifiedObject() throws Exception
{
FootballTeam proxy = interceptorProxyCreator.createProxyFromInstance(new FootballTeam(TEAM_NAME), FootballTeam.class);
+ proxy = interceptorProxyCreator.createProxyFromInstance(proxy, FootballTeam.class);
executeAssertionsOnProxy(proxy);
}
More information about the jboss-cvs-commits
mailing list