corba/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java
author tbell
Mon, 20 Apr 2009 00:12:19 -0700
changeset 2664 a0a22a8f16bd
parent 4 02bb8761fcce
child 3291 805a72a26925
permissions -rw-r--r--
6372405: Server thread hangs when fragments don't complete because of connection abort 5104239: Java: thread deadlock 6191561: JCK15: api/org_omg/PortableInterceptor/ClientRequestInfo/index.html#RIMethods sometime hang 6486322: org.omg.CORBA.ORB.init() thread safety issue 6420980: Security issue with the com.sun.corba.se.impl.orbutil.ORBUtility class 6465377: NullPointerException for RMI ORB in 1.5.0_08 6553303: Corba application fails w/ org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 203 completed: No 6438259: Wrong repository ID generated by IDLJ Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
2664
a0a22a8f16bd 6372405: Server thread hangs when fragments don't complete because of connection abort
tbell
parents: 4
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  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
02bb8761fcce Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
02bb8761fcce Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
02bb8761fcce Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
02bb8761fcce Initial load
duke
parents:
diff changeset
    23
 * have any questions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.orbutil;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.lang.Character;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Field;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Method;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.rmi.NoSuchObjectException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.security.PermissionCollection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.security.Policy;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.security.ProtectionDomain;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.util.ArrayList;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.util.Arrays;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.util.Map;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.util.List;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import java.util.ListIterator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import java.util.Set;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.util.Map.Entry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import java.util.Collection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.util.HashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.util.HashSet;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import java.util.Iterator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import java.util.IdentityHashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import java.util.StringTokenizer;
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 javax.rmi.CORBA.ValueHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import javax.rmi.CORBA.ValueHandlerMultiFormat;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import javax.rmi.CORBA.Util;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import org.omg.CORBA.StructMember ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import org.omg.CORBA.TypeCode ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import org.omg.CORBA.Any ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import org.omg.CORBA.TCKind ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import org.omg.CORBA.SystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import org.omg.CORBA.CompletionStatus ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
import org.omg.CORBA.DATA_CONVERSION ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import org.omg.CORBA.BAD_PARAM ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import org.omg.CORBA.BAD_OPERATION ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import org.omg.CORBA.INTERNAL ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import org.omg.CORBA.TypeCodePackage.BadKind ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import org.omg.CORBA.portable.OutputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import org.omg.CORBA.portable.InputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import com.sun.corba.se.pept.transport.ContactInfoList ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
import com.sun.corba.se.spi.ior.IOR ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.spi.orb.ORBVersion ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.spi.orb.ORBVersionFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.spi.protocol.CorbaClientDelegate ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.spi.ior.iiop.IIOPProfile;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
import com.sun.corba.se.impl.corba.CORBAObjectImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
import com.sun.corba.se.impl.logging.OMGSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
import com.sun.corba.se.impl.ior.iiop.JavaSerializationComponent;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
 *  Handy class full of static functions that don't belong in util.Utility for pure ORB reasons.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
