[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...
Gavin King
gavin.king at jboss.com
Fri Nov 3 20:58:24 EST 2006
User: gavin
Date: 06/11/03 20:58:24
Modified: src/main/org/jboss/seam/interceptors RemoveInterceptor.java
Log:
fix remove interceptor by making it client-side JBSEAM-459
Revision Changes Path
1.17 +21 -25 jboss-seam/src/main/org/jboss/seam/interceptors/RemoveInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RemoveInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/RemoveInterceptor.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- RemoveInterceptor.java 1 Nov 2006 02:54:02 -0000 1.16
+++ RemoveInterceptor.java 4 Nov 2006 01:58:24 -0000 1.17
@@ -1,4 +1,4 @@
-//$Id: RemoveInterceptor.java,v 1.16 2006/11/01 02:54:02 gavin Exp $
+//$Id: RemoveInterceptor.java,v 1.17 2006/11/04 01:58:24 gavin Exp $
package org.jboss.seam.interceptors;
import java.lang.reflect.Method;
@@ -9,31 +9,30 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.seam.ComponentType;
+import org.jboss.seam.InterceptorType;
import org.jboss.seam.annotations.AroundInvoke;
import org.jboss.seam.annotations.Interceptor;
import org.jboss.seam.intercept.InvocationContext;
/**
- * Removes components from the Seam context after invocation
- * of an EJB @Remove method.
+ * Removes SFSB components from the Seam context after invocation
+ * of an EJB @Remove method, or when a system exception is thrown
+ * from the bean.
*
* @author Gavin King
*/
- at Interceptor(stateless=true,
- around={ValidationInterceptor.class, BijectionInterceptor.class, ConversationInterceptor.class})
+ at Interceptor(type=InterceptorType.CLIENT)
public class RemoveInterceptor extends AbstractInterceptor
{
- //TODO: note that this implementation is a bit broken, since it assumes that
- // the thing is always bound to its component name and scope
- // (We are waiting for getInvokedBusinessObject() in EJB3)
-
private static final Log log = LogFactory.getLog(RemoveInterceptor.class);
@AroundInvoke
public Object removeIfNecessary(InvocationContext invocation) throws Exception
{
+ //we have the method from the local interface, get the corresponding one
+ //for the actual bean class (it has the @Remove annotation)
+ Method removeMethod = getComponent().getRemoveMethod( invocation.getMethod().getName() );
Object result;
try
{
@@ -41,48 +40,45 @@
}
catch (Exception exception)
{
- removeIfNecessary( invocation.getMethod(), exception );
+ removeIfNecessary(removeMethod, exception);
throw exception;
}
-
- removeIfNecessary( invocation.getMethod() );
+ removeIfNecessary(removeMethod);
return result;
}
- private void removeIfNecessary(Method method, Exception exception) {
+ private void removeIfNecessary(Method removeMethod, Exception exception) {
if ( exception instanceof RuntimeException || exception instanceof RemoteException )
{
if ( !exception.getClass().isAnnotationPresent(ApplicationException.class) )
{
//it is a "system exception"
- if ( getComponent().getType()==ComponentType.STATEFUL_SESSION_BEAN )
- {
remove();
}
}
- }
- else if ( method.isAnnotationPresent(Remove.class) )
+ else if ( removeMethod!=null )
{
- if ( !method.getAnnotation(Remove.class).retainIfException() )
+ if ( !removeMethod.getAnnotation(Remove.class).retainIfException() )
{
remove();
}
}
}
- private void removeIfNecessary(Method method)
+ private void removeIfNecessary(Method removeMethod)
{
- if ( method.isAnnotationPresent(Remove.class) )
+ if ( removeMethod!=null )
{
remove();
}
}
private void remove() {
- //TODO: account for roles, by checking which role the component
- // is actually bound to (need getInvokedBusinessObject())
getComponent().getScope().getContext().remove( getComponent().getName() );
- log.debug("Stateful component was removed: " + getComponent().getName());
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Stateful component was removed: " + getComponent().getName() );
+ }
}
}
More information about the jboss-cvs-commits
mailing list