corba/src/java.corba/share/classes/javax/rmi/PortableRemoteObject.java
author msheppar
Thu, 01 Jun 2017 17:49:34 +0100
changeset 45443 57dbb6453a4d
parent 25862 a5e25d68f971
permissions -rw-r--r--
8176784: Amend HREF to technote/guides in CORBA API docs to unilinks for guides Reviewed-by: chegar, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
22131
4d7b21463768 8029231: Update copyright years for files in corba repository for 2013
ssides
parents: 21431
diff changeset
     2
 * Copyright (c) 1998, 2013, 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: 4623
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: 4623
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: 4623
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4623
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4623
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;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Method ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.INITIALIZE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.rmi.RemoteException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.rmi.NoSuchObjectException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.io.FileInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.net.MalformedURLException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.rmi.server.RMIClassLoader;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.corba.se.impl.orbutil.GetPropertyAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * Server implementation objects may either inherit from
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * javax.rmi.PortableRemoteObject or they may implement a remote interface
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * and then use the exportObject method to register themselves as a server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 * The toStub method takes a server implementation and returns a stub that
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * can be used to access that server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 * The connect method makes a Remote object ready for remote communication.
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
 * The unexportObject method is used to deregister a server object, allowing it to become
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
 * available for garbage collection.
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 * The narrow method takes an object reference or abstract interface type and
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
 * attempts to narrow it to conform to
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
 * the given interface. If the operation is successful the result will be an
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
 * object of the specified type, otherwise an exception will be thrown.
45443
57dbb6453a4d 8176784: Amend HREF to technote/guides in CORBA API docs to unilinks for guides
msheppar
parents: 25862
diff changeset
    65
 *
57dbb6453a4d 8176784: Amend HREF to technote/guides in CORBA API docs to unilinks for guides
msheppar
parents: 25862
diff changeset
    66
 * <p>See also {@extLink rmi_iiop_guides RMI-IIOP developer's guides}.</p>
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
public class PortableRemoteObject {
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 7672
diff changeset
    70
    private static final javax.rmi.CORBA.PortableRemoteObjectDelegate proDelegate;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    private static final String PortableRemoteObjectClassKey =
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
            "javax.rmi.CORBA.PortableRemoteObjectClass";
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        proDelegate = (javax.rmi.CORBA.PortableRemoteObjectDelegate)
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 7672
diff changeset
    77
            createDelegate(PortableRemoteObjectClassKey);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
     * Initializes the object by calling <code>exportObject(this)</code>.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
     * @exception RemoteException if export fails.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    protected PortableRemoteObject() throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            PortableRemoteObject.exportObject((Remote)this);
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
     * Makes a server object ready to receive remote calls. Note
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
     * that subclasses of PortableRemoteObject do not need to call this
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
     * method, as it is called by the constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
     * @param obj the server object to export.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
     * @exception RemoteException if export fails.
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    public static void exportObject(Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        // Let the delegate do everything, including error handling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            proDelegate.exportObject(obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
     * Returns a stub for the given server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * @param obj the server object for which a stub is required. Must either be a subclass
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     * of PortableRemoteObject or have been previously the target of a call to
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     * {@link #exportObject}.
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     * @return the most derived stub for the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     * @exception NoSuchObjectException if a stub cannot be located for the given server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    public static Remote toStub (Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        throws NoSuchObjectException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            return proDelegate.toStub(obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
     * Deregisters a server object from the runtime, allowing the object to become
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
     * available for garbage collection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
     * @param obj the object to unexport.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
     * @exception NoSuchObjectException if the remote object is not
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
     * currently exported.
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    public static void unexportObject(Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        throws NoSuchObjectException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
            proDelegate.unexportObject(obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
     * Checks to ensure that an object of a remote or abstract interface type
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
     * can be cast to a desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
     * @param narrowFrom the object to check.
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
     * @param narrowTo the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
     * @return an object which can be cast to the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
     * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    public static java.lang.Object narrow ( java.lang.Object narrowFrom,
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                                            java.lang.Class narrowTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        throws ClassCastException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            return proDelegate.narrow(narrowFrom, narrowTo);
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
     * Makes a Remote object ready for remote communication. This normally
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * happens implicitly when the object is sent or received as an argument
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * on a remote method call, but in some circumstances it is useful to
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * perform this action by making an explicit call.  See the
4623
e3aaa29eff65 6917485: Corba doc warnings
andrew
parents: 4
diff changeset
   163
     * {@link javax.rmi.CORBA.Stub#connect} method for more information.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
     * @param target the object to connect.
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * @param source a previously connected object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * @throws RemoteException if <code>source</code> is not connected
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     * or if <code>target</code> is already connected to a different ORB than
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     * <code>source</code>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    public static void connect (Remote target, Remote source)
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            proDelegate.connect(target, source);
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
    // Same code as in javax.rmi.CORBA.Util. Can not be shared because they
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    // are in different packages and the visibility needs to be package for
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    // security reasons. If you know a better solution how to share this code
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    // then remove it from here.
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 7672
diff changeset
   183
    private static Object createDelegate(String classKey) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
        String className = (String)
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
            AccessController.doPrivileged(new GetPropertyAction(classKey));
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        if (className == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
            Properties props = getORBPropertiesFile();
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            if (props != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                className = props.getProperty(classKey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        if (className == null) {
21431
6f404f8e434c 8021257: com.sun.corba.se.** should be on restricted package list
alanb
parents: 7672
diff changeset
   193
            return new com.sun.corba.se.impl.javax.rmi.PortableRemoteObject();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            return (Object) loadDelegateClass(className).newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        } catch (ClassNotFoundException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
            INITIALIZE exc = new INITIALIZE( "Cannot instantiate " + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
            INITIALIZE exc = new INITIALIZE( "Error while instantiating" + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    private static Class loadDelegateClass( String className )  throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            return Class.forName(className, false, loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            // ignore, then try RMIClassLoader
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
            return RMIClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        } catch (MalformedURLException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            String msg = "Could not load " + className + ": " + e.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
            ClassNotFoundException exc = new ClassNotFoundException( msg ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
     * Load the orb.properties file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
    private static Properties getORBPropertiesFile () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        return (Properties) AccessController.doPrivileged(new GetORBPropertiesFileAction());
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
class GetORBPropertiesFileAction implements PrivilegedAction {
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    private boolean debug = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    public GetORBPropertiesFileAction () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    private String getSystemProperty(final String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        // This will not throw a SecurityException because this
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        // class was loaded from rt.jar using the bootstrap classloader.
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        String propValue = (String) AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
                public java.lang.Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                    return System.getProperty(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        );
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        return propValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
    private void getPropertiesFromFile( Properties props, String fileName )
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            File file = new File( fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
            if (!file.exists())
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
                return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
            FileInputStream in = new FileInputStream( file ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                props.load( in ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
                in.close() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
                System.out.println( "ORB properties file " + fileName +
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                    " not found: " + exc) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    public Object run()
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        Properties defaults = new Properties() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        String javaHome = getSystemProperty( "java.home" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        String fileName = javaHome + File.separator + "lib" + File.separator +
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            "orb.properties" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        getPropertiesFromFile( defaults, fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        Properties results = new Properties( defaults ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
        String userHome = getSystemProperty( "user.home" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
        fileName = userHome + File.separator + "orb.properties" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        getPropertiesFromFile( results, fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        return results ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
}