public final class ORBUtility {
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    private ORBUtility() {}
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    private static ORBUtilSystemException wrapper = ORBUtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        CORBALogDomains.UTIL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    private static OMGSystemException omgWrapper = OMGSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        CORBALogDomains.UTIL ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    private static StructMember[] members = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    private static StructMember[] systemExceptionMembers (ORB orb) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        if (members == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            members = new StructMember[3];
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
            members[0] = new StructMember("id", orb.create_string_tc(0), null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
            members[1] = new StructMember("minor", orb.get_primitive_tc(TCKind.tk_long), null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            members[2] = new StructMember("completed", orb.get_primitive_tc(TCKind.tk_long), null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        return members;
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    private static TypeCode getSystemExceptionTypeCode(ORB orb, String repID, String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        synchronized (TypeCode.class) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            return orb.create_exception_tc(repID, name, systemExceptionMembers(orb));
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    private static boolean isSystemExceptionTypeCode(TypeCode type, ORB orb) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        StructMember[] systemExceptionMembers = systemExceptionMembers(orb);
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
            return (type.kind().value() == TCKind._tk_except &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
                    type.member_count() == 3 &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                    type.member_type(0).equal(systemExceptionMembers[0].type) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                    type.member_type(1).equal(systemExceptionMembers[1].type) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
                    type.member_type(2).equal(systemExceptionMembers[2].type));
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        } catch (BadKind ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        } catch (org.omg.CORBA.TypeCodePackage.Bounds ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
     * Static method for writing a CORBA standard exception to an Any.
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
     * @param any The Any to write the SystemException into.
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    public static void insertSystemException(SystemException ex, Any any) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        OutputStream out = any.create_output_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        ORB orb = (ORB)(out.orb());
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        String name = ex.getClass().getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        String repID = ORBUtility.repositoryIdOf(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        out.write_string(repID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        out.write_long(ex.minor);
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        out.write_long(ex.completed.value());
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        any.read_value(out.create_input_stream(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            getSystemExceptionTypeCode(orb, repID, name));
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    public static SystemException extractSystemException(Any any) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
        InputStream in = any.create_input_stream();
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        ORB orb = (ORB)(in.orb());
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        if ( ! isSystemExceptionTypeCode(any.type(), orb)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
            throw wrapper.unknownDsiSysex(CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        return ORBUtility.readSystemException(in);
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     * Creates the correct ValueHandler for the given ORB,
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
     * querying ORBVersion information.  If the ORB or
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
     * ORBVersion is null, gets the ValueHandler from
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
     * Util.createValueHandler.
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    public static ValueHandler createValueHandler(ORB orb) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
        if (orb == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
            return Util.createValueHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        ORBVersion version = orb.getORBVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        if (version == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
            return Util.createValueHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        if (version.equals(ORBVersionFactory.getOLD()))
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
            return new ValueHandlerImpl_1_3();
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
        if (version.equals(ORBVersionFactory.getNEW()))
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
            return new ValueHandlerImpl_1_3_1();
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        return Util.createValueHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
     * Returns true if the given ORB could accurately be determined to be a
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
     * Kestrel or earlier ORB.  Note: If passed the ORBSingleton, this will return
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
     * false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    public static boolean isLegacyORB(ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            ORBVersion currentORB = orb.getORBVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            return currentORB.equals( ORBVersionFactory.getOLD() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        } catch (SecurityException se) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * Returns true if it was accurately determined that the remote ORB is
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     * a foreign (non-JavaSoft) ORB.  Note:  If passed the ORBSingleton, this
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
     * will return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    public static boolean isForeignORB(ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        if (orb == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
            return orb.getORBVersion().equals(ORBVersionFactory.getFOREIGN());
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        } catch (SecurityException se) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    /** Unmarshal a byte array to an integer.
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        Assume the bytes are in BIGENDIAN order.
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
        i.e. array[offset] is the most-significant-byte
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        and  array[offset+3] is the least-significant-byte.
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
        @param array The array of bytes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        @param offset The offset from which to start unmarshalling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    public static int bytesToInt(byte[] array, int offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        int b1, b2, b3, b4;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        b1 = (array[offset++] << 24) & 0xFF000000;
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
        b2 = (array[offset++] << 16) & 0x00FF0000;
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        b3 = (array[offset++] << 8)  & 0x0000FF00;
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        b4 = (array[offset++] << 0)  & 0x000000FF;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        return (b1 | b2 | b3 | b4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
    /** Marshal an integer to a byte array.
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
        The bytes are in BIGENDIAN order.
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
        i.e. array[offset] is the most-significant-byte
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        and  array[offset+3] is the least-significant-byte.
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
        @param array The array of bytes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        @param offset The offset from which to start marshalling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    public static void intToBytes(int value, byte[] array, int offset)
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
        array[offset++] = (byte)((value >>> 24) & 0xFF);
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
        array[offset++] = (byte)((value >>> 16) & 0xFF);
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
        array[offset++] = (byte)((value >>> 8) & 0xFF);
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
        array[offset++] = (byte)((value >>> 0) & 0xFF);
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
    /** Converts an Ascii Character into Hexadecimal digit
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    public static int hexOf( char x )
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        int val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        val = x - '0';
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        if (val >=0 && val <= 9)
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        val = (x - 'a') + 10;
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
        if (val >= 10 && val <= 15)
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
        val = (x - 'A') + 10;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        if (val >= 10 && val <= 15)
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
        throw wrapper.badHexDigit() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    // method moved from util.Utility
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
     * Static method for writing a CORBA standard exception to a stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
     * @param strm The OutputStream to use for marshaling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    public static void writeSystemException(SystemException ex, OutputStream strm)
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
        String s;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
        s = repositoryIdOf(ex.getClass().getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        strm.write_string(s);
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        strm.write_long(ex.minor);
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
        strm.write_long(ex.completed.value());
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
     * Static method for reading a CORBA standard exception from a stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
     * @param strm The InputStream to use for unmarshaling.
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    public static SystemException readSystemException(InputStream strm)
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
            String name = classNameOf(strm.read_string());
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            SystemException ex
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                = (SystemException)ORBClassLoader.loadClass(name).newInstance();
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            ex.minor = strm.read_long();
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
            ex.completed = CompletionStatus.from_int(strm.read_long());
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
            return ex;
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        } catch ( Exception ex ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
            throw wrapper.unknownSysex( CompletionStatus.COMPLETED_MAYBE, ex );
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
     * Get the class name corresponding to a particular repository Id.
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
     * This is used by the system to unmarshal (instantiate) the
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
     * appropriate exception class for an marshaled as the value of
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
     * its repository Id.
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
     * @param repositoryId The repository Id for which we want a class name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    public static String classNameOf(String repositoryId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        String className=null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        className = (String) exceptionClassNames.get(repositoryId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
        if (className == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
            className = "org.omg.CORBA.UNKNOWN";
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        return className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
     * Return true if this repositoryId is a SystemException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
     * @param repositoryId The repository Id to check.
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
    public static boolean isSystemException(String repositoryId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
        String className=null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
        className = (String) exceptionClassNames.get(repositoryId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
        if (className == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     * @return the Java serialization encoding version.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    public static byte getEncodingVersion(ORB orb, IOR ior) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
        // Is Java serialization enabled?
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
        // Check the JavaSerializationComponent (tagged component)
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        // in the IIOPProfile. If present, the peer ORB's GIOP is capable
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        // of using Java serialization instead of CDR serialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
        // In such a case, use Java serialization, iff the java serialization
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        // versions match.
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        if (orb.getORBData().isJavaSerializationEnabled()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
            IIOPProfile prof = ior.getProfile();
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            IIOPProfileTemplate profTemp =
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
                (IIOPProfileTemplate) prof.getTaggedProfileTemplate();
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            java.util.Iterator iter = profTemp.iteratorById(
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
                                  ORBConstants.TAG_JAVA_SERIALIZATION_ID);
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
            if (iter.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
                JavaSerializationComponent jc =
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
                    (JavaSerializationComponent) iter.next();
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
                byte jcVersion = jc.javaSerializationVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
                if (jcVersion >= Message.JAVA_ENC_VERSION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
                    return Message.JAVA_ENC_VERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
                } else if (jcVersion > Message.CDR_ENC_VERSION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
                    return jc.javaSerializationVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
                    // throw error?
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                    // Since encodingVersion is <= 0 (CDR_ENC_VERSION).
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        return Message.CDR_ENC_VERSION; // default
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
     * Get the repository id corresponding to a particular class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
     * This is used by the system to write the
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
     * appropriate repository id for a system exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
     * @param name The class name of the system exception.
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    public static String repositoryIdOf(String name)
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        String id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        id = (String) exceptionRepositoryIds.get(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        if (id == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
            id = "IDL:omg.org/CORBA/UNKNOWN:1.0";
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        return id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    private static final Hashtable exceptionClassNames = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
    private static final Hashtable exceptionRepositoryIds = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    static {
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        // construct repositoryId -> className hashtable
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_CONTEXT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                                "org.omg.CORBA.BAD_CONTEXT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_INV_ORDER:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
                                "org.omg.CORBA.BAD_INV_ORDER");
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_OPERATION:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
                                "org.omg.CORBA.BAD_OPERATION");
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_PARAM:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
                                "org.omg.CORBA.BAD_PARAM");
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_TYPECODE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
                                "org.omg.CORBA.BAD_TYPECODE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        exceptionClassNames.put("IDL:omg.org/CORBA/COMM_FAILURE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
                                "org.omg.CORBA.COMM_FAILURE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
        exceptionClassNames.put("IDL:omg.org/CORBA/DATA_CONVERSION:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
                                "org.omg.CORBA.DATA_CONVERSION");
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
        exceptionClassNames.put("IDL:omg.org/CORBA/IMP_LIMIT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
                                "org.omg.CORBA.IMP_LIMIT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        exceptionClassNames.put("IDL:omg.org/CORBA/INTF_REPOS:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
                                "org.omg.CORBA.INTF_REPOS");
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        exceptionClassNames.put("IDL:omg.org/CORBA/INTERNAL:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
                                "org.omg.CORBA.INTERNAL");
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        exceptionClassNames.put("IDL:omg.org/CORBA/INV_FLAG:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
                                "org.omg.CORBA.INV_FLAG");
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        exceptionClassNames.put("IDL:omg.org/CORBA/INV_IDENT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
                                "org.omg.CORBA.INV_IDENT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
        exceptionClassNames.put("IDL:omg.org/CORBA/INV_OBJREF:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
                                "org.omg.CORBA.INV_OBJREF");
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        exceptionClassNames.put("IDL:omg.org/CORBA/MARSHAL:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
                                "org.omg.CORBA.MARSHAL");
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
        exceptionClassNames.put("IDL:omg.org/CORBA/NO_MEMORY:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
                                "org.omg.CORBA.NO_MEMORY");
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
        exceptionClassNames.put("IDL:omg.org/CORBA/FREE_MEM:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                                "org.omg.CORBA.FREE_MEM");
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
        exceptionClassNames.put("IDL:omg.org/CORBA/NO_IMPLEMENT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                                "org.omg.CORBA.NO_IMPLEMENT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
        exceptionClassNames.put("IDL:omg.org/CORBA/NO_PERMISSION:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
                                "org.omg.CORBA.NO_PERMISSION");
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
        exceptionClassNames.put("IDL:omg.org/CORBA/NO_RESOURCES:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
                                "org.omg.CORBA.NO_RESOURCES");
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
        exceptionClassNames.put("IDL:omg.org/CORBA/NO_RESPONSE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                                "org.omg.CORBA.NO_RESPONSE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
        exceptionClassNames.put("IDL:omg.org/CORBA/OBJ_ADAPTER:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                                "org.omg.CORBA.OBJ_ADAPTER");
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
        exceptionClassNames.put("IDL:omg.org/CORBA/INITIALIZE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                                "org.omg.CORBA.INITIALIZE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
        exceptionClassNames.put("IDL:omg.org/CORBA/PERSIST_STORE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
                                "org.omg.CORBA.PERSIST_STORE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        exceptionClassNames.put("IDL:omg.org/CORBA/TRANSIENT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
                                "org.omg.CORBA.TRANSIENT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        exceptionClassNames.put("IDL:omg.org/CORBA/UNKNOWN:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                                "org.omg.CORBA.UNKNOWN");
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        exceptionClassNames.put("IDL:omg.org/CORBA/OBJECT_NOT_EXIST:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
                                "org.omg.CORBA.OBJECT_NOT_EXIST");
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
        // SystemExceptions from OMG Transactions Service Spec
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
        exceptionClassNames.put("IDL:omg.org/CORBA/INVALID_TRANSACTION:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                                "org.omg.CORBA.INVALID_TRANSACTION");
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
        exceptionClassNames.put("IDL:omg.org/CORBA/TRANSACTION_REQUIRED:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
                                "org.omg.CORBA.TRANSACTION_REQUIRED");
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        exceptionClassNames.put("IDL:omg.org/CORBA/TRANSACTION_ROLLEDBACK:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
                                "org.omg.CORBA.TRANSACTION_ROLLEDBACK");
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
        // from portability RTF 98-07-01.txt
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
        exceptionClassNames.put("IDL:omg.org/CORBA/INV_POLICY:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                                "org.omg.CORBA.INV_POLICY");
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        // from orbrev/00-09-01 (CORBA 2.4 Draft Specification)
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
        exceptionClassNames.
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
            put("IDL:omg.org/CORBA/TRANSACTION_UNAVAILABLE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
                                "org.omg.CORBA.TRANSACTION_UNAVAILABLE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
        exceptionClassNames.put("IDL:omg.org/CORBA/TRANSACTION_MODE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
                                "org.omg.CORBA.TRANSACTION_MODE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
        // Exception types introduced between CORBA 2.4 and 3.0
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        exceptionClassNames.put("IDL:omg.org/CORBA/CODESET_INCOMPATIBLE:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
                                "org.omg.CORBA.CODESET_INCOMPATIBLE");
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        exceptionClassNames.put("IDL:omg.org/CORBA/REBIND:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
                                "org.omg.CORBA.REBIND");
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        exceptionClassNames.put("IDL:omg.org/CORBA/TIMEOUT:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
                                "org.omg.CORBA.TIMEOUT");
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
        exceptionClassNames.put("IDL:omg.org/CORBA/BAD_QOS:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
                                "org.omg.CORBA.BAD_QOS");
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        // Exception types introduced in CORBA 3.0
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
        exceptionClassNames.put("IDL:omg.org/CORBA/INVALID_ACTIVITY:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
                                "org.omg.CORBA.INVALID_ACTIVITY");
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
        exceptionClassNames.put("IDL:omg.org/CORBA/ACTIVITY_COMPLETED:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
                                "org.omg.CORBA.ACTIVITY_COMPLETED");
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
        exceptionClassNames.put("IDL:omg.org/CORBA/ACTIVITY_REQUIRED:1.0",
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
                                "org.omg.CORBA.ACTIVITY_REQUIRED");
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
        // construct className -> repositoryId hashtable
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
        Enumeration keys = exceptionClassNames.keys();
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
        java.lang.Object s;
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
        String rId;
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        String cName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
        try{
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            while (keys.hasMoreElements()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
                s = keys.nextElement();
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                rId = (String) s;
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
                cName = (String) exceptionClassNames.get(rId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
                exceptionRepositoryIds.put (cName, rId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        } catch (NoSuchElementException e) { }
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
    /** Parse a version string such as "1.1.6" or "jdk1.2fcs" into
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        a version array of integers {1, 1, 6} or {1, 2}.
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
        A string of "n." or "n..m" is equivalent to "n.0" or "n.0.m" respectively.
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
    public static int[] parseVersion(String version) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        if (version == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
            return new int[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        char[] s = version.toCharArray();
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
        //find the maximum span of the string "n.n.n..." where n is an integer
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        int start = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
        for (; start < s.length  && (s[start] < '0' || s[start] > '9'); ++start)
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
            if (start == s.length)      //no digit found
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
                return new int[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
        int end = start + 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
        int size = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        for (; end < s.length; ++end)
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
            if (s[end] == '.')
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
                ++size;
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
            else if (s[end] < '0' || s[end] > '9')
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
        int[] val = new int[size];
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
        for (int i = 0; i < size; ++i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
            int dot = version.indexOf('.', start);
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
            if (dot == -1 || dot > end)
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
                dot = end;
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
            if (start >= dot)   //cases like "n." or "n..m"
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
                val[i] = 0;     //convert equivalent to "n.0" or "n.0.m"
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
            else
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
                val[i] = Integer.parseInt(version.substring(start, dot));
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
            start = dot + 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
        return val;
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    /** Compare two version arrays.
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
        Return 1, 0 or -1 if v1 is greater than, equal to, or less than v2.
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    public static int compareVersion(int[] v1, int[] v2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
        if (v1 == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
            v1 = new int[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
        if (v2 == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
            v2 = new int[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
        for (int i = 0; i < v1.length; ++i) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
            if (i >= v2.length || v1[i] > v2[i])        //v1 is longer or greater than v2
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                return 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
            if (v1[i] < v2[i])
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                return -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
        return v1.length == v2.length ? 0 : -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
    /** Compare two version strings.
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
        Return 1, 0 or -1 if v1 is greater than, equal to, or less than v2.
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
    public static synchronized int compareVersion(String v1, String v2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        return compareVersion(parseVersion(v1), parseVersion(v2));
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    private static String compressClassName( String name )
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        // Note that this must end in . in order to be renamed correctly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
        String prefix = "com.sun.corba.se." ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        if (name.startsWith( prefix ) ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
            return "(ORB)." + name.substring( prefix.length() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
            return name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    // Return a compressed representation of the thread name.  This is particularly
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
    // useful on the server side, where there are many SelectReaderThreads, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
    // we need a short unambiguous name for such threads.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
    public static String getThreadName( Thread thr )
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
        if (thr == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
            return "null" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
        // This depends on the formatting in SelectReaderThread and CorbaConnectionImpl.
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        // Pattern for SelectReaderThreads:
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
        // SelectReaderThread CorbaConnectionImpl[ <host> <post> <state>]
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
        // Any other pattern in the Thread's name is just returned.
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
        String name = thr.getName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
        StringTokenizer st = new StringTokenizer( name ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
        int numTokens = st.countTokens() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
        if (numTokens != 5)
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
            return name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
        String[] tokens = new String[numTokens] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
        for (int ctr=0; ctr<numTokens; ctr++ )
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
            tokens[ctr] = st.nextToken() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
        if( !tokens[0].equals("SelectReaderThread"))
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
            return name ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
        return "SelectReaderThread[" + tokens[2] + ":" + tokens[3] + "]" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    private static String formatStackTraceElement( StackTraceElement ste )
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
        return compressClassName( ste.getClassName() ) + "." + ste.getMethodName() +
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
            (ste.isNativeMethod() ? "(Native Method)" :
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
             (ste.getFileName() != null && ste.getLineNumber() >= 0 ?
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
              "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")" :
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
              (ste.getFileName() != null ?  "("+ste.getFileName()+")" : "(Unknown Source)")));
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
    private static void printStackTrace( StackTraceElement[] trace )
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        System.out.println( "    Stack Trace:" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
        // print the stack trace, ommitting the zeroth element, which is
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
        // always this method.
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
        for ( int ctr = 1; ctr < trace.length; ctr++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
            System.out.print( "        >" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
            System.out.println( formatStackTraceElement( trace[ctr] ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
    // Implements all dprint calls in this package.
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    public static synchronized void dprint(java.lang.Object obj, String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
        System.out.println(
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
            compressClassName( obj.getClass().getName() ) + "("  +
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
            getThreadName( Thread.currentThread() ) + "): " + msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
    public static synchronized void dprint(String className, String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
        System.out.println(
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
            compressClassName( className ) + "("  +
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
            getThreadName( Thread.currentThread() ) + "): " + msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    public synchronized void dprint(String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
        ORBUtility.dprint(this, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
    public static synchronized void dprintTrace(Object obj, String msg) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
        ORBUtility.dprint(obj, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
        Throwable thr = new Throwable() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
        printStackTrace( thr.getStackTrace() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    public static synchronized void dprint(java.lang.Object caller,
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
        String msg, Throwable t)
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
        System.out.println(
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
            compressClassName( caller.getClass().getName() ) +
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
            '(' + Thread.currentThread() + "): " + msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
        if (t != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
            printStackTrace( t.getStackTrace() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    public static String[] concatenateStringArrays( String[] arr1, String[] arr2 )
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        String[] result = new String[
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
            arr1.length + arr2.length ] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        for (int ctr = 0; ctr<arr1.length; ctr++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
            result[ctr] = arr1[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        for (int ctr = 0; ctr<arr2.length; ctr++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
            result[ctr + arr1.length] = arr2[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
     * Throws the CORBA equivalent of a java.io.NotSerializableException
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
     * Duplicated from util/Utility for Pure ORB reasons.  There are two
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
     * reasons for this:
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
     * 1) We can't introduce dependencies on the util version from outside
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
     * of the io/util packages since it will not exist in the pure ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
     * build running on JDK 1.3.x.
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
     * 2) We need to pick up the correct minor code from OMGSystemException.
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
    public static void throwNotSerializableForCorba(String className) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
        throw omgWrapper.notSerializable( CompletionStatus.COMPLETED_MAYBE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
            className ) ;
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
     * Returns the maximum stream format version supported by our
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
     * ValueHandler.
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    public static byte getMaxStreamFormatVersion() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
        ValueHandler vh = Util.createValueHandler();
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
        if (!(vh instanceof javax.rmi.CORBA.ValueHandlerMultiFormat))
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
            return ORBConstants.STREAM_FORMAT_VERSION_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
            return ((ValueHandlerMultiFormat)vh).getMaximumStreamFormatVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
    public static CorbaClientDelegate makeClientDelegate( IOR ior )
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
        ORB orb = ior.getORB() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
        CorbaContactInfoList ccil = orb.getCorbaContactInfoListFactory().create( ior ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
        CorbaClientDelegate del = orb.getClientDelegateFactory().create(ccil);
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
        return del ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
    /** This method is used to create untyped object references.
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
    public static org.omg.CORBA.Object makeObjectReference( IOR ior )
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
        CorbaClientDelegate del = makeClientDelegate( ior ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
        org.omg.CORBA.Object objectImpl = new CORBAObjectImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
        StubAdapter.setDelegate( objectImpl, del ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
        return objectImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    /** This method obtains an IOR from a CORBA object reference.
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
    * It will return null if obj is a local object, a null object,
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
    * or an object implemented by a different ORB.  It will
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
    * throw BAD_OPERATION if obj is an unconnected RMI-IIOP object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
    * @return IOR the IOR that represents this objref.  This will
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
    * never be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
    * @exception BAD_OPERATION (from oi._get_delegate) if obj is a
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
    * normal objref, but does not have a delegate set.
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
    * @exception BAD_PARAM if obj is a local object, or else was
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
    * created by a foreign ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
    public static IOR getIOR( org.omg.CORBA.Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
        if (obj == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
            throw wrapper.nullObjectReference() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
        IOR ior = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        if (StubAdapter.isStub(obj)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
            org.omg.CORBA.portable.Delegate del = StubAdapter.getDelegate(
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
                obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
            if (del instanceof CorbaClientDelegate) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
                CorbaClientDelegate cdel = (CorbaClientDelegate)del ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
                ContactInfoList cil = cdel.getContactInfoList() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
                if (cil instanceof CorbaContactInfoList) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
                    CorbaContactInfoList ccil = (CorbaContactInfoList)cil ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
                    ior = ccil.getTargetIOR() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
                    if (ior == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
                        throw wrapper.nullIor() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
                    return ior ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
                    // This is our code, but the ContactInfoList is not a
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
                    // CorbaContactInfoList.  This should not happen, because
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
                    // we are in the CORBA application of the DCSA framework.
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
                    // This is a coding error, and thus an INTERNAL exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
                    // should be thrown.
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
                    // XXX needs minor code
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
                    throw new INTERNAL() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
            // obj is implemented by a foreign ORB, because the Delegate is not a
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
            // ClientDelegate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
            // XXX this case could be handled by marshalling and
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
            // unmarshalling.  However, object_to_string cannot be used
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
            // here, as it is implemented with getIOR.  Note that this
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
            // will require access to an ORB, so that we can create streams
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
            // as needed.  The ORB is available simply as io._orb().
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
            throw wrapper.objrefFromForeignOrb() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
        } else
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
            throw wrapper.localObjectNotAllowed() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
    /** Obtains an IOR for the object reference obj, first connecting it to
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
    * the ORB if necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
    * @return IOR the IOR that represents this objref.  This will
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    * never be null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
    * @exception BAD_OPERATION if the object could not be connected,
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
    * if a connection attempt was needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
    * @exception BAD_PARAM if obj is a local object, or else was
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
    * created by a foreign ORB.
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    */
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
    public static IOR connectAndGetIOR( ORB orb, org.omg.CORBA.Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        IOR result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
            result = getIOR( obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
        } catch (BAD_OPERATION bop) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
            if (StubAdapter.isStub(obj)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
                try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
                    StubAdapter.connect( obj, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
                } catch (java.rmi.RemoteException exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
                    throw wrapper.connectingServant( exc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
                orb.connect( obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
            result = getIOR( obj ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
        return result ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
    public static String operationNameAndRequestId(CorbaMessageMediator m)
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
        return "op/" + m.getOperationName() + " id/" + m.getRequestId();
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
    public static boolean isPrintable(char c)
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
        if (Character.isJavaIdentifierStart(c)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
            // Letters and $ _
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        if (Character.isDigit(c)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
        switch (Character.getType(c)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        case Character.MODIFIER_SYMBOL : return true; // ` ^
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        case Character.DASH_PUNCTUATION : return true; // -
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
        case Character.MATH_SYMBOL : return true; // = ~ + | < >
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
        case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
        case Character.START_PUNCTUATION : return true; // ( [ {
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
        case Character.END_PUNCTUATION : return true; // ) ] }
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
    public static String getClassSecurityInfo(final Class cl)
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
        // Returns a String which looks similar to:
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
        // PermissionCollection java.security.Permissions@1053693 ...
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
        // (java.io.FilePermission <<ALL FILES>> ....)
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
        // (java.io.FilePermission /export0/sunwappserv/lib/- ...)
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
        // ... other permissions ...
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
        // Domain ProtectionDomain  (file:/export0/sunwappserv/lib-)
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
        // java.security.Permissions@141fedb (
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
        // (java.io.FilePermission <<ALL FILES>> ...)
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
        // (java.io.FilePermission /var/tmp//- ...)
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
        String result =
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
            (String)AccessController.doPrivileged(new PrivilegedAction() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                public java.lang.Object run() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
                    StringBuffer sb = new StringBuffer(500);
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                    ProtectionDomain pd = cl.getProtectionDomain();
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
                    Policy policy = Policy.getPolicy();
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
                    PermissionCollection pc = policy.getPermissions(pd);
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
                    sb.append("\nPermissionCollection ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
                    sb.append(pc.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
                    // Don't need to add 'Protection Domain' string, it's
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                    // in ProtectionDomain.toString() already.
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                    sb.append(pd.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
                    return sb.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
            });
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
// End of file.