1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.page.proxy;
18
19 import java.lang.reflect.InvocationHandler;
20 import java.lang.reflect.Method;
21 import java.lang.reflect.Proxy;
22
23 import org.apache.jetspeed.om.folder.Folder;
24 import org.apache.jetspeed.om.page.Link;
25 import org.apache.jetspeed.page.document.proxy.NodeProxy;
26 import org.apache.jetspeed.portalsite.view.SiteView;
27
28 /***
29 * This class proxies PSML Link instances to create a logical view
30 * of site content using the Dynamic Proxy pattern.
31 *
32 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
33 * @version $Id: LinkProxy.java 517121 2007-03-12 07:45:49Z ate $
34 */
35 public class LinkProxy extends NodeProxy implements InvocationHandler
36 {
37 /***
38 * link - proxy delegate link instance
39 */
40 private Link link;
41
42 /***
43 * newInstance - creates a new proxy instance that implements the Link interface
44 *
45 * @param view site view owner of this proxy
46 * @param locatorName name of profile locator associated
47 * with the proxy delegate
48 * @param parentFolder view parent proxy folder
49 * @param link proxy delegate
50 */
51 public static Link newInstance(SiteView view, String locatorName, Folder parentFolder, Link link)
52 {
53 return (Link)Proxy.newProxyInstance(link.getClass().getClassLoader(), new Class[]{Link.class}, new LinkProxy(view, locatorName, parentFolder, link));
54 }
55
56 /***
57 * LinkProxy - private constructor used by newInstance()
58 *
59 * @param view site view owner of this proxy
60 * @param locatorName name of profile locator associated
61 * with the proxy delegate
62 * @param parentFolder view parent proxy folder
63 * @param link proxy delegate
64 */
65 private LinkProxy(SiteView view, String locatorName, Folder parentFolder, Link link)
66 {
67 super(view, locatorName, parentFolder, link.getName(), link.isHidden());
68 this.link = link;
69 }
70
71 /***
72 * invoke - method invocation dispatch for this proxy, (defaults to
73 * invocation of delegate unless method is implemented in this
74 * proxy handler or should be hidden/stubbed)
75 *
76 * @param proxy instance invoked against
77 * @param method Link interface method invoked
78 * @param args method arguments
79 * @throws Throwable
80 */
81 public Object invoke(Object proxy, Method m, Object [] args) throws Throwable
82 {
83
84 if (m.equals(GET_PARENT_METHOD))
85 {
86 return getParent();
87 }
88 else if (m.equals(GET_PATH_METHOD))
89 {
90 return getPath();
91 }
92 else if (m.equals(EQUALS_METHOD))
93 {
94 return new Boolean(equals(args[0]));
95 }
96 else if (m.equals(HASH_CODE_METHOD))
97 {
98 return new Integer(hashCode());
99 }
100 else if (m.equals(IS_HIDDEN_METHOD))
101 {
102 return new Boolean(isHidden());
103 }
104 else if (m.equals(TO_STRING_METHOD))
105 {
106 return toString();
107 }
108
109
110 if (m.getName().startsWith("set"))
111 {
112 throw new RuntimeException("Link instance is immutable from proxy.");
113 }
114
115
116 return m.invoke(link, args);
117 }
118
119 /***
120 * getLink - get proxy delegate link instance
121 *
122 * @return delegate link
123 */
124 public Link getLink()
125 {
126 return link;
127 }
128 }