View Javadoc

1   package net.sf.crispy.impl;
2   
3   import java.lang.reflect.Method;
4   import java.rmi.Naming;
5   import java.util.Vector;
6   
7   import net.sf.crispy.ExceptionWrapper;
8   import net.sf.crispy.Executor;
9   import net.sf.crispy.impl.rmi.RmiInvocationHandler;
10  import net.sf.crispy.util.Invoker;
11  
12  /**
13   * Remote-Call with Remote Method Invocation (RMI).
14   * 
15   * @author Linke
16   */
17  
18  public class RmiExecutor extends Executor {
19  
20  	/**
21  	 * 
22  	 * @uml.property name="dEFAULT_URL_AND_PORT"
23  	 * @uml.associationEnd inverse=":java.lang.String" changeability="frozen" multiplicity=
24  	 * "(0 1)"
25  	 */
26  	public final static String DEFAULT_URL_AND_PORT = "rmi://localhost:1098";
27  
28  	public final static String LOOKUP_NAME = "RmiInvocationHandler";
29  
30  	private RmiInvocationHandler rmiInvocationHandler = null;
31  
32  	public String getDefaultUrlAndPort() { return DEFAULT_URL_AND_PORT; }
33  	
34  	public boolean withConverter() { return true; }
35  
36  	public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
37  		if (rmiInvocationHandler == null) {
38  			String lvLookupStr = getUrlAndPort() + "/" + LOOKUP_NAME;
39  			rmiInvocationHandler = (RmiInvocationHandler) Naming.lookup(lvLookupStr);
40  		}
41  		Vector lvParams = Invoker.array2Vector(pvArgs);
42  		Object lvReturn = rmiInvocationHandler.invoke(pvProxyClass.getName(), pvMethod.getName(), lvParams);
43  		
44  		lvReturn = ExceptionWrapper.isResultExceptionThanThrowIt(lvReturn);
45  
46  		return lvReturn;
47  	}
48  
49  }