corba/src/java.corba/share/classes/javax/rmi/CORBA/Util.java
author avstepan
Sun, 13 Sep 2015 23:31:47 +0300
changeset 32688 936c391804a5
parent 29827 aac4782e69ac
child 39784 cbd312af640f
permissions -rw-r--r--
8133650: replace some <tt> tags (obsolete in html5) in CORBA docs Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
29827
aac4782e69ac 8039440: Tidy warnings cleanup for org/omg
avstepan
parents: 25862
diff changeset
     2
 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package javax.rmi.CORBA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.rmi.RemoteException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.INITIALIZE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.CORBA.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.portable.ObjectImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import javax.rmi.CORBA.Tie;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.io.FileInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.net.MalformedURLException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.rmi.server.RMIClassLoader;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.corba.se.impl.orbutil.GetPropertyAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * Provides utility methods that can be used by stubs and ties to
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 * perform common operations.
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
public class Util {
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    // This can only be set at static initialization time (no sync necessary).
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 5555
diff changeset
    63
    private static final javax.rmi.CORBA.UtilDelegate utilDelegate;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    private static final String UtilClassKey = "javax.rmi.CORBA.UtilClass";
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    static {
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 5555
diff changeset
    67
        utilDelegate = (javax.rmi.CORBA.UtilDelegate)createDelegate(UtilClassKey);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    private Util(){}
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
     * Maps a SystemException to a RemoteException.
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
     * @param ex the SystemException to map.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
     * @return the mapped exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    public static RemoteException mapSystemException(SystemException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
            return utilDelegate.mapSystemException(ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
     * Writes any java.lang.Object as a CORBA any.
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
     * @param out the stream in which to write the any.
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
     * @param obj the object to write as an any.
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    public static void writeAny(OutputStream out, Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            utilDelegate.writeAny(out, obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
     * Reads a java.lang.Object as a CORBA any.
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
     * @param in the stream from which to read the any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
     * @return the object read from the stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    public static Object readAny(InputStream in) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            return utilDelegate.readAny(in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    /**
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   111
     * Writes a java.lang.Object as a CORBA Object. If {@code obj} is
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     * an exported RMI-IIOP server object, the tie is found
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   113
     * and wired to {@code obj}, then written to
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   114
     * {@code out.write_Object(org.omg.CORBA.Object)}.
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   115
     * If {@code obj} is a CORBA Object, it is written to
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   116
     * {@code out.write_Object(org.omg.CORBA.Object)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
     * @param out the stream in which to write the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
     * @param obj the object to write.
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    public static void writeRemoteObject(OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                                         java.lang.Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            utilDelegate.writeRemoteObject(out, obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
     * Writes a java.lang.Object as either a value or a CORBA Object.
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   131
     * If {@code obj} is a value object or a stub object, it is written to
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   132
     * {@code out.write_abstract_interface(java.lang.Object)}.
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   133
     * If {@code obj} is an exported
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   134
     * RMI-IIOP server object, the tie is found and wired to {@code obj},
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   135
     * then written to {@code out.write_abstract_interface(java.lang.Object)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
     * @param out the stream in which to write the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
     * @param obj the object to write.
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    public static void writeAbstractObject(OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
                                           java.lang.Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            utilDelegate.writeAbstractObject(out, obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
     * Registers a target for a tie. Adds the tie to an internal table and calls
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
     * {@link Tie#setTarget} on the tie object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
     * @param tie the tie to register.
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
     * @param target the target for the tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    public static void registerTarget(javax.rmi.CORBA.Tie tie,
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                                      java.rmi.Remote target) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
            utilDelegate.registerTarget(tie, target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    /**
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   163
     * Removes the associated tie from an internal table
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   164
     * and calls {@link Tie#deactivate}
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * to deactivate the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * @param target the object to unexport.
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    public static void unexportObject(java.rmi.Remote target)
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        throws java.rmi.NoSuchObjectException
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
            utilDelegate.unexportObject(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
     * Returns the tie (if any) for a given target object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
     * @return the tie or null if no tie is registered for the given target.
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    public static Tie getTie (Remote target) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
            return utilDelegate.getTie(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
     * Returns a singleton instance of a class that implements the
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
     * {@link ValueHandler} interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
     * @return a class which implements the ValueHandler interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    public static ValueHandler createValueHandler() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            return utilDelegate.createValueHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * Returns the codebase, if any, for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     * @param clz the class to get a codebase for.
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
     * @return a space-separated list of URLs, or null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    public static String getCodebase(java.lang.Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
            return utilDelegate.getCodebase(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
     * Returns a class instance for the specified class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
     * <P>The spec for this method is the "Java to IDL language
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
     * mapping", ptc/00-01-06.
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
     * <P>In Java SE Platform, this method works as follows:
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   221
     * <UL><LI>Find the first non-null {@code ClassLoader} on the
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
     * call stack and attempt to load the class using this
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   223
     * {@code ClassLoader}.
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   224
     * <LI>If the first step fails, and if {@code remoteCodebase}
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
     * is non-null and
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   226
     * {@code useCodebaseOnly} is false, then call
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   227
     * {@code java.rmi.server.RMIClassLoader.loadClass(remoteCodebase, className)}.
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   228
     * <LI>If {@code remoteCodebase} is null or {@code useCodebaseOnly}
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   229
     * is true, then call {@code java.rmi.server.RMIClassLoader.loadClass(className)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
     * <LI>If a class was not successfully loaded by step 1, 2, or 3,
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   231
     * and {@code loader} is non-null, then call {@code loader.loadClass(className)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
     * <LI>If a class was successfully loaded by step 1, 2, 3, or 4, then
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   233
     *  return the loaded class, else throw {@code ClassNotFoundException}.
29827
aac4782e69ac 8039440: Tidy warnings cleanup for org/omg
avstepan
parents: 25862
diff changeset
   234
     * </UL>
aac4782e69ac 8039440: Tidy warnings cleanup for org/omg
avstepan
parents: 25862
diff changeset
   235
     *
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
     * @param className the name of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
     * @param remoteCodebase a space-separated list of URLs at which
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
     * the class might be found. May be null.
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   239
     * @param loader a {@code ClassLoader} that may be used to
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
     * load the class if all other methods fail.
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   241
     * @return the {@code Class} object representing the loaded class.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
     * @exception ClassNotFoundException if class cannot be loaded.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    public static Class loadClass(String className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
                                  String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                                  ClassLoader loader)
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
        throws ClassNotFoundException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            return utilDelegate.loadClass(className,remoteCodebase,loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    /**
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   256
     * The {@code isLocal} method has the same semantics as the
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   257
     * {@code ObjectImpl._is_local}
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   258
     * method, except that it can throw a {@code RemoteException}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
     *
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   260
     * The {@code _is_local()} method is provided so that stubs may determine if a
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
     * particular object is implemented by a local servant and hence local
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
     * invocation APIs may be used.
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
     * @param stub the stub to test.
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
     *
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   266
     * @return The {@code _is_local()} method returns true if
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
     * the servant incarnating the object is located in the same process as
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   268
     * the stub and they both share the same ORB instance.  The {@code _is_local()}
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   269
     * method returns false otherwise. The default behavior of {@code _is_local()} is
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
     * to return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
     * @throws RemoteException The Java to IDL specification does not
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 29827
diff changeset
   273
     * specify the conditions that cause a {@code RemoteException} to be thrown.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    public static boolean isLocal(Stub stub) throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
            return utilDelegate.isLocal(stub);
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
     * Wraps an exception thrown by an implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
     * method.  It returns the corresponding client-side exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
     * @param orig the exception to wrap.
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
     * @return the wrapped exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    public static RemoteException wrapException(Throwable orig) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
            return utilDelegate.wrapException(orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
     * Copies or connects an array of objects. Used by local stubs
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
     * to copy any number of actual parameters, preserving sharing
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
     * across parameters as necessary to support RMI semantics.
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
     * @param obj the objects to copy or connect.
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
     * @param orb the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
     * @return the copied or connected objects.
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
     * @exception RemoteException if any object could not be copied or connected.
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    public static Object[] copyObjects (Object[] obj, ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
            return utilDelegate.copyObjects(obj, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
     * Copies or connects an object. Used by local stubs to copy
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
     * an actual parameter, result object, or exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
     * @param obj the object to copy.
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
     * @param orb the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
     * @return the copy or connected object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
     * @exception RemoteException if the object could not be copied or connected.
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    public static Object copyObject (Object obj, ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        if (utilDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
            return utilDelegate.copyObject(obj, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
    // Same code as in PortableRemoteObject. Can not be shared because they
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
    // are in different packages and the visibility needs to be package for
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    // security reasons. If you know a better solution how to share this code
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    // then remove it from PortableRemoteObject. Also in Stub.java
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 5555
diff changeset
   339
    private static Object createDelegate(String classKey) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
        String className = (String)
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
            AccessController.doPrivileged(new GetPropertyAction(classKey));
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
        if (className == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
            Properties props = getORBPropertiesFile();
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
            if (props != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                className = props.getProperty(classKey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        if (className == null) {
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 5555
diff changeset
   350
            return new com.sun.corba.se.impl.javax.rmi.CORBA.Util();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            return loadDelegateClass(className).newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        } catch (ClassNotFoundException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            INITIALIZE exc = new INITIALIZE( "Cannot instantiate " + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            INITIALIZE exc = new INITIALIZE( "Error while instantiating" + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    private static Class loadDelegateClass( String className )  throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
            return Class.forName(className, false, loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
            // ignore, then try RMIClassLoader
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            return RMIClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        } catch (MalformedURLException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
            String msg = "Could not load " + className + ": " + e.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
            ClassNotFoundException exc = new ClassNotFoundException( msg ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
     * Load the orb.properties file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
    private static Properties getORBPropertiesFile ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        return (Properties) AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
            new GetORBPropertiesFileAction());
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
}