KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.corba.se.spi.orbutil.proxy ;
2
3 import java.io.Serializable JavaDoc ;
4
5 import java.util.Map JavaDoc ;
6 import java.util.LinkedHashMap JavaDoc ;
7   
8 import java.lang.reflect.Proxy JavaDoc ;
9 import java.lang.reflect.Method JavaDoc ;
10 import java.lang.reflect.InvocationHandler JavaDoc ;
11
12 import com.sun.corba.se.spi.logging.CORBALogDomains ;
13 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
14
15 public class CompositeInvocationHandlerImpl implements
16     CompositeInvocationHandler
17 {
18     private Map JavaDoc classToInvocationHandler = new LinkedHashMap JavaDoc() ;
19     private InvocationHandler JavaDoc defaultHandler = null ;
20
21     public void addInvocationHandler( Class JavaDoc interf,
22     InvocationHandler JavaDoc handler )
23     {
24     classToInvocationHandler.put( interf, handler ) ;
25     }
26
27     public void setDefaultHandler( InvocationHandler JavaDoc handler )
28     {
29     defaultHandler = handler ;
30     }
31
32     public Object JavaDoc invoke( Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args )
33     throws Throwable JavaDoc
34     {
35     // Note that the declaring class in method is the interface
36
// in which the method was defined, not the proxy class.
37
Class JavaDoc cls = method.getDeclaringClass() ;
38     InvocationHandler JavaDoc handler =
39         (InvocationHandler JavaDoc)classToInvocationHandler.get( cls ) ;
40
41     if (handler == null) {
42         if (defaultHandler != null)
43         handler = defaultHandler ;
44         else {
45         ORBUtilSystemException wrapper = ORBUtilSystemException.get(
46             CORBALogDomains.UTIL ) ;
47         throw wrapper.noInvocationHandler( "\"" + method.toString() +
48             "\"" ) ;
49         }
50     }
51
52     // handler should never be null here.
53

54     return handler.invoke( proxy, method, args ) ;
55     }
56 }
57
Popular Tags