KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > presentation > rmi > StubConnectImpl


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

7
8 package com.sun.corba.se.impl.presentation.rmi ;
9
10 import java.rmi.RemoteException JavaDoc;
11
12 import javax.rmi.CORBA.Tie JavaDoc;
13
14 import org.omg.CORBA.ORB JavaDoc;
15 import org.omg.CORBA.SystemException JavaDoc;
16 import org.omg.CORBA.BAD_OPERATION JavaDoc;
17 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
18
19 import org.omg.CORBA.portable.ObjectImpl JavaDoc;
20 import org.omg.CORBA.portable.Delegate JavaDoc;
21
22 import com.sun.corba.se.spi.presentation.rmi.StubAdapter;
23
24 import com.sun.corba.se.spi.logging.CORBALogDomains ;
25
26 import com.sun.corba.se.impl.util.Utility;
27
28 import com.sun.corba.se.impl.ior.StubIORImpl ;
29
30 import com.sun.corba.se.impl.logging.UtilSystemException ;
31
32 import com.sun.corba.se.impl.corba.CORBAObjectImpl ;
33
34 public abstract class StubConnectImpl
35 {
36     static UtilSystemException wrapper = UtilSystemException.get(
37     CORBALogDomains.RMIIIOP ) ;
38
39     /** Connect the stub to the orb if necessary.
40     * @param ior The StubIORImpl for this stub (may be null)
41     * @param proxy The externally visible stub seen by the user (may be the same as stub)
42     * @param stub The stub implementation that extends ObjectImpl
43     * @param orb The ORB to which we connect the stub.
44     */

45     public static StubIORImpl connect( StubIORImpl ior, org.omg.CORBA.Object JavaDoc proxy,
46     org.omg.CORBA.portable.ObjectImpl JavaDoc stub, ORB JavaDoc orb ) throws RemoteException JavaDoc
47     {
48     Delegate JavaDoc del = null ;
49
50     try {
51         try {
52         del = StubAdapter.getDelegate( stub );
53         
54         if (del.orb(stub) != orb)
55             throw wrapper.connectWrongOrb() ;
56         } catch (org.omg.CORBA.BAD_OPERATION JavaDoc err) {
57         if (ior == null) {
58             // No IOR, can we get a Tie for this stub?
59
Tie JavaDoc tie = (javax.rmi.CORBA.Tie JavaDoc) Utility.getAndForgetTie(proxy);
60             if (tie == null)
61             throw wrapper.connectNoTie() ;
62
63             // Is the tie already connected? If it is, check that it's
64
// connected to the same ORB, otherwise connect it.
65
ORB JavaDoc existingOrb = orb ;
66             try {
67             existingOrb = tie.orb();
68             } catch (BAD_OPERATION JavaDoc exc) {
69             // Thrown when tie is an ObjectImpl and its delegate is not set.
70
tie.orb(orb);
71             } catch (BAD_INV_ORDER JavaDoc exc) {
72             // Thrown when tie is a Servant and its delegate is not set.
73
tie.orb(orb);
74             }
75
76             if (existingOrb != orb)
77             throw wrapper.connectTieWrongOrb() ;
78             
79             // Get the delegate for the stub from the tie.
80
del = StubAdapter.getDelegate( tie ) ;
81             ObjectImpl JavaDoc objref = new CORBAObjectImpl() ;
82             objref._set_delegate( del ) ;
83             ior = new StubIORImpl( objref ) ;
84         } else {
85             // ior is initialized, so convert ior to an object, extract
86
// the delegate, and set it on ourself
87
del = ior.getDelegate( orb ) ;
88         }
89
90         StubAdapter.setDelegate( stub, del ) ;
91         }
92     } catch (SystemException JavaDoc exc) {
93         throw new RemoteException JavaDoc("CORBA SystemException", exc );
94     }
95
96     return ior ;
97     }
98 }
99
Popular Tags