KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > dist > corba > CORBARemoteRef


1 /*
2   Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
3   Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
4
5   JAC-Core is free software. You can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation.
8   
9   JAC-Core is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13   This work uses the Javassist system - Copyright (c) 1999-2000
14   Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */

15
16 package org.objectweb.jac.core.dist.corba;
17
18 import org.objectweb.jac.core.dist.RemoteContainer;
19 import org.objectweb.jac.core.dist.RemoteRef;
20
21 import org.omg.CORBA.ORB JavaDoc;
22 import org.omg.CosNaming.NameComponent JavaDoc;
23 import org.omg.CosNaming.NamingContext JavaDoc;
24 import org.omg.CosNaming.NamingContextHelper JavaDoc;
25 import org.omg.PortableServer.POA JavaDoc;
26 import org.omg.PortableServer.POAHelper JavaDoc;
27
28
29 /**
30  * CORBARemoteRef stores the reference of a remote object
31  * that can be accessed by the CORBA/IIOP protocol.
32  *
33  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
34  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
35  */

36  
37 public class CORBARemoteRef extends RemoteRef {
38
39    /**
40     * The string used to identify the type of objects registered
41     * in the COS Naming.
42     */

43    
44    final static protected String JavaDoc cosNamingEntryType = "jac daemon";
45    
46    
47    /** This is the container CORBA remote reference stringified. */
48    protected String JavaDoc remContString;
49    
50
51    /**
52     * This method sets the reference of the remote CORBA container
53     * starting from a logical name registered in the COS Naming.
54     *
55     * @param contName the name of the container
56     * @return the container reference
57     */

58    
59    public void resolve( String JavaDoc contName ) {
60    
61       org.omg.CORBA.Object JavaDoc obj = null;
62       
63       /** This is a logical name registered in the COS Naming */
64
65       try {
66          obj =
67         nc.resolve(
68            new NameComponent JavaDoc[]{
69               new NameComponent JavaDoc( contName, cosNamingEntryType )
70            }
71         );
72       }
73       catch( Exception JavaDoc e ) { e.printStackTrace(); }
74
75       CORBARemoteContainerInterf stub =
76          CORBARemoteContainerInterfHelper.narrow(obj);
77       remContString = orb.object_to_string(obj);
78       remCont = new CORBARemoteContainerStub(stub);
79       
80       remCont.setName ( contName );
81       
82    }
83    
84    
85    /**
86     * This method re-gets the reference of a remote container.
87     * CORBA do not linearalize remote references in a standard way.
88     * Thus a remote reference may need to be adapted whenever it is transmitted.
89     *
90     * This method is called when a remote reference
91     * is received by a RemoteContainer.
92     */

93    
94    public void reresolve() {
95
96       org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(remContString);
97       CORBARemoteContainerInterf stub =
98          CORBARemoteContainerInterfHelper.narrow(obj);
99       remCont = new CORBARemoteContainerStub(stub);
100    }
101    
102
103
104    /** The CORBA ORB. */
105    static protected ORB JavaDoc orb;
106    
107    /** The CORBA root POA. */
108    static protected POA JavaDoc poa;
109    
110    /** The root naming context of the COSNaming. */
111    static protected NamingContext JavaDoc nc;
112
113    
114    static {
115    
116       orb = ORB.init( new String JavaDoc[]{}, null );
117       
118       try {
119          poa = POAHelper.narrow( orb.resolve_initial_references("RootPOA") );
120          nc =
121         NamingContextHelper.narrow(
122            orb.resolve_initial_references("NameService")
123         );
124       }
125       catch( Exception JavaDoc e ) { e.printStackTrace(); }
126    }
127    
128 }
129
Popular Tags