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