1
2
3
4
5 package net.sf.crispy.impl;
6
7 import java.util.Properties;
8
9 import net.sf.crispy.InvocationException;
10 import net.sf.crispy.impl.local.MiniLocalObjectServer;
11 import net.sf.crispy.proxy.StaticProxy;
12
13 /**
14 * Local call from Java object.
15 *
16 * @author Linke
17 *
18 */
19 public class StaticLocalObjectProxy extends StaticProxy {
20
21 public StaticLocalObjectProxy () {}
22 public StaticLocalObjectProxy (Properties pvProperties) { super (pvProperties); }
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 null;
31 }
32
33 /**
34 * @see net.sf.crispy.proxy.Proxy#newInstance(java.lang.Class)
35 */
36 public Object newInstance (Class pvClass) {
37 setProxyClass (pvClass);
38 setProxyObject(getProxyByInterface(pvClass));
39 return getProxyObject();
40 }
41
42 /**
43 * Abbildung einer Schnittstelle auf eine Implementierung.
44 * Spielt nur eine Rolle beim lokalen Zugriff.
45 */
46 private Object getProxyByInterface(Class pvInterface) throws InvocationException {
47 if (pvInterface == null) {
48 throw new IllegalArgumentException("Das Interface fuer die Erzeugung des Proxy-Objektes darf nicht null sein.");
49 }
50
51
52 try {
53 Object o = MiniLocalObjectServer.getServiceByInterface(pvInterface);
54 if (o != null) { return o; }
55 } catch (InvocationException e) {
56 if (log.isDebugEnabled()) { log.debug(e); }
57 }
58
59
60 String lvClassName = getProperties().getProperty(pvInterface.getName());
61 if (lvClassName == null) {
62 throw new InvocationException("It is not possible to create a proxy object for the interface -" + pvInterface.getName());
63 }
64 try {
65 return Class.forName(lvClassName).newInstance();
66 } catch (Exception e) {
67 throw new InvocationException("For the Interface: " + pvInterface + " can no class: "
68 + lvClassName + " create!", e);
69 }
70 }
71
72 }