KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > orbutil > proxy > DelegateInvocationHandlerImpl


1 /*
2  * @(#)DelegateInvocationHandlerImpl.java 1.9 05/10/31
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.spi.orbutil.proxy ;
9
10 import java.io.Serializable JavaDoc ;
11
12 import java.util.Map JavaDoc ;
13 import java.util.LinkedHashMap JavaDoc ;
14   
15 import java.lang.reflect.Proxy JavaDoc ;
16 import java.lang.reflect.Method JavaDoc ;
17 import java.lang.reflect.InvocationHandler JavaDoc ;
18 import java.lang.reflect.InvocationTargetException JavaDoc ;
19 import com.sun.corba.se.impl.presentation.rmi.DynamicAccessPermission ;
20
21 public abstract class DelegateInvocationHandlerImpl
22 {
23     private DelegateInvocationHandlerImpl() {}
24
25     public static InvocationHandler JavaDoc create( final Object JavaDoc delegate )
26     {
27         SecurityManager JavaDoc s = System.getSecurityManager();
28         if (s != null) {
29             s.checkPermission(new DynamicAccessPermission("access"));
30         }
31
32     return new InvocationHandler JavaDoc() {
33         public Object JavaDoc invoke( Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args )
34         throws Throwable JavaDoc
35         {
36         // This throws an IllegalArgument exception if the delegate
37
// is not assignable from method.getDeclaring class.
38
try {
39             return method.invoke( delegate, args ) ;
40         } catch (InvocationTargetException JavaDoc ite) {
41             // Propagate the underlying exception as the
42
// result of the invocation
43
throw ite.getCause() ;
44         }
45         }
46     } ;
47     }
48 }
49
Popular Tags