corba/src/java.corba/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/Util.java
author chegar
Tue, 19 Apr 2016 14:34:43 +0100
changeset 37620 230612715768
parent 33680 56aa0b79bf5a
permissions -rw-r--r--
8148863: Remove sun.misc.ManagedLocalsThread from corba Reviewed-by: alanb, coffeys, msheppar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
29937
c774371adf92 8048997: Enhance thread contexts in CORBA
msheppar
parents: 25862
diff changeset
     2
 * Copyright (c) 1999, 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 com.sun.corba.se.impl.javax.rmi.CORBA; // Util (sed marker, don't remove!)
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
import java.rmi.UnexpectedException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.rmi.MarshalException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.rmi.server.RMIClassLoader;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.util.Map;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.WeakHashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.io.Serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.io.NotSerializableException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.lang.reflect.Constructor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import javax.rmi.CORBA.ValueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import javax.rmi.CORBA.Tie;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import java.rmi.MarshalException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import java.rmi.NoSuchObjectException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import java.rmi.AccessException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import java.rmi.ServerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import java.rmi.ServerException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import java.rmi.ServerRuntimeException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import javax.transaction.TransactionRequiredException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import javax.transaction.TransactionRolledbackException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import javax.transaction.InvalidTransactionException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import org.omg.CORBA.COMM_FAILURE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import org.omg.CORBA.BAD_PARAM;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import org.omg.CORBA.INV_OBJREF;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import org.omg.CORBA.NO_PERMISSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import org.omg.CORBA.MARSHAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import org.omg.CORBA.OBJECT_NOT_EXIST;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import org.omg.CORBA.TRANSACTION_REQUIRED;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import org.omg.CORBA.TRANSACTION_ROLLEDBACK;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import org.omg.CORBA.INVALID_TRANSACTION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import org.omg.CORBA.BAD_OPERATION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import org.omg.CORBA.ACTIVITY_REQUIRED;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import org.omg.CORBA.ACTIVITY_COMPLETED;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import org.omg.CORBA.INVALID_ACTIVITY;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import org.omg.CORBA.TCKind;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import org.omg.CORBA.portable.UnknownException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
import org.omg.CORBA.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
import org.omg.CORBA.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
// This class must be able to function with non-Sun ORBs.
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
// This means that any of the following com.sun.corba classes
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
// must only occur in contexts that also handle the non-Sun case.
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
import com.sun.corba.se.pept.transport.ContactInfoList ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
import com.sun.corba.se.spi.orb.ORBVersionFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
import com.sun.corba.se.spi.protocol.CorbaClientDelegate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
import com.sun.corba.se.spi.copyobject.ReflectiveCopyException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
import com.sun.corba.se.spi.copyobject.CopierManager ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
import com.sun.corba.se.spi.copyobject.ObjectCopierFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
import com.sun.corba.se.spi.copyobject.ObjectCopier ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
import com.sun.corba.se.impl.io.ValueHandlerImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
import com.sun.corba.se.impl.logging.OMGSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
import com.sun.corba.se.impl.util.IdentityHashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
import com.sun.corba.se.impl.util.JDKBridge;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
import com.sun.corba.se.impl.logging.UtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
import com.sun.corba.se.spi.logging.CORBALogDomains;
16136
f5a39cbcd82f 8000631: Restrict access to class constructor
coffeys
parents: 13052
diff changeset
   114
import sun.corba.SharedSecrets;
29937
c774371adf92 8048997: Enhance thread contexts in CORBA
msheppar
parents: 25862
diff changeset
   115
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
 * Provides utility methods that can be used by stubs and ties to
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
 * perform common operations.
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
public class Util implements javax.rmi.CORBA.UtilDelegate
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    // Runs as long as there are exportedServants
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    private static KeepAlive keepAlive = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    // Maps targets to ties.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    private static IdentityHashtable exportedServants = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
16136
f5a39cbcd82f 8000631: Restrict access to class constructor
coffeys
parents: 13052
diff changeset
   129
    private static final ValueHandlerImpl valueHandlerSingleton =
