01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS"
13: * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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
27: InvocationHandler {
28: private PortletDefinitionComposite def = null;
29: private static PortletRegistry registry;
30: private String name;
31:
32: public PortletDefinitionCompositeProxy(
33: PortletDefinitionComposite def) {
34: this .def = def;
35: this .name = def.getUniqueName();
36: }
37:
38: public static void setRegistry(PortletRegistry r) {
39: registry = r;
40: }
41:
42: public static PortletDefinitionComposite createProxy(
43: PortletDefinitionComposite def) {
44: Class[] proxyInterfaces = new Class[] { PortletDefinitionComposite.class };
45: PortletDefinitionComposite proxy = (PortletDefinitionComposite) Proxy
46: .newProxyInstance(PortletDefinitionComposite.class
47: .getClassLoader(), proxyInterfaces,
48: new PortletDefinitionCompositeProxy(def));
49: return proxy;
50: }
51:
52: protected void invalidate() {
53: this .def = null;
54: }
55:
56: protected void setRealDefinition(PortletDefinitionComposite d) {
57: this .def = d;
58: }
59:
60: protected PortletDefinitionComposite getRealApplication() {
61: return def;
62: }
63:
64: public Object invoke(Object proxy, Method m, Object[] args)
65: throws Throwable {
66: try {
67: if (def == null) {
68: def = registry.getPortletDefinitionByUniqueName(name);
69: }
70: return m.invoke(def, args);
71: } catch (InvocationTargetException e) {
72: throw e.getTargetException();
73: }
74: }
75:
76: }
|