[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...
Gavin King
gavin.king at jboss.com
Wed Jul 26 17:51:05 EDT 2006
User: gavin
Date: 06/07/26 17:51:05
Modified: src/main/org/jboss/seam/interceptors
SeamInvocationContext.java JavaBeanInterceptor.java
Interceptor.java
Added: src/main/org/jboss/seam/interceptors
ClientSideInterceptor.java
Log:
client-side interceptors
Revision Changes Path
1.6 +8 -9 jboss-seam/src/main/org/jboss/seam/interceptors/SeamInvocationContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamInvocationContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/SeamInvocationContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SeamInvocationContext.java 5 Jun 2006 19:43:42 -0000 1.5
+++ SeamInvocationContext.java 26 Jul 2006 21:51:05 -0000 1.6
@@ -1,4 +1,4 @@
-//$Id: SeamInvocationContext.java,v 1.5 2006/06/05 19:43:42 gavin Exp $
+//$Id: SeamInvocationContext.java,v 1.6 2006/07/26 21:51:05 gavin Exp $
package org.jboss.seam.interceptors;
import java.lang.reflect.Method;
@@ -8,6 +8,7 @@
import javax.interceptor.InvocationContext;
import org.jboss.seam.Component;
+import org.jboss.seam.InterceptorType;
/**
* Adapts from EJB interception to Seam component interceptors
@@ -17,16 +18,16 @@
public class SeamInvocationContext implements InvocationContext
{
- public SeamInvocationContext(InvocationContext ejbInvocationContext, Component component)
+ private final InvocationContext ejbInvocationContext;
+ private final List<Interceptor> interceptors;
+ int location = 0;
+
+ public SeamInvocationContext(InvocationContext ejbInvocationContext, List<Interceptor> interceptors)
{
- this.component = component;
this.ejbInvocationContext = ejbInvocationContext;
+ this.interceptors = interceptors;
}
- private final InvocationContext ejbInvocationContext;
- private final Component component;
- int location = 0;
-
public Object getTarget()
{
return ejbInvocationContext.getTarget();
@@ -49,8 +50,6 @@
public Object proceed() throws Exception
{
-
- List<Interceptor> interceptors = component.getInterceptors();
if ( location==interceptors.size() )
{
return ejbInvocationContext.proceed();
1.7 +9 -2 jboss-seam/src/main/org/jboss/seam/interceptors/JavaBeanInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JavaBeanInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/JavaBeanInterceptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- JavaBeanInterceptor.java 5 Jun 2006 19:43:42 -0000 1.6
+++ JavaBeanInterceptor.java 26 Jul 2006 21:51:05 -0000 1.7
@@ -1,4 +1,4 @@
-//$Id: JavaBeanInterceptor.java,v 1.6 2006/06/05 19:43:42 gavin Exp $
+//$Id: JavaBeanInterceptor.java,v 1.7 2006/07/26 21:51:05 gavin Exp $
package org.jboss.seam.interceptors;
import java.io.Serializable;
@@ -11,6 +11,8 @@
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
+import org.jboss.seam.Component;
+import org.jboss.seam.InterceptorType;
import org.jboss.seam.ejb.SeamInterceptor;
/**
@@ -21,9 +23,14 @@
public class JavaBeanInterceptor implements MethodInterceptor, Serializable
{
- private final SeamInterceptor seamInterceptor = new SeamInterceptor();
+ private final SeamInterceptor seamInterceptor;
private boolean recursive = false;
+ public JavaBeanInterceptor(Component component)
+ {
+ seamInterceptor = new SeamInterceptor(InterceptorType.ANY, component);
+ }
+
public Object intercept(final Object target, final Method method, final Object[] params,
final MethodProxy methodProxy) throws Throwable
{
1.10 +23 -6 jboss-seam/src/main/org/jboss/seam/interceptors/Interceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Interceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/Interceptor.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- Interceptor.java 14 Jun 2006 16:25:20 -0000 1.9
+++ Interceptor.java 26 Jul 2006 21:51:05 -0000 1.10
@@ -1,4 +1,4 @@
-//$Id: Interceptor.java,v 1.9 2006/06/14 16:25:20 gavin Exp $
+//$Id: Interceptor.java,v 1.10 2006/07/26 21:51:05 gavin Exp $
package org.jboss.seam.interceptors;
import java.lang.annotation.Annotation;
@@ -9,6 +9,7 @@
import javax.interceptor.InvocationContext;
import org.jboss.seam.Component;
+import org.jboss.seam.InterceptorType;
import org.jboss.seam.util.Reflections;
/**
@@ -18,14 +19,20 @@
*/
public final class Interceptor extends Reflections
{
- private Method aroundInvokeMethod;
private final Object userInterceptor;
+ private Method aroundInvokeMethod;
+ private InterceptorType type;
public Object getUserInterceptor()
{
return userInterceptor;
}
+ public InterceptorType getType()
+ {
+ return type;
+ }
+
public String toString()
{
return "Interceptor(" + userInterceptor.getClass().getName() + ")";
@@ -34,30 +41,34 @@
public Interceptor(AbstractInterceptor builtinInterceptor, Component component)
{
userInterceptor = builtinInterceptor;
- init(null, component);
+ init(null, component, builtinInterceptor.getClass());
}
public Interceptor(Annotation annotation, Component component)
{
Interceptors interceptorAnnotation = annotation.annotationType()
.getAnnotation(Interceptors.class);
+ Class interceptorClass;
try
{
Class[] classes = interceptorAnnotation.value();
if (classes.length!=1)
{
+ //TODO: remove this silly restriction!
throw new IllegalArgumentException("Must be exactly one interceptor when used as a meta-annotation");
}
- userInterceptor = classes[0].newInstance();
+ interceptorClass = classes[0];
+ userInterceptor = interceptorClass.newInstance();
}
catch (Exception e)
{
throw new IllegalArgumentException("could not instantiate interceptor", e);
}
- init(annotation, component);
+ init(annotation, component, interceptorClass);
}
- private void init(Annotation annotation, Component component)
+
+ private void init(Annotation annotation, Component component, Class<?> interceptorClass)
{
for (Method method : userInterceptor.getClass().getMethods())
{
@@ -67,10 +78,12 @@
aroundInvokeMethod = method;
}
Class[] params = method.getParameterTypes();
+ //if there is a method that takes the annotation, call it, to pass initialization info
if ( annotation!=null && params.length==1 && params[0]==annotation.annotationType() )
{
Reflections.invokeAndWrap(method, userInterceptor, annotation);
}
+ //if there is a method that takes the component, call it
if ( params.length==1 && params[0]==Component.class )
{
Reflections.invokeAndWrap(method, userInterceptor, component);
@@ -83,6 +96,10 @@
userInterceptor.getClass().getName()
);
}
+
+ type = interceptorClass.isAnnotationPresent(org.jboss.seam.annotations.Interceptor.class) ?
+ interceptorClass.getAnnotation(org.jboss.seam.annotations.Interceptor.class).type() :
+ InterceptorType.SERVER;
}
public Object aroundInvoke(InvocationContext invocation) throws Exception
1.1 date: 2006/07/26 21:51:05; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/interceptors/ClientSideInterceptor.java
Index: ClientSideInterceptor.java
===================================================================
//$Id: ClientSideInterceptor.java,v 1.1 2006/07/26 21:51:05 gavin Exp $
package org.jboss.seam.interceptors;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.interceptor.InvocationContext;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.jboss.seam.Component;
import org.jboss.seam.InterceptorType;
import org.jboss.seam.ejb.SeamInterceptor;
/**
* Adapts from CGLIB interception to Seam component interception
*
* @author Gavin King
*/
public class ClientSideInterceptor implements MethodInterceptor, Serializable
{
private final SeamInterceptor seamInterceptor;
private final Object bean;
public ClientSideInterceptor(Object bean, Component component)
{
this.bean = bean;
seamInterceptor = new SeamInterceptor(InterceptorType.CLIENT, component);
}
public Object intercept(final Object proxy, final Method method, final Object[] params,
final MethodProxy methodProxy) throws Throwable
{
return interceptInvocation(bean, method, params, methodProxy);
}
private Object interceptInvocation(final Object bean, final Method method, final Object[] params,
final MethodProxy methodProxy) throws Exception
{
return seamInterceptor.aroundInvoke( new InvocationContext() {
Object[] resultParams = params;
final Map contextData = new HashMap();
public Object getTarget()
{
return bean;
}
public Map getContextData()
{
return contextData;
}
public Method getMethod()
{
return method;
}
public Object[] getParameters()
{
return params;
}
public Object proceed() throws Exception
{
try
{
return methodProxy.invoke(bean, resultParams);
}
catch (Error e)
{
throw e;
}
catch (Exception e)
{
throw e;
}
catch (Throwable t)
{
//only extremely wierd stuff!
throw new Exception(t);
}
}
public void setParameters(Object[] newParams)
{
resultParams = newParams;
}
});
}
}
More information about the jboss-cvs-commits
mailing list