f5a39cbcd82f 8000631: Restrict access to class constructor
coffeys
parents: 13052
diff changeset
   130
        SharedSecrets.getJavaCorbaAccess().newValueHandlerImpl();
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    private UtilSystemException utilWrapper = UtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
                                                  CORBALogDomains.RPC_ENCODING);
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
13052
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   135
    private static Util instance = null;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    public Util() {
13052
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   138
        setInstance(this);
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   139
    }
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   140
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   141
    private static void setInstance( Util util ) {
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   142
        assert instance == null : "Instance already defined";
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   143
        instance = util;
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   144
    }
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   145
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   146
    public static Util getInstance() {
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   147
        return instance;
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   148
    }
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   149
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   150
    public static boolean isInstanceDefined() {
63c6c4c360e1 7079902: Refine CORBA data models
mbankal
parents: 5555
diff changeset
   151
        return instance != null;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    // Used by TOAFactory.shutdown to unexport all targets for this
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    // particular ORB.  This happens during ORB shutdown.
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    public void unregisterTargetsForORB(org.omg.CORBA.ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        for (Enumeration e = exportedServants.keys(); e.hasMoreElements(); )
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
            java.lang.Object key = e.nextElement();
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
            Remote target = (Remote)(key instanceof Tie ? ((Tie)key).getTarget() : key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
            // Bug 4476347: BAD_OPERATION is thrown if the ties delegate isn't set.
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
            // We can ignore this because it means the tie is not connected to an ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                if (orb == getTie(target).orb()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                        unexportObject(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
                    } catch( java.rmi.NoSuchObjectException ex ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
                        // We neglect this exception if at all if it is
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                        // raised. It is not harmful.
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            } catch (BAD_OPERATION bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
                /* Ignore */
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
   /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
     * Maps a SystemException to a RemoteException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
     * @param ex the SystemException to map.
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     * @return the mapped exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    public RemoteException mapSystemException(SystemException ex)
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        if (ex instanceof UnknownException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            Throwable orig = ((UnknownException)ex).originalEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            if (orig instanceof Error) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                return new ServerError("Error occurred in server thread",(Error)orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
            } else if (orig instanceof RemoteException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                return new ServerException("RemoteException occurred in server thread",
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                    (Exception)orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            } else if (orig instanceof RuntimeException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                throw (RuntimeException) orig;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        // Build the message string...
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
        String name = ex.getClass().getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
        String corbaName = name.substring(name.lastIndexOf('.')+1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
        String status;
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        switch (ex.completed.value()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            case CompletionStatus._COMPLETED_YES:
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                status = "Yes";
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
            case CompletionStatus._COMPLETED_NO:
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                status = "No";
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
            case CompletionStatus._COMPLETED_MAYBE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
            default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                status = "Maybe";
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
        String message = "CORBA " + corbaName + " " + ex.minor + " " + status;
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
        // Now map to the correct RemoteException type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        if (ex instanceof COMM_FAILURE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
            return new MarshalException(message, ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        } else if (ex instanceof INV_OBJREF) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            RemoteException newEx = new NoSuchObjectException(message);
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
            newEx.detail = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            return newEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        } else if (ex instanceof NO_PERMISSION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
            return new AccessException(message, ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        } else if (ex instanceof MARSHAL) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
            return new MarshalException(message, ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        } else if (ex instanceof OBJECT_NOT_EXIST) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
            RemoteException newEx = new NoSuchObjectException(message);
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
            newEx.detail = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            return newEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        } else if (ex instanceof TRANSACTION_REQUIRED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
            RemoteException newEx = new TransactionRequiredException(message);
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
            newEx.detail = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
            return newEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        } else if (ex instanceof TRANSACTION_ROLLEDBACK) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
            RemoteException newEx = new TransactionRolledbackException(message);
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
            newEx.detail = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
            return newEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
        } else if (ex instanceof INVALID_TRANSACTION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
            RemoteException newEx = new InvalidTransactionException(message);
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            newEx.detail = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            return newEx;
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
        } else if (ex instanceof BAD_PARAM) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
            Exception inner = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
            // Pre-Merlin Sun ORBs used the incorrect minor code for
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            // this case.  See Java to IDL ptc-00-01-08 1.4.8.
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
            if (ex.minor == ORBConstants.LEGACY_SUN_NOT_SERIALIZABLE ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
                ex.minor == OMGSystemException.NOT_SERIALIZABLE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
                if (ex.getMessage() != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
                    inner = new NotSerializableException(ex.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
                    inner = new NotSerializableException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
                inner.initCause( ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            return new MarshalException(message,inner);
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        } else if (ex instanceof ACTIVITY_REQUIRED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
            try {
18304
56149cf29cf9 8001032: Restrict object access
coffeys
parents: 16136
diff changeset
   264
                Class<?> cl = SharedSecrets.getJavaCorbaAccess().loadClass(
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
                               "javax.activity.ActivityRequiredException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                Class[] params = new Class[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                params[0] = java.lang.String.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
                params[1] = java.lang.Throwable.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
                Constructor cr = cl.getConstructor(params);
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
                Object[] args = new Object[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
                args[0] = message;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
                args[1] = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
                return (RemoteException) cr.newInstance(args);
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
                utilWrapper.classNotFound(
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
                              e, "javax.activity.ActivityRequiredException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        } else if (ex instanceof ACTIVITY_COMPLETED) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
            try {
18304
56149cf29cf9 8001032: Restrict object access
coffeys
parents: 16136
diff changeset
   280
                Class<?> cl = SharedSecrets.getJavaCorbaAccess().loadClass(
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
                               "javax.activity.ActivityCompletedException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                Class[] params = new Class[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
                params[0] = java.lang.String.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
                params[1] = java.lang.Throwable.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
                Constructor cr = cl.getConstructor(params);
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
                Object[] args = new Object[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
                args[0] = message;
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
                args[1] = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                return (RemoteException) cr.newInstance(args);
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
              } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
                  utilWrapper.classNotFound(
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
                                e, "javax.activity.ActivityCompletedException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
              }
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        } else if (ex instanceof INVALID_ACTIVITY) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
            try {
18304
56149cf29cf9 8001032: Restrict object access
coffeys
parents: 16136
diff changeset
   296
                Class<?> cl = SharedSecrets.getJavaCorbaAccess().loadClass(
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
                               "javax.activity.InvalidActivityException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                Class[] params = new Class[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
                params[0] = java.lang.String.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
                params[1] = java.lang.Throwable.class;
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
                Constructor cr = cl.getConstructor(params);
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
                Object[] args = new Object[2];
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
                args[0] = message;
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
                args[1] = ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
                return (RemoteException) cr.newInstance(args);
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
              } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
                  utilWrapper.classNotFound(
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
                                e, "javax.activity.InvalidActivityException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
              }
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        // Just map to a generic RemoteException...
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        return new RemoteException(message, ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
     * Writes any java.lang.Object as a CORBA any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
     * @param out the stream in which to write the any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
     * @param obj the object to write as an any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    public void writeAny( org.omg.CORBA.portable.OutputStream out,
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
                         java.lang.Object obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
        org.omg.CORBA.ORB orb = out.orb();
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
        // Create Any
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        Any any = orb.create_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        // Make sure we have a connected object...
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        java.lang.Object newObj = Utility.autoConnect(obj,orb,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        if (newObj instanceof org.omg.CORBA.Object) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            any.insert_Object((org.omg.CORBA.Object)newObj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            if (newObj == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
                // Handle the null case, including backwards
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
                // compatibility issues
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
                any.insert_Value(null, createTypeCodeForNull(orb));
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
                if (newObj instanceof Serializable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
                    // If they're our Any and ORB implementations,
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
                    // we may want to do type code related versioning.
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                    TypeCode tc = createTypeCode((Serializable)newObj, any, orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                    if (tc == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                        any.insert_Value((Serializable)newObj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                    else
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
                        any.insert_Value((Serializable)newObj, tc);
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                } else if (newObj instanceof Remote) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
                    ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
                    ORBUtility.throwNotSerializableForCorba(newObj.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
        out.write_any(any);
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
     * When using our own ORB and Any implementations, we need to get
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
     * the ORB version and create the type code appropriately.  This is
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
     * to overcome a bug in which the JDK 1.3.x ORBs used a tk_char
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
     * rather than a tk_wchar to describe a Java char field.
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
     * This only works in RMI-IIOP with Util.writeAny since we actually
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
     * know what ORB and stream we're writing with when we insert
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
     * the value.
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
     * Returns null if it wasn't possible to create the TypeCode (means
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
     * it wasn't our ORB or Any implementation).
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
     * This does not handle null objs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
    private TypeCode createTypeCode(Serializable obj,
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
                                    org.omg.CORBA.Any any,
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
                                    org.omg.CORBA.ORB orb) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        if (any instanceof com.sun.corba.se.impl.corba.AnyImpl &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
            orb instanceof ORB) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
            com.sun.corba.se.impl.corba.AnyImpl anyImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
                = (com.sun.corba.se.impl.corba.AnyImpl)any;
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
            ORB ourORB = (ORB)orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
            return anyImpl.createTypeCodeForClass(obj.getClass(), ourORB);
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
     * This is used to create the TypeCode for a null reference.
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
     * It also handles backwards compatibility with JDK 1.3.x.
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
     * This method will not return null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
    private TypeCode createTypeCodeForNull(org.omg.CORBA.ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
        if (orb instanceof ORB) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
            ORB ourORB = (ORB)orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
            // Preserve backwards compatibility with Kestrel and Ladybird
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
            // by not fully implementing interop issue resolution 3857,
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            // and returning a null TypeCode with a tk_value TCKind.
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
            // If we're not talking to Kestrel or Ladybird, fall through
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
            // to the abstract interface case (also used for foreign ORBs).
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
            if (!ORBVersionFactory.getFOREIGN().equals(ourORB.getORBVersion()) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
                ORBVersionFactory.getNEWER().compareTo(ourORB.getORBVersion()) > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
                return orb.get_primitive_tc(TCKind.tk_value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        // Use tk_abstract_interface as detailed in the resolution
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
        // REVISIT: Define this in IDL and get the ID in generated code
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        String abstractBaseID = "IDL:omg.org/CORBA/AbstractBase:1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        return orb.create_abstract_interface_tc(abstractBaseID, "");
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
     * Reads a java.lang.Object as a CORBA any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
     * @param in the stream from which to read the any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
     * @return the object read from the stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
    public Object readAny(InputStream in)
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
        Any any = in.read_any();
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
        if ( any.type().kind().value() == TCKind._tk_objref )
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
            return any.extract_Object ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            return any.extract_Value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
    /**
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   440
     * Writes a java.lang.Object as a CORBA Object. If {@code obj} is
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
     * 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: 30384
diff changeset
   442
     * and wired to {@code obj}, then written to {@code out.write_Object(org.omg.CORBA.Object)}.
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   443
     * 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: 30384
diff changeset
   444
     * {@code out.write_Object(org.omg.CORBA.Object)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
     * @param out the stream in which to write the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
     * @param obj the object to write.
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
    public void writeRemoteObject(OutputStream out, java.lang.Object obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        // Make sure we have a connected object, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
        // write it out...
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
        Object newObj = Utility.autoConnect(obj,out.orb(),false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        out.write_Object((org.omg.CORBA.Object)newObj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
     * 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: 30384
diff changeset
   459
     * 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: 30384
diff changeset
   460
     * {@code out.write_abstract_interface(java.lang.Object)}. If {@code obj} is an exported
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   461
     * 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: 30384
diff changeset
   462
     * then written to {@code out.write_abstract_interface(java.lang.Object)}.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
     * @param out the stream in which to write the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
     * @param obj the object to write.
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    public void writeAbstractObject( OutputStream out, java.lang.Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
        // Make sure we have a connected object, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
        // write it out...
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        Object newObj = Utility.autoConnect(obj,out.orb(),false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
        ((org.omg.CORBA_2_3.portable.OutputStream)out).write_abstract_interface(newObj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
     * Registers a target for a tie. Adds the tie to an internal table and calls
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
     * {@link Tie#setTarget} on the tie object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
     * @param tie the tie to register.
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
     * @param target the target for the tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    public void registerTarget(javax.rmi.CORBA.Tie tie, java.rmi.Remote target)
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
        synchronized (exportedServants) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
            // Do we already have this target registered?
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
            if (lookupTie(target) == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
                // No, so register it and set the target...
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
                exportedServants.put(target,tie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
                tie.setTarget(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
                // Do we need to instantiate our keep-alive thread?
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
                if (keepAlive == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                    // Yes. Instantiate our keep-alive thread and start
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
                    // it up...
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
                    keepAlive = (KeepAlive)AccessController.doPrivileged(new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
                        public java.lang.Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
                            return new KeepAlive();
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
                    });
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
                    keepAlive.start();
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
     * Removes the associated tie from an internal table and calls {@link Tie#deactivate}
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
     * to deactivate the object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
     * @param target the object to unexport.
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    public void unexportObject(java.rmi.Remote target)
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        throws java.rmi.NoSuchObjectException
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        synchronized (exportedServants) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
            Tie cachedTie = lookupTie(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
            if (cachedTie != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                exportedServants.remove(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                Utility.purgeStubForTie(cachedTie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                Utility.purgeTieAndServant(cachedTie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                    cleanUpTie(cachedTie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                } catch (BAD_OPERATION e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                    // ignore
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                } catch (org.omg.CORBA.OBJ_ADAPTER e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
                    // This can happen when the target was never associated with a POA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                    // We can safely ignore this case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                // Is it time to shut down our keep alive thread?
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                if (exportedServants.isEmpty()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
                    keepAlive.quit();
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                    keepAlive = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
                throw new java.rmi.NoSuchObjectException("Tie not found" );
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
    protected void cleanUpTie(Tie cachedTie)
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
        throws java.rmi.NoSuchObjectException
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
        cachedTie.setTarget(null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
        cachedTie.deactivate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
     * Returns the tie (if any) for a given target object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
     * @return the tie or null if no tie is registered for the given target.
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    public Tie getTie (Remote target)
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
        synchronized (exportedServants) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
            return lookupTie(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
     * An unsynchronized version of getTie() for internal use.
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
    private static Tie lookupTie (Remote target)
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
        Tie result = (Tie)exportedServants.get(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        if (result == null && target instanceof Tie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
            if (exportedServants.contains(target)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
                result = (Tie)target;
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
     * Returns a singleton instance of a class that implements the
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
     * {@link ValueHandler} interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
     * @return a class which implements the ValueHandler interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    public ValueHandler createValueHandler()
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
        return valueHandlerSingleton;
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
     * Returns the codebase, if any, for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
     * @param clz the class to get a codebase for.
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
     * @return a space-separated list of URLs, or null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
    public String getCodebase(java.lang.Class clz) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
        return RMIClassLoader.getClassAnnotation(clz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
     * Returns a class instance for the specified class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
     * @param className the name of the class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
     * @param remoteCodebase a space-separated list of URLs at which
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
     * the class might be found. May be null.
30384
ff19c1d6f92a 8079342: some docs cleanup for CORBA - part 2
avstepan
parents: 29937
diff changeset
   595
     * @param loader a class whose ClassLoader may be used to
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
     * load the class if all other methods fail.
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   597
     * @return the {@code Class} object representing the loaded class.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
     * @exception ClassNotFoundException if class cannot be loaded.
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    public Class loadClass( String className, String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        ClassLoader loader) throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
        return JDKBridge.loadClass(className,remoteCodebase,loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
    /**
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   607
     * The {@code isLocal} method has the same semantics as the
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
     * ObjectImpl._is_local method, except that it can throw a RemoteException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
     * (no it doesn't but the spec says it should.)
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
     *
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   611
     * The {@code _is_local()} method is provided so that stubs may determine
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
     * if a particular object is implemented by a local servant and hence local
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
     * invocation APIs may be used.
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
     * @param stub the stub to test.
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
     *
32688
936c391804a5 8133650: replace some <tt> tags (obsolete in html5) in CORBA docs
avstepan
parents: 30384
diff changeset
   617
     * @return The {@code _is_local()} method returns true if
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
     * 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: 30384
diff changeset
   619
     * 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: 30384
diff changeset
   620
     * method returns false otherwise. The default behavior of {@code _is_local()} is
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
     * to return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
     * @throws RemoteException The Java to IDL specification does to
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
     * specify the conditions that cause a RemoteException to be thrown.
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    public boolean isLocal(javax.rmi.CORBA.Stub stub) throws RemoteException
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
        boolean result = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
            org.omg.CORBA.portable.Delegate delegate = stub._get_delegate() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
            if (delegate instanceof CorbaClientDelegate) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
                // For the Sun ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                CorbaClientDelegate cdel = (CorbaClientDelegate)delegate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
                ContactInfoList cil = cdel.getContactInfoList() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                if (cil instanceof CorbaContactInfoList) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
                    CorbaContactInfoList ccil = (CorbaContactInfoList)cil ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                    LocalClientRequestDispatcher lcs = ccil.getLocalClientRequestDispatcher() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                    result = lcs.useLocalInvocation( null ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                // For a non-Sun ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
                result = delegate.is_local( stub ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
        } catch (SystemException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
            throw javax.rmi.CORBA.Util.mapSystemException(e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
     * Wraps an exception thrown by an implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
     * method.  It returns the corresponding client-side exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
     * @param orig the exception to wrap.
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
     * @return the wrapped exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    public RemoteException wrapException(Throwable orig)
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
        if (orig instanceof SystemException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
            return mapSystemException((SystemException)orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
        if (orig instanceof Error) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
            return new ServerError("Error occurred in server thread",(Error)orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        } else if (orig instanceof RemoteException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
            return new ServerException("RemoteException occurred in server thread",
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
                                       (Exception)orig);
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        } else if (orig instanceof RuntimeException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
            throw (RuntimeException) orig;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
        if (orig instanceof Exception)
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
            return new UnexpectedException( orig.toString(), (Exception)orig );
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
            return new UnexpectedException( orig.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
     * Copies or connects an array of objects. Used by local stubs
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
     * to copy any number of actual parameters, preserving sharing
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
     * across parameters as necessary to support RMI semantics.
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
     * @param obj the objects to copy or connect.
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
     * @param orb the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
     * @return the copied or connected objects.
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
     * @exception RemoteException if any object could not be copied or connected.
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
    public Object[] copyObjects (Object[] obj, org.omg.CORBA.ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
        throws RemoteException
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
        if (obj == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
            // Bug fix for 5018613: JCK test expects copyObjects to throw
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
            // NPE when obj==null.  This is actually not in the spec, since
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
            // obj is not really an RMI-IDL data type, but we follow our
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
            // test here, and force this error to be thrown.
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
            throw new NullPointerException() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
        Class compType = obj.getClass().getComponentType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
        if (Remote.class.isAssignableFrom( compType ) && !compType.isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
            // obj is an array of remote impl types.  This
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
            // causes problems with stream copier, so we copy
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
            // it over to an array of Remotes instead.
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
            Remote[] result = new Remote[obj.length] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
            System.arraycopy( (Object)obj, 0, (Object)result, 0, obj.length ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
            return (Object[])copyObject( result, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            return (Object[])copyObject( obj, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
     * Copies or connects an object. Used by local stubs to copy
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
     * an actual parameter, result object, or exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
     * @param obj the object to copy.
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
     * @param orb the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
     * @return the copy or connected object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
     * @exception RemoteException if the object could not be copied or connected.
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    public Object copyObject (Object obj, org.omg.CORBA.ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
        throws RemoteException
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
        if (orb instanceof ORB) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
            ORB lorb = (ORB)orb ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
                    // This gets the copier for the current invocation, which was
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
                    // previously set by preinvoke.
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
                    return lorb.peekInvocationInfo().getCopierFactory().make().copy( obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
                } catch (java.util.EmptyStackException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
                    // copyObject was invoked outside of an invocation, probably by
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
                    // a test.  Get the default copier from the ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
                    // XXX should we just make the default copier available directly
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
                    // and avoid constructing one on each call?
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
                    CopierManager cm = lorb.getCopierManager() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
                    ObjectCopier copier = cm.getDefaultObjectCopierFactory().make() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
                    return copier.copy( obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
            } catch (ReflectiveCopyException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
                RemoteException rexc = new RemoteException() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
                rexc.initCause( exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
                throw rexc ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
            org.omg.CORBA_2_3.portable.OutputStream out =
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
                (org.omg.CORBA_2_3.portable.OutputStream)orb.create_output_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
            out.write_value((Serializable)obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
            org.omg.CORBA_2_3.portable.InputStream in =
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
                (org.omg.CORBA_2_3.portable.InputStream)out.create_input_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
            return in.read_value();
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
37620
230612715768 8148863: Remove sun.misc.ManagedLocalsThread from corba
chegar
parents: 33680
diff changeset
   754
class KeepAlive extends Thread
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
{
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
    boolean quit = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
    public KeepAlive ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
    {
37620
230612715768 8148863: Remove sun.misc.ManagedLocalsThread from corba
chegar
parents: 33680
diff changeset
   760
        super(null, null, "Servant-KeepAlive-Thread", 0, false);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        setDaemon(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
    public synchronized void run ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
        while (!quit) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
                wait();
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
            } catch (InterruptedException e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
    public synchronized void quit ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
        quit = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
        notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
}