KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > component > proxy > ProxyInvoker


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.component.proxy;
19
20 import java.lang.reflect.InvocationHandler JavaDoc;
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.lang.reflect.Proxy JavaDoc;
23
24 import org.sape.carbon.core.component.Component;
25
26 /**
27  * <p>This class provides the final invocation on the targe class. This class
28  * or something similar should always be at the end of interceptor chains that
29  * are configured to execute the supplied invocations.</p>
30  *
31  * Copyright 2003 Sapient
32  * @since carbon 2.0
33  * @author Greg Hinkle, March 2003
34  * @version $Revision: 1.6 $($Author: ghinkl $ / $Date: 2003/10/14 16:40:35 $)
35  */

36 public class ProxyInvoker implements Interceptor {
37
38
39     /**
40      * This method sets the next interceptor as the next in the chain from the
41      * current interceptor.
42      * @param interceptor the next interceptor in the chain
43      */

44     public void setNextInterceptor(Interceptor interceptor) {
45         throw new UnsupportedOperationException JavaDoc(
46             "ProxyInvoker is designed to be configured at the end of the "
47                 + "interceptor chain. It makes no sense to configure it "
48                 + "before the end of the chain. Please check your "
49                 + "Component Template Configuration.");
50     }
51
52     /**
53      * Handles the delegation to the target of the component call. The
54      * target will either be the Functional Implementation object or
55      * one of the interceptors (delegates).
56      *
57      * @param invocation the invocation to execute
58      * @return the results of the invocation's execution
59      * @throws Throwable indicates an error in the invokation chain
60      */

61     public Object JavaDoc invoke(Invocation invocation)
62             throws Throwable JavaDoc {
63
64         try {
65             // GH: There used to be a shortcut for proxy calls
66
// that would directly call the invocation handler
67
// rather than using a reflective invoke. This was
68
// removed as the component target calls are not
69
// like this and the Proxy.isProxyClass test causes
70
// too much of a slowdown.
71
return invocation.getMethod().invoke(
72                 invocation.getTarget(),
73                 invocation.getMethodArguments()
74             );
75         } catch (IllegalAccessException JavaDoc iae) {
76             throw iae;
77         } catch (InvocationTargetException JavaDoc ite) {
78             throw ite.getTargetException();
79         }
80
81     }
82
83     /**
84      * This should return the list of interfaces that a decorator wishes to
85      * expose through the component proxy. This is used by the
86      * component factory to determine what interfaces the component proxy will
87      * implement.
88      *
89      * @return Class[] an array of interfaces
90      */

91     public Class JavaDoc[] getExposedInterfaces() {
92         return new Class JavaDoc[0];
93     }
94
95     /**
96      * Called after creation to pass a reference to the component to each of
97      * its decorators. The component reference should not be used within
98      * this method because not all other interceptors have this reference yet
99      * and they may rely on this reference thus leading to null pointer
100      * exceptions.
101      *
102      * @param component a reference to the component that this interceptor is
103      * assisting
104      */

105     public void setComponentReference(Component component) {
106     }
107
108 }
109
Popular Tags