src/share/classes/com/sun/corba/se/spi/orbutil/proxy/CompositeInvocationHandlerImpl.java

Tue, 25 May 2010 15:52:11 -0700

author
ohair
date
Tue, 25 May 2010 15:52:11 -0700
changeset 158
91006f157c46
parent 1
55540e827aef
child 515
be4fdc568d73
permissions
-rw-r--r--

6943119: Rebrand source copyright notices
Reviewed-by: darcy

duke@1 1 /*
ohair@158 2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.corba.se.spi.orbutil.proxy ;
duke@1 27
duke@1 28 import java.io.Serializable ;
duke@1 29
duke@1 30 import java.util.Map ;
duke@1 31 import java.util.LinkedHashMap ;
duke@1 32
duke@1 33 import java.lang.reflect.Proxy ;
duke@1 34 import java.lang.reflect.Method ;
duke@1 35 import java.lang.reflect.InvocationHandler ;
duke@1 36
duke@1 37 import com.sun.corba.se.spi.logging.CORBALogDomains ;
duke@1 38 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
duke@1 39
duke@1 40 public class CompositeInvocationHandlerImpl implements
duke@1 41 CompositeInvocationHandler
duke@1 42 {
duke@1 43 private Map classToInvocationHandler = new LinkedHashMap() ;
duke@1 44 private InvocationHandler defaultHandler = null ;
duke@1 45
duke@1 46 public void addInvocationHandler( Class interf,
duke@1 47 InvocationHandler handler )
duke@1 48 {
duke@1 49 classToInvocationHandler.put( interf, handler ) ;
duke@1 50 }
duke@1 51
duke@1 52 public void setDefaultHandler( InvocationHandler handler )
duke@1 53 {
duke@1 54 defaultHandler = handler ;
duke@1 55 }
duke@1 56
duke@1 57 public Object invoke( Object proxy, Method method, Object[] args )
duke@1 58 throws Throwable
duke@1 59 {
duke@1 60 // Note that the declaring class in method is the interface
duke@1 61 // in which the method was defined, not the proxy class.
duke@1 62 Class cls = method.getDeclaringClass() ;
duke@1 63 InvocationHandler handler =
duke@1 64 (InvocationHandler)classToInvocationHandler.get( cls ) ;
duke@1 65
duke@1 66 if (handler == null) {
duke@1 67 if (defaultHandler != null)
duke@1 68 handler = defaultHandler ;
duke@1 69 else {
duke@1 70 ORBUtilSystemException wrapper = ORBUtilSystemException.get(
duke@1 71 CORBALogDomains.UTIL ) ;
duke@1 72 throw wrapper.noInvocationHandler( "\"" + method.toString() +
duke@1 73 "\"" ) ;
duke@1 74 }
duke@1 75 }
duke@1 76
duke@1 77 // handler should never be null here.
duke@1 78
duke@1 79 return handler.invoke( proxy, method, args ) ;
duke@1 80 }
duke@1 81 }

mercurial