1 /* _NamingContextImplBase.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package org
.omg
.CosNaming
;
41 import gnu
.CORBA
.Minor
;
43 import org
.omg
.CORBA
.BAD_OPERATION
;
44 import org
.omg
.CORBA
.CompletionStatus
;
45 import org
.omg
.CORBA
.DynamicImplementation
;
46 import org
.omg
.CORBA
.ObjectHelper
;
47 import org
.omg
.CORBA
.ObjectHolder
;
48 import org
.omg
.CORBA
.ServerRequest
;
49 import org
.omg
.CORBA
.portable
.InputStream
;
50 import org
.omg
.CORBA
.portable
.InvokeHandler
;
51 import org
.omg
.CORBA
.portable
.OutputStream
;
52 import org
.omg
.CORBA
.portable
.ResponseHandler
;
53 import org
.omg
.CORBA
.portable
.Streamable
;
54 import org
.omg
.CosNaming
.NamingContextPackage
.AlreadyBound
;
55 import org
.omg
.CosNaming
.NamingContextPackage
.AlreadyBoundHelper
;
56 import org
.omg
.CosNaming
.NamingContextPackage
.CannotProceed
;
57 import org
.omg
.CosNaming
.NamingContextPackage
.CannotProceedHelper
;
58 import org
.omg
.CosNaming
.NamingContextPackage
.InvalidName
;
59 import org
.omg
.CosNaming
.NamingContextPackage
.InvalidNameHelper
;
60 import org
.omg
.CosNaming
.NamingContextPackage
.NotEmpty
;
61 import org
.omg
.CosNaming
.NamingContextPackage
.NotEmptyHelper
;
62 import org
.omg
.CosNaming
.NamingContextPackage
.NotFound
;
63 import org
.omg
.CosNaming
.NamingContextPackage
.NotFoundHelper
;
65 import java
.util
.Hashtable
;
68 * The naming context implementation base.
70 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
72 public abstract class _NamingContextImplBase
73 extends DynamicImplementation
74 implements NamingContext
, InvokeHandler
77 * Use serialVersionUID (v1.4) for interoperability.
79 private static final long serialVersionUID
= -114280294134561035L;
82 * As there are quite many methods, it may be sensible to use the hashtable.
83 * This field is also reused in NamingContextPOA.
85 static Hashtable methods
= new Hashtable();
88 * Put all methods into the table.
92 methods
.put("bind", new Integer(0));
93 methods
.put("rebind", new Integer(1));
94 methods
.put("bind_context", new Integer(2));
95 methods
.put("rebind_context", new Integer(3));
96 methods
.put("resolve", new Integer(4));
97 methods
.put("unbind", new Integer(5));
98 methods
.put("new_context", new Integer(6));
99 methods
.put("bind_new_context", new Integer(7));
100 methods
.put("destroy", new Integer(8));
101 methods
.put("list", new Integer(9));
105 * Return the array of repository ids.
107 public String
[] _ids()
109 return new String
[] { NamingContextHelper
.id() };
113 * The server calls this method after receiving the request message
114 * from client. The implementation base calls one of its abstract
115 * methods to perform the requested operation.
117 * @param method the method being invoked.
118 * @param in the stream to read parameters from.
119 * @param rh the handler to get a stream for writing a response.
121 * @return the stream, returned by the handler.
123 public OutputStream
_invoke(String method
, InputStream in
, ResponseHandler rh
)
125 OutputStream out
= null;
126 Integer call_method
= (Integer
) methods
.get(method
);
127 if (call_method
== null)
128 throw new BAD_OPERATION(Minor
.Method
, CompletionStatus
.COMPLETED_MAYBE
);
130 switch (call_method
.intValue())
136 NameComponent
[] a_name
= NameHelper
.read(in
);
137 org
.omg
.CORBA
.Object an_object
= ObjectHelper
.read(in
);
138 bind(a_name
, an_object
);
139 out
= rh
.createReply();
143 out
= rh
.createExceptionReply();
144 NotFoundHelper
.write(out
, ex
);
146 catch (CannotProceed ex
)
148 out
= rh
.createExceptionReply();
149 CannotProceedHelper
.write(out
, ex
);
151 catch (InvalidName ex
)
153 out
= rh
.createExceptionReply();
154 InvalidNameHelper
.write(out
, ex
);
156 catch (AlreadyBound ex
)
158 out
= rh
.createExceptionReply();
159 AlreadyBoundHelper
.write(out
, ex
);
168 NameComponent
[] a_name
= NameHelper
.read(in
);
169 org
.omg
.CORBA
.Object an_object
= ObjectHelper
.read(in
);
170 rebind(a_name
, an_object
);
171 out
= rh
.createReply();
175 out
= rh
.createExceptionReply();
176 NotFoundHelper
.write(out
, ex
);
178 catch (CannotProceed ex
)
180 out
= rh
.createExceptionReply();
181 CannotProceedHelper
.write(out
, ex
);
183 catch (InvalidName ex
)
185 out
= rh
.createExceptionReply();
186 InvalidNameHelper
.write(out
, ex
);
191 case 2 : // bind_context
195 NameComponent
[] a_name
= NameHelper
.read(in
);
196 NamingContext a_context
= NamingContextHelper
.read(in
);
197 bind_context(a_name
, a_context
);
198 out
= rh
.createReply();
202 out
= rh
.createExceptionReply();
203 NotFoundHelper
.write(out
, ex
);
205 catch (CannotProceed ex
)
207 out
= rh
.createExceptionReply();
208 CannotProceedHelper
.write(out
, ex
);
210 catch (InvalidName ex
)
212 out
= rh
.createExceptionReply();
213 InvalidNameHelper
.write(out
, ex
);
215 catch (AlreadyBound ex
)
217 out
= rh
.createExceptionReply();
218 AlreadyBoundHelper
.write(out
, ex
);
223 case 3 : // rebind_context
227 NameComponent
[] a_name
= NameHelper
.read(in
);
228 NamingContext a_context
= NamingContextHelper
.read(in
);
229 rebind_context(a_name
, a_context
);
230 out
= rh
.createReply();
234 out
= rh
.createExceptionReply();
235 NotFoundHelper
.write(out
, ex
);
237 catch (CannotProceed ex
)
239 out
= rh
.createExceptionReply();
240 CannotProceedHelper
.write(out
, ex
);
242 catch (InvalidName ex
)
244 out
= rh
.createExceptionReply();
245 InvalidNameHelper
.write(out
, ex
);
254 NameComponent
[] a_name
= NameHelper
.read(in
);
255 org
.omg
.CORBA
.Object __result
= null;
256 __result
= resolve(a_name
);
257 out
= rh
.createReply();
258 ObjectHelper
.write(out
, __result
);
262 out
= rh
.createExceptionReply();
263 NotFoundHelper
.write(out
, ex
);
265 catch (CannotProceed ex
)
267 out
= rh
.createExceptionReply();
268 CannotProceedHelper
.write(out
, ex
);
270 catch (InvalidName ex
)
272 out
= rh
.createExceptionReply();
273 InvalidNameHelper
.write(out
, ex
);
282 NameComponent
[] a_name
= NameHelper
.read(in
);
284 out
= rh
.createReply();
288 out
= rh
.createExceptionReply();
289 NotFoundHelper
.write(out
, ex
);
291 catch (CannotProceed ex
)
293 out
= rh
.createExceptionReply();
294 CannotProceedHelper
.write(out
, ex
);
296 catch (InvalidName ex
)
298 out
= rh
.createExceptionReply();
299 InvalidNameHelper
.write(out
, ex
);
304 case 6 : // new_context
306 NamingContext __result
= null;
307 __result
= new_context();
308 out
= rh
.createReply();
309 NamingContextHelper
.write(out
, __result
);
313 case 7 : // bind_new_context
317 NameComponent
[] a_name
= NameHelper
.read(in
);
318 NamingContext __result
= null;
319 __result
= bind_new_context(a_name
);
320 out
= rh
.createReply();
321 NamingContextHelper
.write(out
, __result
);
325 out
= rh
.createExceptionReply();
326 NotFoundHelper
.write(out
, ex
);
328 catch (AlreadyBound ex
)
330 out
= rh
.createExceptionReply();
331 AlreadyBoundHelper
.write(out
, ex
);
333 catch (CannotProceed ex
)
335 out
= rh
.createExceptionReply();
336 CannotProceedHelper
.write(out
, ex
);
338 catch (InvalidName ex
)
340 out
= rh
.createExceptionReply();
341 InvalidNameHelper
.write(out
, ex
);
351 out
= rh
.createReply();
355 out
= rh
.createExceptionReply();
356 NotEmptyHelper
.write(out
, ex
);
363 int amount
= in
.read_ulong();
364 BindingListHolder a_list
= new BindingListHolder();
365 BindingIteratorHolder an_iter
= new BindingIteratorHolder();
366 list(amount
, a_list
, an_iter
);
367 out
= rh
.createReply();
368 BindingListHelper
.write(out
, a_list
.value
);
369 BindingIteratorHelper
.write(out
, an_iter
.value
);
374 throw new BAD_OPERATION(0, CompletionStatus
.COMPLETED_MAYBE
);
381 * The obsolete invocation using server request. Implemented for
382 * compatibility reasons, but is it more effectinve to use
385 * @param request a server request.
387 public void invoke(ServerRequest request
)
389 Streamable result
= null;
391 // The server request contains no required result type.
392 Integer call_method
= (Integer
) methods
.get(request
.operation());
393 if (call_method
== null)
394 throw new BAD_OPERATION(Minor
.Method
, CompletionStatus
.COMPLETED_MAYBE
);
396 switch (call_method
.intValue())
398 case 4 : // resolve, object
399 result
= new ObjectHolder();
402 case 6 : // new_context, NamingContext
403 case 7 : // bind_new_context, NamingContext
405 result
= new NamingContextHolder();
409 default : // void for others.
413 gnu
.CORBA
.ServiceRequestAdapter
.invoke(request
, this, result
);