1 /** 2 * 3 */ 4 package net.sf.crispy.impl; 5 6 import java.rmi.Naming; 7 import java.util.Properties; 8 9 import net.sf.crispy.InvocationException; 10 import net.sf.crispy.InvocationStrategy; 11 import net.sf.crispy.proxy.StaticProxy; 12 import net.sf.crispy.strategy.NameInvocationStrategy; 13 14 /** 15 * Remote-Call with Remote Method Invocation (RMI). 16 * 17 * @author Linke 18 * 19 */ 20 public class StaticRmiProxy extends StaticProxy { 21 22 public final static String DEFAULT_URL_AND_PORT = "rmi://localhost:1098"; 23 24 /** 25 * Get default url and port. If no url and port is in properties. 26 * 27 * @return Default url and port. 28 */ 29 public String getDefaultUrlAndPort() { 30 return DEFAULT_URL_AND_PORT; 31 } 32 33 public InvocationStrategy getDefaultInvocationStrategy(Properties pvProperties) { 34 String lvInterfaceClassName = (String) pvProperties.get(PROPERTY_CURRENT_INTERFACE_CLASS); 35 String lvLookupName = getProperties().getProperty(lvInterfaceClassName); 36 if (lvLookupName == null) { 37 throw new InvocationException("For the Class: " + lvInterfaceClassName + " is no RMI-Entry exist " + 38 "(LookUp-Name: " + lvLookupName + ")."); 39 } 40 return new NameInvocationStrategy(lvLookupName); 41 } 42 43 44 /** 45 * @see net.sf.crispy.proxy.Proxy#newInstance(java.lang.Class) 46 */ 47 public Object newInstance(Class pvProxyClass) { 48 String lvLookupStr = getUrlAndPort() + "/" + getInvocationStrategy(); 49 if (log.isDebugEnabled()) { log.debug("StaticRmiProxy LookUp-String: " + lvLookupStr); } 50 try { 51 Object lvProxyObject = Naming.lookup(lvLookupStr); 52 setProxyObject(lvProxyObject); 53 setProxyClass(lvProxyObject.getClass()); 54 } catch (Exception e) { 55 throw new InvocationException("Error in newInstance in StaticRmiProxy: " + e, e); 56 } 57 return getProxyObject(); 58 } 59 60 61 }