aoqi@0: /* msheppar@1294: * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: /* aoqi@0: * Licensed Materials - Property of IBM aoqi@0: * RMI-IIOP v1.0 aoqi@0: * Copyright IBM Corp. 1998 1999 All Rights Reserved aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: package javax.rmi.CORBA; aoqi@0: aoqi@0: import java.rmi.RemoteException; aoqi@0: aoqi@0: import org.omg.CORBA.ORB; aoqi@0: import org.omg.CORBA.INITIALIZE; aoqi@0: import org.omg.CORBA.SystemException; aoqi@0: import org.omg.CORBA.Any; aoqi@0: import org.omg.CORBA.portable.InputStream; aoqi@0: import org.omg.CORBA.portable.OutputStream; aoqi@0: import org.omg.CORBA.portable.ObjectImpl; aoqi@0: aoqi@0: import javax.rmi.CORBA.Tie; aoqi@0: import java.rmi.Remote; aoqi@0: import java.io.File; aoqi@0: import java.io.FileInputStream; msheppar@1294: import java.io.SerializablePermission; aoqi@0: import java.net.MalformedURLException ; aoqi@0: import java.security.AccessController; aoqi@0: import java.security.PrivilegedAction; aoqi@0: import java.util.Properties; aoqi@0: import java.rmi.server.RMIClassLoader; aoqi@0: aoqi@0: import com.sun.corba.se.impl.orbutil.GetPropertyAction; aoqi@0: aoqi@0: /** aoqi@0: * Provides utility methods that can be used by stubs and ties to aoqi@0: * perform common operations. aoqi@0: */ aoqi@0: public class Util { aoqi@0: aoqi@0: // This can only be set at static initialization time (no sync necessary). aoqi@0: private static final javax.rmi.CORBA.UtilDelegate utilDelegate; aoqi@0: private static final String UtilClassKey = "javax.rmi.CORBA.UtilClass"; aoqi@0: msheppar@1294: private static final String ALLOW_CREATEVALUEHANDLER_PROP = "jdk.rmi.CORBA.allowCustomValueHandler"; msheppar@1294: private static boolean allowCustomValueHandler; msheppar@1294: aoqi@0: static { aoqi@0: utilDelegate = (javax.rmi.CORBA.UtilDelegate)createDelegate(UtilClassKey); msheppar@1294: allowCustomValueHandler = readAllowCustomValueHandlerProperty(); msheppar@1294: } msheppar@1294: msheppar@1294: private static boolean readAllowCustomValueHandlerProperty () { msheppar@1294: return AccessController msheppar@1294: .doPrivileged(new PrivilegedAction() { msheppar@1294: @Override msheppar@1294: public Boolean run() { msheppar@1294: return Boolean.getBoolean(ALLOW_CREATEVALUEHANDLER_PROP); msheppar@1294: } msheppar@1294: }); aoqi@0: } aoqi@0: aoqi@0: private Util(){} aoqi@0: aoqi@0: /** aoqi@0: * Maps a SystemException to a RemoteException. aoqi@0: * @param ex the SystemException to map. aoqi@0: * @return the mapped exception. aoqi@0: */ aoqi@0: public static RemoteException mapSystemException(SystemException ex) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: return utilDelegate.mapSystemException(ex); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Writes any java.lang.Object as a CORBA any. aoqi@0: * @param out the stream in which to write the any. aoqi@0: * @param obj the object to write as an any. aoqi@0: */ aoqi@0: public static void writeAny(OutputStream out, Object obj) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: utilDelegate.writeAny(out, obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Reads a java.lang.Object as a CORBA any. aoqi@0: * @param in the stream from which to read the any. aoqi@0: * @return the object read from the stream. aoqi@0: */ aoqi@0: public static Object readAny(InputStream in) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: return utilDelegate.readAny(in); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Writes a java.lang.Object as a CORBA Object. If obj is aoqi@0: * an exported RMI-IIOP server object, the tie is found aoqi@0: * and wired to obj, then written to msheppar@1294: * out.write_Object(org.omg.CORBA.Object). aoqi@0: * If obj is a CORBA Object, it is written to aoqi@0: * out.write_Object(org.omg.CORBA.Object). aoqi@0: * @param out the stream in which to write the object. aoqi@0: * @param obj the object to write. aoqi@0: */ aoqi@0: public static void writeRemoteObject(OutputStream out, aoqi@0: java.lang.Object obj) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: utilDelegate.writeRemoteObject(out, obj); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Writes a java.lang.Object as either a value or a CORBA Object. aoqi@0: * If obj is a value object or a stub object, it is written to aoqi@0: * out.write_abstract_interface(java.lang.Object). If obj aoqi@0: is aoqi@0: an exported aoqi@0: * RMI-IIOP server object, the tie is found and wired to obj, aoqi@0: * then written to out.write_abstract_interface(java.lang.Object). aoqi@0: * @param out the stream in which to write the object. aoqi@0: * @param obj the object to write. aoqi@0: */ aoqi@0: public static void writeAbstractObject(OutputStream out, aoqi@0: java.lang.Object obj) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: utilDelegate.writeAbstractObject(out, obj); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Registers a target for a tie. Adds the tie to an internal table and calls aoqi@0: * {@link Tie#setTarget} on the tie object. aoqi@0: * @param tie the tie to register. aoqi@0: * @param target the target for the tie. aoqi@0: */ aoqi@0: public static void registerTarget(javax.rmi.CORBA.Tie tie, aoqi@0: java.rmi.Remote target) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: utilDelegate.registerTarget(tie, target); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Removes the associated tie from an internal table and calls {@link aoqi@0: Tie#deactivate} aoqi@0: * to deactivate the object. aoqi@0: * @param target the object to unexport. aoqi@0: */ aoqi@0: public static void unexportObject(java.rmi.Remote target) aoqi@0: throws java.rmi.NoSuchObjectException aoqi@0: { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: utilDelegate.unexportObject(target); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns the tie (if any) for a given target object. aoqi@0: * @return the tie or null if no tie is registered for the given target. aoqi@0: */ aoqi@0: public static Tie getTie (Remote target) { aoqi@0: aoqi@0: if (utilDelegate != null) { aoqi@0: return utilDelegate.getTie(target); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Returns a singleton instance of a class that implements the aoqi@0: * {@link ValueHandler} interface. aoqi@0: * @return a class which implements the ValueHandler interface. aoqi@0: */ aoqi@0: public static ValueHandler createValueHandler() { aoqi@0: msheppar@1294: isCustomSerializationPermitted(); msheppar@1294: aoqi@0: if (utilDelegate != null) { aoqi@0: return utilDelegate.createValueHandler(); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns the codebase, if any, for the given class. aoqi@0: * @param clz the class to get a codebase for. aoqi@0: * @return a space-separated list of URLs, or null. aoqi@0: */ aoqi@0: public static String getCodebase(java.lang.Class clz) { aoqi@0: if (utilDelegate != null) { aoqi@0: return utilDelegate.getCodebase(clz); aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns a class instance for the specified class. aoqi@0: *

The spec for this method is the "Java to IDL language aoqi@0: * mapping", ptc/00-01-06. aoqi@0: *

In Java SE Platform, this method works as follows: aoqi@0: *