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

Mon, 22 Jul 2013 19:38:08 -0700

author
mchung
date
Mon, 22 Jul 2013 19:38:08 -0700
changeset 515
be4fdc568d73
parent 158
91006f157c46
child 539
b99535e22efe
permissions
-rw-r--r--

8017196: Ensure Proxies are handled appropriately
Reviewed-by: dfuchs, jrose, jdn, ahgross, chegar

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 ;
mchung@515 39 import com.sun.corba.se.impl.presentation.rmi.DynamicAccessPermission;
duke@1 40
duke@1 41 public class CompositeInvocationHandlerImpl implements
duke@1 42 CompositeInvocationHandler
duke@1 43 {
duke@1 44 private Map classToInvocationHandler = new LinkedHashMap() ;
duke@1 45 private InvocationHandler defaultHandler = null ;
duke@1 46
duke@1 47 public void addInvocationHandler( Class interf,
duke@1 48 InvocationHandler handler )
duke@1 49 {
mchung@515 50 checkAccess();
duke@1 51 classToInvocationHandler.put( interf, handler ) ;
duke@1 52 }
duke@1 53
duke@1 54 public void setDefaultHandler( InvocationHandler handler )
duke@1 55 {
mchung@515 56 checkAccess();
duke@1 57 defaultHandler = handler ;
duke@1 58 }
duke@1 59
duke@1 60 public Object invoke( Object proxy, Method method, Object[] args )
duke@1 61 throws Throwable
duke@1 62 {
duke@1 63 // Note that the declaring class in method is the interface
duke@1 64 // in which the method was defined, not the proxy class.
duke@1 65 Class cls = method.getDeclaringClass() ;
duke@1 66 InvocationHandler handler =
duke@1 67 (InvocationHandler)classToInvocationHandler.get( cls ) ;
duke@1 68
duke@1 69 if (handler == null) {
duke@1 70 if (defaultHandler != null)
duke@1 71 handler = defaultHandler ;
duke@1 72 else {
duke@1 73 ORBUtilSystemException wrapper = ORBUtilSystemException.get(
duke@1 74 CORBALogDomains.UTIL ) ;
duke@1 75 throw wrapper.noInvocationHandler( "\"" + method.toString() +
duke@1 76 "\"" ) ;
duke@1 77 }
duke@1 78 }
duke@1 79
duke@1 80 // handler should never be null here.
duke@1 81
duke@1 82 return handler.invoke( proxy, method, args ) ;
duke@1 83 }
mchung@515 84
mchung@515 85 private static final DynamicAccessPermission perm = new DynamicAccessPermission("access");
mchung@515 86 private void checkAccess() {
mchung@515 87 final SecurityManager sm = System.getSecurityManager();
mchung@515 88 if (sm != null) {
mchung@515 89 sm.checkPermission(perm);
duke@1 90 }
mchung@515 91 }
mchung@515 92 }

mercurial