One of ways can be proxy object:
remote interface:
Code:
public interface Server
extends javax.ejb.EJBObject {
public Object invoke( String clsName ,
String methodName,
Class params[] ,
Object args[]
) throws java.rmi.RemoteException, Exception;
}
home interface :
Code:
public interface ServerHome
extends javax.ejb.EJBHome {
public Server create() throws javax.ejb.CreateException,
java.rmi.RemoteException;
}
implementation :
Code:
public Object invoke(String clsName, String methodName,
Class params[] ,Object args[]) throws Exception{
//INTERCEPTS ALL CALLS FROM REMOTE CLIENT
Object obj = lookup(clsName);
return obj.getClass().
getMethod(methodName,params).
invoke(obj,args);
}
client:
Code:
public Object create(Class anyInterface){
return Proxy.newProxyInstance(anyInterface.getClassLoader(), new Class[]{anyInterface}, new InvocationHandler(){
public Object invoke( Object obj,
Method method,
Object[] args) throws java.lang.Throwable {
//INTERCEPTS ALL CALLS CALLS TO REMOTE SERVER
return server.
invoke( method.getDeclaringClass(),
method.getName(),
method.getParameterTypes(),
args);
}
}
);
}
It is a simple way to use pseudo AOP with EJB for client, server or for both.
It needs to lookup single bean on client "Server", server can invoke method on Local/Remote bean or on POJO.