package org.mockejb;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.*;
import org.apache.commons.logging.*;
import org.mockejb.interceptor.*;
public class EjbExceptionHandler implements Aspect, Serializable {
private static Log logger = LogFactory.getLog( EjbExceptionHandler.class.getName() );
public Pointcut getPointcut(){
return PointcutPair.or( new ClassPointcut( EJBObject.class, true),
new ClassPointcut( EJBLocalObject.class, true) );
}
public void intercept( InvocationContext invocationContext ) throws Exception {
try {
invocationContext.proceed();
}
catch ( Exception exception ){
if ( MockContainer.isSystemException( exception ) ) {
logger.error("\nException during invocation of "+
invocationContext.getTargetMethod(), exception);
MockEjbContext ejbContext =
(MockEjbContext) invocationContext.getPropertyValue( MockEjbContext.class.getName() );
if ( ejbContext.isRemote() &&
!(exception instanceof RemoteException ) ) {
throw new RemoteException( "System Error", exception );
}
if ( ! ejbContext.isRemote() && !(exception instanceof EJBException )) {
throw new EJBException( exception );
}
}
throw exception;
}
}
public boolean equals( Object obj ){
if ( obj instanceof EjbExceptionHandler)
return true;
else
return false;
}
public int hashCode() {
return this.getClass().hashCode();
}
}