KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > impl > factory > PassThroughInvocationHandler


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.fortress.impl.factory;
19
20 import java.lang.reflect.InvocationHandler JavaDoc;
21 import java.lang.reflect.InvocationTargetException JavaDoc;
22 import java.lang.reflect.Method JavaDoc;
23
24 /**
25  * InvocationHandler that just passes on all methods to target object.
26  *
27  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
28  */

29 final class PassThroughInvocationHandler
30     implements InvocationHandler JavaDoc
31 {
32     /**
33      * The target object delegated to.
34      */

35     private final Object JavaDoc m_object;
36
37     /**
38      * Create an Invocation handler for specified object.
39      *
40      * @param object the object to delegate to
41      */

42     public PassThroughInvocationHandler( final Object JavaDoc object )
43     {
44         if ( null == object )
45         {
46             throw new NullPointerException JavaDoc( "object" );
47         }
48
49         m_object = object;
50     }
51
52     /**
53      * Invoke the appropriate method on underlying object.
54      *
55      * @param proxy the proxy object
56      * @param meth the method
57      * @param args the arguments
58      * @return the return value of object
59      * @exception Throwable method throws an exception
60      */

61     public Object JavaDoc invoke( final Object JavaDoc proxy,
62                           final Method JavaDoc meth,
63                           final Object JavaDoc[] args )
64         throws Throwable JavaDoc
65     {
66         try
67         {
68             return meth.invoke( m_object, args );
69         }
70         catch ( final InvocationTargetException JavaDoc ite )
71         {
72             throw ite.getTargetException();
73         }
74     }
75
76     /**
77      * Retrieve the underlying object delegated to.
78      *
79      * @return the object delegated to
80      */

81     Object JavaDoc getObject()
82     {
83         return m_object;
84     }
85 }
86
Popular Tags