KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > DelegateInvocationHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28  
29 /*
30  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/support/DelegateInvocationHandler.java,v 1.2 2005/12/25 03:40:40 tcfujii Exp $
31  * $Revision: 1.2 $
32  * $Date: 2005/12/25 03:40:40 $
33  */

34
35 package com.sun.enterprise.management.support;
36
37 import java.lang.reflect.Proxy JavaDoc;
38 import java.lang.reflect.Method JavaDoc;
39 import java.lang.reflect.InvocationHandler JavaDoc;
40
41 import com.sun.appserv.management.util.misc.ClassUtil;
42
43 /**
44  */

45 public final class DelegateInvocationHandler implements InvocationHandler JavaDoc
46 {
47     private final Delegate mDelegate;
48     
49         private
50     DelegateInvocationHandler( final Delegate delegate )
51     {
52         mDelegate = delegate;
53     }
54     
55         static public Object JavaDoc
56     newProxyInstance(
57         Delegate delegate,
58         Class JavaDoc interfaceClass )
59     {
60         final DelegateInvocationHandler handler =
61             new DelegateInvocationHandler( delegate );
62             
63         final ClassLoader JavaDoc classLoader = interfaceClass.getClassLoader();
64         
65         final Class JavaDoc[] interfaces = new Class JavaDoc[] { interfaceClass };
66         final Object JavaDoc proxy = Proxy.newProxyInstance( classLoader,
67                             interfaces, handler);
68         
69         return( proxy );
70     }
71     
72     /**
73         Just forward whatever it is to the Delegate
74      */

75         public Object JavaDoc
76     invoke(
77         Object JavaDoc proxy,
78         Method JavaDoc method,
79         Object JavaDoc[] args
80         )
81         throws java.lang.Throwable JavaDoc
82     {
83         final Class JavaDoc[] sig = method.getParameterTypes();
84         
85         return( mDelegate.invoke( method.getName(), args, ClassUtil.classnamesFromSignature( sig ) ) );
86     }
87     
88 }
89
90
91
92
93
94
95
96
97
98
99
100
Popular Tags