KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > javax > rmi > CORBA > StubDelegateImpl


1 /*
2  * @(#)StubDelegateImpl.java 1.17 04/06/26
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Licensed Materials - Property of IBM
9  * RMI-IIOP v1.0
10  * Copyright IBM Corp. 1998 1999 All Rights Reserved
11  *
12  * US Government Users Restricted Rights - Use, duplication or
13  * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
14  */

15
16 package com.sun.corba.se.impl.javax.rmi.CORBA;
17
18 import java.io.IOException JavaDoc;
19
20 import java.rmi.RemoteException JavaDoc;
21
22 import javax.rmi.CORBA.Tie JavaDoc;
23
24 import org.omg.CORBA.ORB JavaDoc;
25 import org.omg.CORBA.SystemException JavaDoc;
26 import org.omg.CORBA.BAD_OPERATION JavaDoc;
27 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
28
29 import org.omg.CORBA.portable.Delegate JavaDoc;
30 import org.omg.CORBA.portable.OutputStream JavaDoc;
31 import org.omg.CORBA.portable.InputStream JavaDoc;
32
33 import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
34
35 import com.sun.corba.se.spi.logging.CORBALogDomains ;
36
37 import com.sun.corba.se.impl.util.Utility;
38
39 import com.sun.corba.se.impl.ior.StubIORImpl ;
40 import com.sun.corba.se.impl.presentation.rmi.StubConnectImpl ;
41
42 import com.sun.corba.se.impl.logging.UtilSystemException ;
43
44 /**
45  * Base class from which all static RMI-IIOP stubs must inherit.
46  */

47 public class StubDelegateImpl implements javax.rmi.CORBA.StubDelegate JavaDoc
48 {
49     static UtilSystemException wrapper = UtilSystemException.get(
50     CORBALogDomains.RMIIIOP ) ;
51
52     private StubIORImpl ior ;
53
54     public StubIORImpl getIOR()
55     {
56     return ior ;
57     }
58     
59     public StubDelegateImpl()
60     {
61     ior = null ;
62     }
63
64     /**
65      * Sets the IOR components if not already set.
66      */

67     private void init (javax.rmi.CORBA.Stub JavaDoc self)
68     {
69         // If the Stub is not connected to an ORB, BAD_OPERATION exception
70
// will be raised by the code below.
71
if (ior == null)
72         ior = new StubIORImpl( self ) ;
73     }
74         
75     /**
76      * Returns a hash code value for the object which is the same for all stubs
77      * that represent the same remote object.
78      * @return the hash code value.
79      */

80     public int hashCode(javax.rmi.CORBA.Stub JavaDoc self)
81     {
82         init(self);
83     return ior.hashCode() ;
84     }
85
86     /**
87      * Compares two stubs for equality. Returns <code>true</code> when used to compare stubs
88      * that represent the same remote object, and <code>false</code> otherwise.
89      * @param obj the reference object with which to compare.
90      * @return <code>true</code> if this object is the same as the <code>obj</code>
91      * argument; <code>false</code> otherwise.
92      */

93     public boolean equals(javax.rmi.CORBA.Stub JavaDoc self, java.lang.Object JavaDoc obj)
94     {
95         if (self == obj) {
96             return true;
97         }
98         
99         if (!(obj instanceof javax.rmi.CORBA.Stub JavaDoc)) {
100             return false;
101         }
102         
103     // no need to call init() because of calls to hashCode() below
104

105         javax.rmi.CORBA.Stub JavaDoc other = (javax.rmi.CORBA.Stub JavaDoc) obj;
106         if (other.hashCode() != self.hashCode()) {
107             return false;
108         }
109
110         // hashCodes being the same does not mean equality. The stubs still
111
// could be pointing to different IORs. So, do a literal comparison.
112
// Apparently the ONLY way to do this (other than using private
113
// reflection) toString, because it is not possible to directly
114
// access the StubDelegateImpl from the Stub.
115
return self.toString().equals( other.toString() ) ;
116     }
117
118     public boolean equals( Object JavaDoc obj )
119     {
120     if (this == obj)
121         return true ;
122
123     if (!(obj instanceof StubDelegateImpl))
124         return false ;
125
126     StubDelegateImpl other = (StubDelegateImpl)obj ;
127
128     if (ior == null)
129         return ior == other.ior ;
130     else
131         return ior.equals( other.ior ) ;
132     }
133
134     /**
135      * Returns a string representation of this stub. Returns the same string
136      * for all stubs that represent the same remote object.
137      * @return a string representation of this stub.
138      */

139     public String JavaDoc toString(javax.rmi.CORBA.Stub JavaDoc self)
140     {
141     if (ior == null)
142         return null ;
143     else
144         return ior.toString() ;
145     }
146     
147     /**
148      * Connects this stub to an ORB. Required after the stub is deserialized
149      * but not after it is demarshalled by an ORB stream. If an unconnected
150      * stub is passed to an ORB stream for marshalling, it is implicitly
151      * connected to that ORB. Application code should not call this method
152      * directly, but should call the portable wrapper method
153      * {@link javax.rmi.PortableRemoteObject#connect}.
154      * @param orb the ORB to connect to.
155      * @exception RemoteException if the stub is already connected to a different
156      * ORB, or if the stub does not represent an exported remote or local object.
157      */

158     public void connect(javax.rmi.CORBA.Stub JavaDoc self, ORB JavaDoc orb)
159         throws RemoteException JavaDoc
160     {
161     ior = StubConnectImpl.connect( ior, self, self, orb ) ;
162     }
163
164     /**
165      * Serialization method to restore the IOR state.
166      */

167     public void readObject(javax.rmi.CORBA.Stub JavaDoc self,
168     java.io.ObjectInputStream JavaDoc stream) throws IOException JavaDoc, ClassNotFoundException JavaDoc
169     {
170     if (ior == null)
171         ior = new StubIORImpl() ;
172
173     ior.doRead( stream ) ;
174     }
175
176     /**
177      * Serialization method to save the IOR state.
178      * @serialData The length of the IOR type ID (int), followed by the IOR type ID
179      * (byte array encoded using ISO8859-1), followed by the number of IOR profiles
180      * (int), followed by the IOR profiles. Each IOR profile is written as a
181      * profile tag (int), followed by the length of the profile data (int), followed
182      * by the profile data (byte array).
183      */

184     public void writeObject(javax.rmi.CORBA.Stub JavaDoc self,
185     java.io.ObjectOutputStream JavaDoc stream) throws IOException JavaDoc
186     {
187         init(self);
188     ior.doWrite( stream ) ;
189     }
190 }
191
Popular Tags