1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.components.portletregistry;
18
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.InvocationTargetException;
21 import java.lang.reflect.Method;
22 import java.lang.reflect.Proxy;
23
24 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
25
26 public class PortletDefinitionCompositeProxy implements InvocationHandler
27 {
28 private PortletDefinitionComposite def = null;
29 private static PortletRegistry registry;
30 private String name;
31
32 public PortletDefinitionCompositeProxy(PortletDefinitionComposite def)
33 {
34 this.def = def;
35 this.name = def.getUniqueName();
36 }
37
38 public static void setRegistry(PortletRegistry r)
39 {
40 registry = r;
41 }
42
43 public static PortletDefinitionComposite createProxy(
44 PortletDefinitionComposite def)
45 {
46 Class[] proxyInterfaces = new Class[]
47 { PortletDefinitionComposite.class};
48 PortletDefinitionComposite proxy = (PortletDefinitionComposite) Proxy
49 .newProxyInstance(PortletDefinitionComposite.class
50 .getClassLoader(), proxyInterfaces,
51 new PortletDefinitionCompositeProxy(def));
52 return proxy;
53 }
54
55 protected void invalidate()
56 {
57 this.def = null;
58 }
59
60 protected void setRealDefinition(PortletDefinitionComposite d)
61 {
62 this.def = d;
63 }
64
65 protected PortletDefinitionComposite getRealApplication()
66 {
67 return def;
68 }
69
70 public Object invoke(Object proxy, Method m, Object[] args)
71 throws Throwable
72 {
73 try
74 {
75 if (def == null)
76 {
77 def = registry.getPortletDefinitionByUniqueName(name);
78 }
79 return m.invoke(def, args);
80 }
81 catch (InvocationTargetException e)
82 {
83 throw e.getTargetException();
84 }
85 }
86
87 }