KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > runtime > INSRegistrationSchemeImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@objectweb.org
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Lesser General Public
9
// License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or any later version.
11
//
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
// Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public
18
// License along with this library; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
// USA
21
//
22
// Initial developer(s): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.corba.runtime;
31
32 /**
33  ** <p>Default implementation of the <tt>INSRegistrationScheme</tt> scheme.</p>
34  **
35  ** @see org.objectweb.corba.runtime.RegistrationServiceImpl RegistrationServiceImpl
36  **/

37 public class INSRegistrationSchemeImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements INSRegistrationScheme
40 {
41     // scheme
42
static final private String JavaDoc _class_name = "INSRegistrationSchemeImpl";
43     static final private String JavaDoc _scheme_id = INSRegistrationScheme.SCHEME_ID;
44
45     // default constructor
46
protected
47     INSRegistrationSchemeImpl()
48     {
49     }
50
51     //
52
// entry point
53
//
54

55     static public RegistrationScheme
56     create_scheme()
57     {
58         return new INSRegistrationSchemeImpl();
59     }
60
61     //
62
// IDL:objectweb.org/corba/runtime/RegistrationScheme:1.0
63
//
64

65     final public String JavaDoc
66     scheme_id()
67     {
68         return _scheme_id;
69     }
70
71     //
72
// IDL:objectweb.org/corba/runtime/INSRegistrationScheme:1.0
73
//
74

75     final public void
76     bind(String JavaDoc name, org.omg.CORBA.Object JavaDoc ref, ORBService orbs)
77     {
78         // obtain NS
79
org.omg.CORBA.Object JavaDoc obj = orbs.resolve_initial_references("NameService");
80
81         // check if NS is available
82
if (obj==null) {
83             final String JavaDoc opname = "bind";
84             final String JavaDoc msg = "IGNORE (no NS)";
85             TheLogger.debug(_class_name, opname, msg);
86             return ;
87         }
88
89         bind_in_ns(name, ref, obj);
90     }
91
92     final public void
93     bind_in_ns(String JavaDoc name, org.omg.CORBA.Object JavaDoc ref, org.omg.CORBA.Object JavaDoc obj)
94     {
95         final String JavaDoc opname = "bind_in_ns";
96
97         org.omg.CosNaming.NamingContext JavaDoc ns = null;
98         try {
99             ns = org.omg.CosNaming.NamingContextHelper.narrow(obj);
100         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
101             final String JavaDoc msg = "IGNORE (not a NS)";
102             TheLogger.debug(_class_name, opname, msg, ex);
103             return ;
104         }
105
106         // use name as INS name
107
String JavaDoc insname = name;
108
109         // bind
110
org.omg.CosNaming.NameComponent JavaDoc[] ncomp = new org.omg.CosNaming.NameComponent JavaDoc[1];
111         ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(insname, "");
112         try {
113             ns.rebind(ncomp, ref);
114         } catch (Exception JavaDoc ex) {
115             final String JavaDoc msg = "IGNORE (INS name: "+insname+")";
116             TheLogger.debug(_class_name, opname, msg, ex);
117             return ;
118         }
119     }
120
121     final public void
122     unbind(String JavaDoc name, ORBService orbs)
123     {
124         // obtain NS
125
org.omg.CORBA.Object JavaDoc obj = orbs.resolve_initial_references("NameService");
126
127         // check if NS is available
128
if (obj==null) {
129             final String JavaDoc opname = "unbind";
130             final String JavaDoc msg = "IGNORE (no NS)";
131             TheLogger.debug(_class_name, opname, msg);
132             return ;
133         }
134
135         unbind_in_ns(name, obj);
136     }
137
138     final public void
139     unbind_in_ns(String JavaDoc name, org.omg.CORBA.Object JavaDoc obj)
140     {
141         final String JavaDoc opname = "unbind_in_ns";
142
143         org.omg.CosNaming.NamingContext JavaDoc ns = null;
144         try {
145             ns = org.omg.CosNaming.NamingContextHelper.narrow(obj);
146         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
147             // ignore
148
final String JavaDoc msg = "IGNORE (not a NS)";
149             TheLogger.debug(_class_name, opname, msg, ex);
150             return ;
151         }
152
153         // use name as INS name
154
String JavaDoc insname = name;
155
156         // unbind
157
org.omg.CosNaming.NameComponent JavaDoc[] ncomp = new org.omg.CosNaming.NameComponent JavaDoc[1];
158         ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(insname, "");
159         try {
160             ns.unbind(ncomp);
161         } catch (Exception JavaDoc ex) {
162             // ignore
163
final String JavaDoc msg = "IGNORE (INS name: "+insname+")";
164             TheLogger.debug(_class_name, opname, msg, ex);
165             return ;
166         }
167     }
168
169     public org.omg.CORBA.Object JavaDoc
170     lookup(String JavaDoc name, ORBService orbs)
171     {
172         // obtain NS
173
org.omg.CORBA.Object JavaDoc obj = orbs.resolve_initial_references("NameService");
174
175         // check if NS is available
176
if (obj==null) {
177             // ignore
178
final String JavaDoc opname = "lookup";
179             final String JavaDoc msg = "FAILED (no NS)";
180             TheLogger.error(_class_name, opname, msg);
181             return null;
182         }
183
184         return lookup_in_ns(name, obj);
185     }
186
187     public org.omg.CORBA.Object JavaDoc
188     lookup_in_ns(String JavaDoc name, org.omg.CORBA.Object JavaDoc obj)
189     {
190         final String JavaDoc opname = "lookup_in_ns";
191
192         org.omg.CosNaming.NamingContext JavaDoc ns = null;
193         try {
194             ns = org.omg.CosNaming.NamingContextHelper.narrow(obj);
195         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
196             final String JavaDoc msg = "FAILED (not a NS)";
197             TheLogger.error(_class_name, opname, msg, ex);
198             return null;
199         }
200
201         // use name as INS name
202
String JavaDoc insname = name;
203
204         // lookup
205
org.omg.CosNaming.NameComponent JavaDoc[] ncomp = new org.omg.CosNaming.NameComponent JavaDoc[1];
206         ncomp[0] = new org.omg.CosNaming.NameComponent JavaDoc(insname, "");
207         org.omg.CORBA.Object JavaDoc res = null;
208         try {
209             res = ns.resolve(ncomp);
210         } catch (Exception JavaDoc ex) {
211             final String JavaDoc msg = "FAILED (INS name: "+insname+")";
212             TheLogger.error(_class_name, opname, msg, ex);
213             return null;
214         }
215
216         return res;
217     }
218 }
219
Popular Tags