1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portalsite.view;
18
19 import java.lang.reflect.Method;
20 import java.lang.reflect.Proxy;
21
22 /***
23 * This class is the base class for all site content
24 * proxy implementations.
25 *
26 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
27 * @version $Id: SiteViewProxy.java 516448 2007-03-09 16:25:47Z ate $
28 */
29 public abstract class SiteViewProxy
30 {
31 /***
32 * view - site view this proxy is part of
33 */
34 private SiteView view;
35
36 /***
37 * locatorName - name of profile locator name associated
38 * with the derived delegate of this proxy
39 * in the site view
40 */
41 private String locatorName;
42
43 /***
44 * SiteViewProxy - constructor
45 *
46 * @param view site view owner of this proxy
47 * @param locatorName profile locator name associated with
48 * the derived delegate of this proxy in
49 * the site view
50 */
51 protected SiteViewProxy(SiteView view, String locatorName)
52 {
53 this.view = view;
54 this.locatorName = locatorName;
55 }
56
57 /***
58 * getView - return site view for this proxy
59 *
60 * @return site view
61 */
62 public SiteView getView()
63 {
64 return view;
65 }
66
67 /***
68 * getLocatorName - return profile locator name associated
69 * with the derived delegate of this proxy in
70 * the site view
71 *
72 * @return profile locator name
73 */
74 public String getLocatorName()
75 {
76 return locatorName;
77 }
78
79 /***
80 * reflectMethod - trap method reflection exceptions utility function
81 *
82 * @param methodClass class or interface
83 * @param methodName method name
84 * @param methodArgs array of type, class, or interface parameter types
85 */
86 protected static Method reflectMethod(Class methodClass, String methodName, Class [] methodArgs)
87 {
88
89 try
90 {
91 return methodClass.getMethod(methodName, methodArgs);
92 }
93 catch (NoSuchMethodException nsme)
94 {
95 RuntimeException rte = new RuntimeException("SiteViewProxy.reflectMethod(): unexpected reflection exception for: " + methodClass.getName() + "." + methodName);
96 rte.initCause(nsme);
97 throw rte;
98 }
99 }
100
101 /***
102 * getSiteViewProxy - utility method to access SiteViewProxy handler
103 * from a proxy instance
104 *
105 * @param proxy proxy instance
106 * @return site view invocation handler instance
107 */
108 public static SiteViewProxy getSiteViewProxy(Object proxy)
109 {
110 if ((proxy != null) && Proxy.isProxyClass(proxy.getClass()))
111 {
112 Object proxyHandler = Proxy.getInvocationHandler(proxy);
113 if (proxyHandler instanceof SiteViewProxy)
114 {
115 return (SiteViewProxy)proxyHandler;
116 }
117 }
118 return null;
119 }
120 }