1 package com.sun.corba.se.spi.orbutil.proxy ; 2 3 import java.io.Serializable ; 4 5 import java.util.Map ; 6 import java.util.LinkedHashMap ; 7 8 import java.lang.reflect.Proxy ; 9 import java.lang.reflect.Method ; 10 import java.lang.reflect.InvocationHandler ; 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 classToInvocationHandler = new LinkedHashMap () ; 19 private InvocationHandler defaultHandler = null ; 20 21 public void addInvocationHandler( Class interf, 22 InvocationHandler handler ) 23 { 24 classToInvocationHandler.put( interf, handler ) ; 25 } 26 27 public void setDefaultHandler( InvocationHandler handler ) 28 { 29 defaultHandler = handler ; 30 } 31 32 public Object invoke( Object proxy, Method method, Object [] args ) 33 throws Throwable 34 { 35 Class cls = method.getDeclaringClass() ; 38 InvocationHandler handler = 39 (InvocationHandler )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 54 return handler.invoke( proxy, method, args ) ; 55 } 56 } 57 | Popular Tags |