001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.portalsite.view;
018:
019: import java.lang.reflect.Method;
020: import java.lang.reflect.Proxy;
021:
022: /**
023: * This class is the base class for all site content
024: * proxy implementations.
025: *
026: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
027: * @version $Id: SiteViewProxy.java 516448 2007-03-09 16:25:47Z ate $
028: */
029: public abstract class SiteViewProxy {
030: /**
031: * view - site view this proxy is part of
032: */
033: private SiteView view;
034:
035: /**
036: * locatorName - name of profile locator name associated
037: * with the derived delegate of this proxy
038: * in the site view
039: */
040: private String locatorName;
041:
042: /**
043: * SiteViewProxy - constructor
044: *
045: * @param view site view owner of this proxy
046: * @param locatorName profile locator name associated with
047: * the derived delegate of this proxy in
048: * the site view
049: */
050: protected SiteViewProxy(SiteView view, String locatorName) {
051: this .view = view;
052: this .locatorName = locatorName;
053: }
054:
055: /**
056: * getView - return site view for this proxy
057: *
058: * @return site view
059: */
060: public SiteView getView() {
061: return view;
062: }
063:
064: /**
065: * getLocatorName - return profile locator name associated
066: * with the derived delegate of this proxy in
067: * the site view
068: *
069: * @return profile locator name
070: */
071: public String getLocatorName() {
072: return locatorName;
073: }
074:
075: /**
076: * reflectMethod - trap method reflection exceptions utility function
077: *
078: * @param methodClass class or interface
079: * @param methodName method name
080: * @param methodArgs array of type, class, or interface parameter types
081: */
082: protected static Method reflectMethod(Class methodClass,
083: String methodName, Class[] methodArgs) {
084: // trap reflection exceptions
085: try {
086: return methodClass.getMethod(methodName, methodArgs);
087: } catch (NoSuchMethodException nsme) {
088: RuntimeException rte = new RuntimeException(
089: "SiteViewProxy.reflectMethod(): unexpected reflection exception for: "
090: + methodClass.getName() + "." + methodName);
091: rte.initCause(nsme);
092: throw rte;
093: }
094: }
095:
096: /**
097: * getSiteViewProxy - utility method to access SiteViewProxy handler
098: * from a proxy instance
099: *
100: * @param proxy proxy instance
101: * @return site view invocation handler instance
102: */
103: public static SiteViewProxy getSiteViewProxy(Object proxy) {
104: if ((proxy != null) && Proxy.isProxyClass(proxy.getClass())) {
105: Object proxyHandler = Proxy.getInvocationHandler(proxy);
106: if (proxyHandler instanceof SiteViewProxy) {
107: return (SiteViewProxy) proxyHandler;
108: }
109: }
110: return null;
111: }
112: }
|