corba/src/share/classes/javax/rmi/PortableRemoteObject.java
author andrew
Sat, 16 Jan 2010 01:04:04 +0000
changeset 4623 e3aaa29eff65
parent 4 02bb8761fcce
child 5555 b2b5ed3f0d0d
permissions -rw-r--r--
6917485: Corba doc warnings Summary: Fix warnings generated by javadoc Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
02bb8761fcce Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
02bb8761fcce Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
02bb8761fcce Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
02bb8761fcce Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
public class PortableRemoteObject {
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    private static javax.rmi.CORBA.PortableRemoteObjectDelegate proDelegate = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    private static final String PortableRemoteObjectClassKey =
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
            "javax.rmi.CORBA.PortableRemoteObjectClass";
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    private static final String defaultPortableRemoteObjectImplName =
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
            "com.sun.corba.se.impl.javax.rmi.PortableRemoteObject";
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        proDelegate = (javax.rmi.CORBA.PortableRemoteObjectDelegate)
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
            createDelegateIfSpecified(PortableRemoteObjectClassKey);
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
     * Initializes the object by calling <code>exportObject(this)</code>.
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
     * @exception RemoteException if export fails.
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    protected PortableRemoteObject() throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
            PortableRemoteObject.exportObject((Remote)this);
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
     * Makes a server object ready to receive remote calls. Note
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
     * that subclasses of PortableRemoteObject do not need to call this
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
     * method, as it is called by the constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
     * @param obj the server object to export.
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
     * @exception RemoteException if export fails.
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    public static void exportObject(Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        // Let the delegate do everything, including error handling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            proDelegate.exportObject(obj);
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * Returns a stub for the given server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     * @param obj the server object for which a stub is required. Must either be a subclass
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     * of PortableRemoteObject or have been previously the target of a call to
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     * {@link #exportObject}.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     * @return the most derived stub for the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
     * @exception NoSuchObjectException if a stub cannot be located for the given server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    public static Remote toStub (Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        throws NoSuchObjectException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            return proDelegate.toStub(obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
     * Deregisters a server object from the runtime, allowing the object to become
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
     * available for garbage collection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
     * @param obj the object to unexport.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
     * @exception NoSuchObjectException if the remote object is not
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
     * currently exported.
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    public static void unexportObject(Remote obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        throws NoSuchObjectException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
            proDelegate.unexportObject(obj);
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
     * Checks to ensure that an object of a remote or abstract interface type
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
     * can be cast to a desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
     * @param narrowFrom the object to check.
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
     * @param narrowTo the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
     * @return an object which can be cast to the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
     * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    public static java.lang.Object narrow ( java.lang.Object narrowFrom,
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                                            java.lang.Class narrowTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        throws ClassCastException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
            return proDelegate.narrow(narrowFrom, narrowTo);
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        return null;
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * Makes a Remote object ready for remote communication. This normally
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * happens implicitly when the object is sent or received as an argument
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * on a remote method call, but in some circumstances it is useful to
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     * perform this action by making an explicit call.  See the
4623
e3aaa29eff65 6917485: Corba doc warnings
andrew
parents: 4
diff changeset
   164
     * {@link javax.rmi.CORBA.Stub#connect} method for more information.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * @param target the object to connect.
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * @param source a previously connected object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     * @throws RemoteException if <code>source</code> is not connected
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     * or if <code>target</code> is already connected to a different ORB than
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     * <code>source</code>.
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    public static void connect (Remote target, Remote source)
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        throws RemoteException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        if (proDelegate != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            proDelegate.connect(target, source);
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
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    // Same code as in javax.rmi.CORBA.Util. Can not be shared because they
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    // are in different packages and the visibility needs to be package for
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    // security reasons. If you know a better solution how to share this code
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    // then remove it from here.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    private static Object createDelegateIfSpecified(String classKey) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        String className = (String)
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
            AccessController.doPrivileged(new GetPropertyAction(classKey));
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        if (className == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            Properties props = getORBPropertiesFile();
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            if (props != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                className = props.getProperty(classKey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        if (className == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                className = defaultPortableRemoteObjectImplName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
            return (Object) loadDelegateClass(className).newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        } catch (ClassNotFoundException ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
            INITIALIZE exc = new INITIALIZE( "Cannot instantiate " + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
            throw exc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            INITIALIZE exc = new INITIALIZE( "Error while instantiating" + className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
            exc.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
            throw exc ;
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
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    private static Class loadDelegateClass( String className )  throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
            return Class.forName(className, false, loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
            // ignore, then try RMIClassLoader
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
            return RMIClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        } catch (MalformedURLException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
            String msg = "Could not load " + className + ": " + e.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            ClassNotFoundException exc = new ClassNotFoundException( msg ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
            throw exc ;
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
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
     * Load the orb.properties file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    private static Properties getORBPropertiesFile () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        return (Properties) AccessController.doPrivileged(new GetORBPropertiesFileAction());
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
class GetORBPropertiesFileAction implements PrivilegedAction {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    private boolean debug = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    public GetORBPropertiesFileAction () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    private String getSystemProperty(final String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
        // This will not throw a SecurityException because this
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        // class was loaded from rt.jar using the bootstrap classloader.
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
        String propValue = (String) AccessController.doPrivileged(
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
            new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
                public java.lang.Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                    return System.getProperty(name);
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
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        return propValue;
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    private void getPropertiesFromFile( Properties props, String fileName )
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
            File file = new File( fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            if (!file.exists())
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
                return ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
            FileInputStream in = new FileInputStream( file ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                props.load( in ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
                in.close() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
            if (debug)
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                System.out.println( "ORB properties file " + fileName +
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
                    " not found: " + exc) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    public Object run()
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        Properties defaults = new Properties() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
        String javaHome = getSystemProperty( "java.home" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        String fileName = javaHome + File.separator + "lib" + File.separator +
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
            "orb.properties" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        getPropertiesFromFile( defaults, fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
        Properties results = new Properties( defaults ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
        String userHome = getSystemProperty( "user.home" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
        fileName = userHome + File.separator + "orb.properties" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        getPropertiesFromFile( results, fileName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        return results ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
}