corba/src/share/classes/com/sun/corba/se/impl/util/Utility.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1999, 2004, 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
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
package com.sun.corba.se.impl.util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.BAD_OPERATION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import org.omg.CORBA.BAD_INV_ORDER;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.CORBA.BAD_PARAM;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.CORBA.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.Any;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.TypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import org.omg.CORBA.Principal;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import org.omg.CORBA.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.CORBA.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import org.omg.CORBA.portable.BoxedValueHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.CORBA.portable.ValueFactory;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import org.omg.CORBA.portable.Streamable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import org.omg.CORBA.portable.Delegate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import java.util.NoSuchElementException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import java.rmi.Remote;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import java.rmi.NoSuchObjectException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import java.rmi.RemoteException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import java.rmi.server.RemoteStub;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import javax.rmi.PortableRemoteObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import javax.rmi.CORBA.Stub;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import javax.rmi.CORBA.Tie;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import java.io.Serializable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import java.io.FileInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.PortableServer.POA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import com.sun.org.omg.SendingContext.CodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.impl.logging.UtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.impl.logging.OMGSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
 *  Handy class full of static functions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
public final class Utility {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    public static final String STUB_PREFIX = "_";
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    public static final String RMI_STUB_SUFFIX = "_Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    public static final String DYNAMIC_STUB_SUFFIX = "_DynamicStub" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    public static final String IDL_STUB_SUFFIX = "Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    public static final String TIE_SUFIX = "_Tie";
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    private static IdentityHashtable tieCache = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    private static IdentityHashtable tieToStubCache = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    private static IdentityHashtable stubToTieCache = new IdentityHashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    private static Object CACHE_MISS = new Object();
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    private static UtilSystemException wrapper = UtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        CORBALogDomains.UTIL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    private static OMGSystemException omgWrapper = OMGSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        CORBALogDomains.UTIL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
     * Ensure that stubs, ties, and implementation objects
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
     * are 'connected' to the runtime. Converts implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
     * objects to a type suitable for sending on the wire.
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
     * @param obj the object to connect.
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
     * @param orb the ORB to connect to if obj is exported to IIOP.
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
     * @param convertToStub true if implementation types should be
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
     * converted to Stubs rather than just org.omg.CORBA.Object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
     * @return the connected object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     * @exception NoSuchObjectException if obj is an implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
     * which has not been exported.
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    public static Object autoConnect(Object obj, ORB orb, boolean convertToStub)
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        if (obj == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
            return obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        if (StubAdapter.isStub(obj)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
                StubAdapter.getDelegate(obj) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            } catch (BAD_OPERATION okay) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
                    StubAdapter.connect( obj, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
                } catch (RemoteException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
                    // The stub could not be connected because it
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
                    // has an invalid IOR...
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
                    throw wrapper.objectNotConnected( e,
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                        obj.getClass().getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            return obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        if (obj instanceof Remote) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
            Remote remoteObj = (Remote)obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            Tie theTie = Util.getTie(remoteObj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            if (theTie != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
                    theTie.orb();
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
                } catch (SystemException okay) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
                    theTie.orb(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
                if (convertToStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
                    Object result = loadStub(theTie,null,null,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
                    if (result != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
                        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                        throw wrapper.couldNotLoadStub(obj.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
                    return StubAdapter.activateTie( theTie );
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
                // This is an implementation object which has not been
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
                // exported to IIOP OR is a JRMP stub or implementation
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
                // object which cannot be marshalled into an ORB stream...
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
                throw wrapper.objectNotExported( obj.getClass().getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        // Didn't need to do anything, just return the input...
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        return obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
     * Get a new instance of an RMI-IIOP Tie for the
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     * given server object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    public static Tie loadTie(Remote obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        Tie result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        Class objClass = obj.getClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        // Have we tried to find this guy before?
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        synchronized (tieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
            Object it = tieCache.get(obj);
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
            if (it == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                // No, so try it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                    // First try the classname...
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                    result = loadTie(objClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                    // If we don't have a valid tie at this point,
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                    // walk up the parent chain until we either
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                    // load a tie or encounter PortableRemoteObject
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                    // or java.lang.Object...
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                    while (result == null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
                           (objClass = objClass.getSuperclass()) != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                           objClass != PortableRemoteObject.class &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
                           objClass != Object.class) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
                        result = loadTie(objClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
                    wrapper.loadTieFailed( ex, objClass.getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                // Did we get it?
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                    // Nope, so cache that fact...
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                    tieCache.put(obj,CACHE_MISS);
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
                    // Yes, so cache it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
                    tieCache.put(obj,result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
                // Yes, return a new instance or fail again if
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
                // it was a miss last time...
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
                if (it != CACHE_MISS) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
                        result = (Tie) it.getClass().newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
                    } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
     * Load an RMI-IIOP Tie
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    private static Tie loadTie(Class theClass)
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        return com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory().
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            getTie( theClass ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
     * Clear the stub/tie caches. Intended for use by
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
     * test code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    public static void clearCaches() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
        synchronized (tieToStubCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
            tieToStubCache.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
        synchronized (tieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
            tieCache.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        synchronized (stubToTieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
            stubToTieCache.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
     * Load a class and check that it is assignable to a given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
     * @param className the class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
     * @param remoteCodebase the codebase to use. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
     * @param loader the class loader of last resort. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
     * @param expectedType the expected type. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
     * @return the loaded class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    static Class loadClassOfType(String className, String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
        ClassLoader loader, Class expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        ClassLoader expectedTypeClassLoader) throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        Class loadedClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
            //Sequence finding of the stubs according to spec
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
            try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
                //If-else is put here for speed up of J2EE.
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
                //According to the OMG spec, the if clause is not dead code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                //It can occur if some compiler has allowed generation
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
                //into org.omg.stub hierarchy for non-offending
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
                //classes. This will encourage people to
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
                //produce non-offending class stubs in their own hierarchy.
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
                if (!PackagePrefixChecker.hasOffendingPrefix(
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
                    PackagePrefixChecker.withoutPackagePrefix(className))){
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
                    loadedClass = Util.loadClass(
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                        PackagePrefixChecker.withoutPackagePrefix(className),
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                        remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
                        loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
                    loadedClass = Util.loadClass(className, remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
                        loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
            } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
                loadedClass = Util.loadClass(className, remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                    loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            if (expectedType == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
                return loadedClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
            if (expectedType == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
                throw cnfe;
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
        // If no class was loaded, or if the loaded class is not of the
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
        // correct type, make a further attempt to load the correct class
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
        // using the classloader of the expected type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
        // _REVISIT_ Is this step necessary, or should the Util,loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        // algorithm always produce a valid class if the setup is correct?
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
        // Does the OMG standard algorithm need to be changed to include
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        // this step?
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
        if (loadedClass == null || !expectedType.isAssignableFrom(loadedClass)){
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            if (expectedType.getClassLoader() != expectedTypeClassLoader)
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
                throw new IllegalArgumentException(
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
                    "expectedTypeClassLoader not class loader of "  +
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
                    "expected Type.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
            if (expectedTypeClassLoader != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
                loadedClass = expectedTypeClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
            else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
                if (cl == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
                    cl = ClassLoader.getSystemClassLoader();
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
                loadedClass = cl.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        return loadedClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
     * Load a class and check that it is compatible with a given type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
     * @param className the class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
     * @param remoteCodebase the codebase to use. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
     * @param loadingContext the loading context. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
     * @param relatedType the related type. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
     * @return the loaded class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
    public static Class loadClassForClass (String className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
                                           String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                                           ClassLoader loader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                                           Class relatedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
                                           ClassLoader relatedTypeClassLoader)
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        if (relatedType == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
            return Util.loadClass(className, remoteCodebase, loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        Class loadedClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            loadedClass = Util.loadClass(className, remoteCodebase, loader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            if (relatedType.getClassLoader() == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                throw cnfe;
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
        // If no class was not loaded, or if the loaded class is not of the
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
        // correct type, make a further attempt to load the correct class
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
        // using the classloader of the related type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        // _REVISIT_ Is this step necessary, or should the Util,loadClass
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
        // algorithm always produce a valid class if the setup is correct?
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        // Does the OMG standard algorithm need to be changed to include
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
        // this step?
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
        if (loadedClass == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
            (loadedClass.getClassLoader() != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
             loadedClass.getClassLoader().loadClass(relatedType.getName()) !=
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                 relatedType))
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
            if (relatedType.getClassLoader() != relatedTypeClassLoader)
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
                throw new IllegalArgumentException(
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                    "relatedTypeClassLoader not class loader of relatedType.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
            if (relatedTypeClassLoader != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
                loadedClass = relatedTypeClassLoader.loadClass(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
        return loadedClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
     * Get the helper for an IDLValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
     * Throws MARSHAL exception if no helper found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
    public static BoxedValueHelper getHelper(Class clazz, String codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        String repId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
        String className = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
        if (clazz != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
            className = clazz.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
            if (codebase == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
                codebase = Util.getCodebase(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
            if (repId != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
                className = RepositoryId.cache.getId(repId).getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
            if (className == null) // no repId or unrecognized repId
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                throw wrapper.unableLocateValueHelper(
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                    CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
            ClassLoader clazzLoader =
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
                (clazz == null ? null : clazz.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
            Class helperClass =
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
                loadClassForClass(className+"Helper", codebase, clazzLoader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                clazz, clazzLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
            return (BoxedValueHelper)helperClass.newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
            throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
                cnfe );
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        } catch (IllegalAccessException iae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
            throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
                iae );
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        } catch (InstantiationException ie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
            throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
                ie );
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
        } catch (ClassCastException cce) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
            throw wrapper.unableLocateValueHelper( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                cce );
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
     * Get the factory for an IDLValue
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
     * Throws MARSHAL exception if no factory found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
    public static ValueFactory getFactory(Class clazz, String codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                               ORB orb, String repId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        ValueFactory factory = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
        if ((orb != null) && (repId != null)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
                factory = ((org.omg.CORBA_2_3.ORB)orb).lookup_value_factory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                    repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
            } catch (org.omg.CORBA.BAD_PARAM ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                // Try other way
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        String className = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        if (clazz != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
            className = clazz.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
            if (codebase == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                codebase = Util.getCodebase(clazz);
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
            if (repId != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
                className = RepositoryId.cache.getId(repId).getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
            if (className == null) // no repId or unrecognized repId
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
                throw omgWrapper.unableLocateValueFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                    CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        // if earlier search found a non-default factory, or the same default
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        // factory that loadClassForClass would return, bale out now...
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
        if (factory != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
            (!factory.getClass().getName().equals(className+"DefaultFactory") ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
             (clazz == null && codebase == null)))
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
            return factory;
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
            ClassLoader clazzLoader =
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
                (clazz == null ? null : clazz.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            Class factoryClass =
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                loadClassForClass(className+"DefaultFactory", codebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                clazzLoader, clazz, clazzLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
            return (ValueFactory)factoryClass.newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        } catch (ClassNotFoundException cnfe) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            throw omgWrapper.unableLocateValueFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
                CompletionStatus.COMPLETED_MAYBE, cnfe);
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
        } catch (IllegalAccessException iae) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
            throw omgWrapper.unableLocateValueFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
                CompletionStatus.COMPLETED_MAYBE, iae);
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
        } catch (InstantiationException ie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
            throw omgWrapper.unableLocateValueFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
                CompletionStatus.COMPLETED_MAYBE, ie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        } catch (ClassCastException cce) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
            throw omgWrapper.unableLocateValueFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
                CompletionStatus.COMPLETED_MAYBE, cce);
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
     * Load an RMI-IIOP Stub given a Tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
     * @param tie the tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
     * @param stubClass the stub class. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
     * @param remoteCodebase the codebase to use. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
     * @param onlyMostDerived if true, will fail if cannot load a stub for the
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
     * first repID in the tie. If false, will walk all repIDs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
     * @return the stub or null if not found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
    public static Remote loadStub(Tie tie,
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
                                  PresentationManager.StubFactory stubFactory,
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                                  String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                                  boolean onlyMostDerived)
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        StubEntry entry = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        // Do we already have it cached?
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        synchronized (tieToStubCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
            Object cached = tieToStubCache.get(tie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
            if (cached == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
                // No, so go try to load it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
                entry = loadStubAndUpdateCache(
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                        tie, stubFactory, remoteCodebase, onlyMostDerived);
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
                // Yes, is it a stub?  If not, it was a miss last
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
                // time, so return null again...
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
                if (cached != CACHE_MISS) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
                    // It's a stub.
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
                    entry = (StubEntry) cached;
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
                    // Does the cached stub meet the requirements
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                    // of the caller? If the caller does not require
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
                    // the most derived stub and does not require
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                    // a specific stub type, we don't have to check
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
                    // any further because the cached type is good
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
                    // enough...
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                    if (!entry.mostDerived && onlyMostDerived) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
                        // We must reload because we do not have
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                        // the most derived cached already...
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                        // The stubFactory arg must be null here
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                        // to force onlyMostDerived=true to work
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
                        // correctly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
                        entry = loadStubAndUpdateCache(tie,null,
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
                            remoteCodebase,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
                    } else if (stubFactory != null &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
                        !StubAdapter.getTypeIds(entry.stub)[0].equals(
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
                            stubFactory.getTypeIds()[0]) )
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
                        // We do not have exactly the right stub. First, try to
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
                        // upgrade the cached stub by forcing it to the most
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
                        // derived stub...
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
                        entry = loadStubAndUpdateCache(tie,null,
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
                            remoteCodebase,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
                        // If that failed, try again with the exact type
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
                        // we need...
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
                        if (entry == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
                            entry = loadStubAndUpdateCache(tie,stubFactory,
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
                                    remoteCodebase,onlyMostDerived);
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
                    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
                        // Use the cached stub. Is the delegate set?
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
                        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                            Delegate stubDel = StubAdapter.getDelegate(
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
                                entry.stub ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                        } catch (Exception e2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
                            // No, so set it if we can...
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
                                Delegate del = StubAdapter.getDelegate(
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                                    tie ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                                StubAdapter.setDelegate( entry.stub,
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
                                    del ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                            } catch (Exception e) {}
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        if (entry != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
            return (Remote)entry.stub;
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
     * Load an RMI-IIOP Stub given a Tie, but do not look in the cache.
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
     * This method must be called with the lock held for tieToStubCache.
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
     * @param tie the tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
     * @param stubFactory the stub factory. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
     * @param remoteCodebase the codebase to use. May be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
     * @param onlyMostDerived if true, will fail if cannot load a stub for the
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
     * first repID in the tie. If false, will walk all repIDs.
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
     * @return the StubEntry or null if not found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
    private static StubEntry loadStubAndUpdateCache (
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
        Tie tie, PresentationManager.StubFactory  stubFactory,
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
        String remoteCodebase, boolean onlyMostDerived)
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
        org.omg.CORBA.Object stub = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
        StubEntry entry = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
        boolean tieIsStub = StubAdapter.isStub( tie ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
        if (stubFactory != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                stub = stubFactory.makeStub();
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
            } catch (Throwable e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
                wrapper.stubFactoryCouldNotMakeStub( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
                if (e instanceof ThreadDeath) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
                    throw (ThreadDeath) e;
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
            String[] ids = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
            if (tieIsStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
                ids = StubAdapter.getTypeIds( tie ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
                // This will throw an exception if the tie
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
                // is not a Servant.  XXX Handle this better?
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
                ids = ((org.omg.PortableServer.Servant)tie).
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
                      _all_interfaces( null, null );
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
            if (remoteCodebase == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
                remoteCodebase = Util.getCodebase(tie.getClass());
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
            if (ids.length == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
                stub = new org.omg.stub.java.rmi._Remote_Stub();
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
                // Now walk all the RepIDs till we find a stub or fail...
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
                for (int i = 0; i < ids.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
                    if (ids[i].length() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
                        stub = new org.omg.stub.java.rmi._Remote_Stub();
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
                        PresentationManager.StubFactoryFactory stubFactoryFactory =
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
                            com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory();
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
                        RepositoryId rid = RepositoryId.cache.getId( ids[i] ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
                        String className = rid.getClassName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
                        boolean isIDLInterface = rid.isIDLType() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
                        stubFactory = stubFactoryFactory.createStubFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
                            className, isIDLInterface, remoteCodebase, null,
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
                            tie.getClass().getClassLoader() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
                        stub = stubFactory.makeStub();
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
                    } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
                        wrapper.errorInMakeStubFromRepositoryId( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
                    if (onlyMostDerived)
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
        if (stub == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
            // Stub == null, so cache the miss...
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
            tieToStubCache.put(tie,CACHE_MISS);
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
            if (tieIsStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
                    Delegate del = StubAdapter.getDelegate( tie ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
                    StubAdapter.setDelegate( stub, del ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
                } catch( Exception e1 ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
                    // The tie does not have a delegate set, so stash
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
                    // this tie away using the stub as a key so that
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
                    // later, when the stub is connected, we can find
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
                    // and connect the tie as well...
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
                    synchronized (stubToTieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
                        stubToTieCache.put(stub,tie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
                // Tie extends Servant
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
                    Delegate delegate = StubAdapter.getDelegate( tie ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
                    StubAdapter.setDelegate( stub, delegate ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
                } catch( org.omg.CORBA.BAD_INV_ORDER bad) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
                    synchronized (stubToTieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
                        stubToTieCache.put(stub,tie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
                } catch( Exception e ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
                    // Exception is caught because of any of the
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
                    // following reasons
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
                    // 1) POA is not associated with the TIE
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
                    // 2) POA Policies for the tie-associated POA
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
                    //    does not support _this_object() call.
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
                    throw wrapper.noPoa( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
            // Update the cache...
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
            entry = new StubEntry(stub,onlyMostDerived);
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
            tieToStubCache.put(tie,entry);
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
        return entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
     * If we loadStub(Tie,...) stashed away a tie which was
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
     * not connected, remove it from the cache and return
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
     * it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
    public static Tie getAndForgetTie (org.omg.CORBA.Object stub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
        synchronized (stubToTieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
            return (Tie) stubToTieCache.remove(stub);
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
     * Remove any cached Stub for the given tie.
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
    public static void purgeStubForTie (Tie tie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
        StubEntry entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
        synchronized (tieToStubCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
            entry = (StubEntry)tieToStubCache.remove(tie);
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
        if (entry != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
            synchronized (stubToTieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
                stubToTieCache.remove(entry.stub);
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
     * Remove cached tie/servant pair.
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
    public static void purgeTieAndServant (Tie tie) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
        synchronized (tieCache) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
            Object target = tie.getTarget();
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
            if (target != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
                tieCache.remove(target);
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
     * Convert a RepId to a stubName...
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
    public static String stubNameFromRepID (String repID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
        // Convert the typeid to a RepositoryId instance, get
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
        // the className and mangle it as needed...
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        RepositoryId id = RepositoryId.cache.getId(repID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
        String className = id.getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        if (id.isIDLType()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
            className = idlStubName(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
            className = stubName(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
        return className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
     * Load an RMI-IIOP Stub.  This is used in PortableRemoteObject.narrow.
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
    public static Remote loadStub (org.omg.CORBA.Object narrowFrom,
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
                                   Class narrowTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
        Remote result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
            // Get the codebase from the delegate to use when loading
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
            // the new stub, if possible...
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
            String codebase = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
                // We can't assume that narrowFrom is a CORBA_2_3 stub, yet
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
                // it may have a 2_3 Delegate that provides a codebase.  Swallow
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
                // the ClassCastException otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
                Delegate delegate = StubAdapter.getDelegate( narrowFrom ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
                codebase = ((org.omg.CORBA_2_3.portable.Delegate)delegate).
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
                    get_codebase(narrowFrom);
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
            } catch (ClassCastException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
                wrapper.classCastExceptionInLoadStub( e ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
            PresentationManager.StubFactoryFactory sff =
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
                com.sun.corba.se.spi.orb.ORB.getStubFactoryFactory() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
            PresentationManager.StubFactory sf = sff.createStubFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
                narrowTo.getName(), false, codebase, narrowTo,
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
                narrowTo.getClassLoader() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
            result = (Remote)sf.makeStub() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
            StubAdapter.setDelegate( result,
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
                StubAdapter.getDelegate( narrowFrom ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
        } catch (Exception err) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
            wrapper.exceptionInLoadStub( err ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
     * Load an RMI-IIOP Stub class.  This is used in the
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
     * StaticStubFactoryFactory code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
    public static Class loadStubClass(String repID,
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
                                      String remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
                                      Class expectedType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        throws ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
        // Get the repID and check for "" special case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
        // We should never be called with it (See CDRInputStream
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
        // and the loadStub() method)...
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
        if (repID.length() == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
            throw new ClassNotFoundException();
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
        // Get the stubname from the repID and load
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
        // the class. If we have a valid 'sender', fall
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        // back to using its codebase if we need to...
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
        String className = Utility.stubNameFromRepID(repID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        ClassLoader expectedTypeClassLoader = (expectedType == null ? null :
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
            expectedType.getClassLoader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
              return loadClassOfType(className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
                                       remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
                                       expectedTypeClassLoader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
                                       expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
                                       expectedTypeClassLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
        } catch (ClassNotFoundException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
            return loadClassOfType(PackagePrefixChecker.packagePrefix() + className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
                                   remoteCodebase,
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
                                   expectedTypeClassLoader,
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
                                   expectedType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
                                   expectedTypeClassLoader);
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
     * Create an RMI stub name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
    public static String stubName (String className)
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        return stubName( className, false ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
    public static String dynamicStubName( String className )
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
        return stubName( className, true ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
    private static String stubName( String className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
        boolean isDynamic )
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        String name = stubNameForCompiler( className, isDynamic ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
        if (PackagePrefixChecker.hasOffendingPrefix( name ))
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
            name = PackagePrefixChecker.packagePrefix() + name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
        return name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
    public static String stubNameForCompiler (String className)
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
        return stubNameForCompiler( className, false ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
    private static String stubNameForCompiler( String className,
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
        boolean isDynamic )
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
        int index = className.indexOf('$');
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        if (index < 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
            index = className.lastIndexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
        String suffix = isDynamic ? DYNAMIC_STUB_SUFFIX :
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
            RMI_STUB_SUFFIX ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
        if (index > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
            return className.substring(0,index+1) + STUB_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                className.substring(index+1) + suffix;
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
            return STUB_PREFIX + className + suffix;
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
     * Create an RMI tie name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
    public static String tieName (String className)
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
        return
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
            PackagePrefixChecker.hasOffendingPrefix(tieNameForCompiler(className)) ?
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
            PackagePrefixChecker.packagePrefix() + tieNameForCompiler(className) :
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
            tieNameForCompiler(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
    public static String tieNameForCompiler (String className)
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
        int index = className.indexOf('$');
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
        if (index < 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
            index = className.lastIndexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
        if (index > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
            return className.substring(0,index+1) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
                STUB_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
                className.substring(index+1) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
                TIE_SUFIX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
            return STUB_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
                className +
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
                TIE_SUFIX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
     * Throws the CORBA equivalent of a java.io.NotSerializableException
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
    public static void throwNotSerializableForCorba(String className) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
        throw omgWrapper.notSerializable( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
            className ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
     * Create an IDL stub name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
    public static String idlStubName(String className)
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
        String result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
        int index = className.lastIndexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
        if (index > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
            result = className.substring(0,index+1) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
                STUB_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
                className.substring(index+1) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
                IDL_STUB_SUFFIX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
            result = STUB_PREFIX +
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
                className +
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
                IDL_STUB_SUFFIX;
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
    public static void printStackTrace()
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
        Throwable thr = new Throwable( "Printing stack trace:" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
        thr.fillInStackTrace() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
        thr.printStackTrace() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
     * Read an object reference from the input stream and narrow
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
     * it to the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
     * @param in the stream to read from.
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
     * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
    public static Object readObjectAndNarrow(InputStream in,
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                                             Class narrowTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
        throws ClassCastException
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
        Object result = in.read_Object();
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
        if (result != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
            return PortableRemoteObject.narrow(result, narrowTo);
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
     * Read an abstract interface type from the input stream and narrow
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
     * it to the desired type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
     * @param in the stream to read from.
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
     * @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
    public static Object readAbstractAndNarrow(
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
        org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
        throws ClassCastException
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
        Object result = in.read_abstract_interface();
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
        if (result != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
            return PortableRemoteObject.narrow(result, narrowTo);
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
            return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
    /** Converts an Ascii Character into Hexadecimal digit
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
    static int hexOf( char x )
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
        int val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
        val = x - '0';
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        if (val >=0 && val <= 9)
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        val = (x - 'a') + 10;
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
        if (val >= 10 && val <= 15)
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
        val = (x - 'A') + 10;
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        if (val >= 10 && val <= 15)
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
        throw wrapper.badHexDigit() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
class StubEntry {
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
    org.omg.CORBA.Object stub;
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
    boolean mostDerived;
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
    StubEntry(org.omg.CORBA.Object stub, boolean mostDerived) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        this.stub = stub;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
        this.mostDerived = mostDerived;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
}