corba/src/share/classes/com/sun/corba/se/impl/javax/rmi/CORBA/StubDelegateImpl.java
author alanb
Mon, 10 Jun 2013 17:15:42 +0100
changeset 18302 3b06314efbd0
parent 5555 b2b5ed3f0d0d
child 22131 4d7b21463768
permissions -rw-r--r--
8016218: Warnings building corba repo due to missing hashCode methods Reviewed-by: chegar, coffeys, dfuchs
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
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
package com.sun.corba.se.impl.javax.rmi.CORBA;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.rmi.RemoteException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import javax.rmi.CORBA.Tie;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
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.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.BAD_OPERATION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import org.omg.CORBA.BAD_INV_ORDER;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.CORBA.portable.Delegate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import org.omg.CORBA.portable.OutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.CORBA.portable.InputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.corba.se.impl.ior.StubIORImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.corba.se.impl.presentation.rmi.StubConnectImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.corba.se.impl.logging.UtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 * Base class from which all static RMI-IIOP stubs must inherit.
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
public class StubDelegateImpl implements javax.rmi.CORBA.StubDelegate
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    static UtilSystemException wrapper = UtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        CORBALogDomains.RMIIIOP ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    private StubIORImpl ior ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    public StubIORImpl getIOR()
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        return ior ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    public StubDelegateImpl()
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        ior = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
     * Sets the IOR components if not already set.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    private void init (javax.rmi.CORBA.Stub self)
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        // If the Stub is not connected to an ORB, BAD_OPERATION exception
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        // will be raised by the code below.
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        if (ior == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
            ior = new StubIORImpl( self ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
     * Returns a hash code value for the object which is the same for all stubs
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
     * that represent the same remote object.
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
     * @return the hash code value.
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    public int hashCode(javax.rmi.CORBA.Stub self)
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        init(self);
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        return ior.hashCode() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
     * Compares two stubs for equality. Returns <code>true</code> when used to compare stubs
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
     * that represent the same remote object, and <code>false</code> otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
     * @param obj the reference object with which to compare.
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
     * @return <code>true</code> if this object is the same as the <code>obj</code>
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
     *          argument; <code>false</code> otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    public boolean equals(javax.rmi.CORBA.Stub self, java.lang.Object obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        if (self == obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        if (!(obj instanceof javax.rmi.CORBA.Stub)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        // no need to call init() because of calls to hashCode() below
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        javax.rmi.CORBA.Stub other = (javax.rmi.CORBA.Stub) obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        if (other.hashCode() != self.hashCode()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
        // hashCodes being the same does not mean equality. The stubs still
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        // could be pointing to different IORs. So, do a literal comparison.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
        // Apparently the ONLY way to do this (other than using private
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        // reflection)  toString, because it is not possible to directly
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        // access the StubDelegateImpl from the Stub.
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        return self.toString().equals( other.toString() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    public boolean equals( Object obj )
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        if (this == obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            return true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
        if (!(obj instanceof StubDelegateImpl))
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        StubDelegateImpl other = (StubDelegateImpl)obj ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        if (ior == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
            return ior == other.ior ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
            return ior.equals( other.ior ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
18302
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   150
    public int hashCode() {
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   151
        if (ior == null) {
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   152
            return 0;
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   153
        } else {
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   154
            return ior.hashCode();
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   155
        }
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   156
    }
3b06314efbd0 8016218: Warnings building corba repo due to missing hashCode methods
alanb
parents: 5555
diff changeset
   157
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
     * Returns a string representation of this stub. Returns the same string
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * for all stubs that represent the same remote object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * @return a string representation of this stub.
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    public String toString(javax.rmi.CORBA.Stub self)
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        if (ior == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
            return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
            return ior.toString() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
     * Connects this stub to an ORB. Required after the stub is deserialized
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
     * but not after it is demarshalled by an ORB stream. If an unconnected
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     * stub is passed to an ORB stream for marshalling, it is implicitly
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
     * connected to that ORB. Application code should not call this method
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
     * directly, but should call the portable wrapper method
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
     * {@link javax.rmi.PortableRemoteObject#connect}.
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
     * @param orb the ORB to connect to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
     * @exception RemoteException if the stub is already connected to a different
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
     * ORB, or if the stub does not represent an exported remote or local object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    public void connect(javax.rmi.CORBA.Stub self, ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        throws RemoteException
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
        ior = StubConnectImpl.connect( ior, self, self, orb ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
     * Serialization method to restore the IOR state.
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    public void readObject(javax.rmi.CORBA.Stub self,
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
        java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
        if (ior == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
            ior = new StubIORImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
        ior.doRead( stream ) ;
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
     * Serialization method to save the IOR state.
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * @serialData The length of the IOR type ID (int), followed by the IOR type ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     * (byte array encoded using ISO8859-1), followed by the number of IOR profiles
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
     * (int), followed by the IOR profiles.  Each IOR profile is written as a
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * profile tag (int), followed by the length of the profile data (int), followed
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     * by the profile data (byte array).
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    public void writeObject(javax.rmi.CORBA.Stub self,
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
        java.io.ObjectOutputStream stream) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        init(self);
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        ior.doWrite( stream ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
}