KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > pcosnaming > NamingContextImpl


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

7 /*
8  * @(#)NamingContextImpl.java 1.4 00/02/07
9  *
10  * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
11  * Palo Alto, California, 94303, U.S.A. All Rights Reserved.
12  *
13  * This software is the confidential and proprietary information of Sun
14  * Microsystems, Inc. ("Confidential Information"). You shall not
15  * disclose such Confidential Information and shall use it only in
16  * accordance with the terms of the license agreement you entered into
17  * with Sun.
18  *
19  * CopyrightVersion 1.2
20  *
21  */

22
23 package com.sun.corba.se.impl.naming.pcosnaming;
24
25
26 import org.omg.CORBA.Object JavaDoc;
27 import org.omg.CORBA.SystemException JavaDoc;
28 import org.omg.CORBA.BAD_PARAM JavaDoc;
29 import org.omg.CORBA.CompletionStatus JavaDoc;
30 import org.omg.CORBA.Policy JavaDoc;
31 import org.omg.PortableServer.POA JavaDoc;
32 import org.omg.PortableServer.LifespanPolicyValue JavaDoc;
33 import org.omg.PortableServer.RequestProcessingPolicyValue JavaDoc;
34 import org.omg.PortableServer.IdAssignmentPolicyValue JavaDoc;
35 import org.omg.PortableServer.ServantRetentionPolicyValue JavaDoc;
36
37 import org.omg.CosNaming.*;
38 import org.omg.CosNaming.NamingContextPackage.*;
39 import org.omg.CosNaming.NamingContextExtPackage.*;
40
41 import com.sun.corba.se.impl.naming.cosnaming.NamingContextDataStore;
42 import com.sun.corba.se.impl.naming.cosnaming.NamingUtils;
43
44 import com.sun.corba.se.impl.naming.namingutil.INSURLHandler;
45
46 import com.sun.corba.se.spi.orb.ORB;
47 import com.sun.corba.se.spi.logging.CORBALogDomains;
48
49 import com.sun.corba.se.impl.orbutil.ORBConstants;
50 import com.sun.corba.se.impl.logging.NamingSystemException;
51
52 import java.io.Serializable JavaDoc;
53 import java.util.Hashtable JavaDoc;
54
55 /**
56  * Class NamingContextImpl implements the org.omg.CosNaming::NamingContext and
57  * NamingContextExt interface.
58  * <p>
59  * The operations bind(), rebind(), bind_context() and rebind_context()
60  * are all really implemented by doBind(). resolve() is really implemented
61  * by doResolve(), unbind() by doUnbind(). list(), new_context() and
62  * destroy() uses the NamingContextDataStore interface directly. All the
63  * doX() methods are public static.
64  * They synchronize on the NamingContextDataStore object.
65  * <p>
66  * None of the methods here are Synchronized because These methods will be
67  * invoked from Super class's doBind( ), doResolve( ) which are already
68  * Synchronized.
69  */

70
71
72 public class NamingContextImpl
73     extends NamingContextExtPOA
74     implements NamingContextDataStore, Serializable JavaDoc
75 {
76
77     // The ORB is required to do string_to_object() operations
78
// All the references are stored in the files in the form of IOR strings
79
private transient ORB orb;
80
81     // The ObjectKey will be in the format NC<Index> which uniquely identifies
82
// The NamingContext internaly
83
private final String JavaDoc objKey;
84
85     // Hash table contains all the entries in the NamingContexts. The
86
// CORBA.Object references will be stored in the form of IOR strings
87
// and the Child Naming Contexts will have it's key as the entry in the
88
// table. This table is written into File everytime an update is made
89
// on this context.
90
private final Hashtable JavaDoc theHashtable = new Hashtable JavaDoc( );
91
92     // The NameServiceHandle is required to get the ObjectId from the
93
// NamingContext's references. These references are created using
94
// POA in the NameService.
95
private transient NameService theNameServiceHandle;
96
97     // ServantManager is the single point of contact to Read, Write and
98
// Update the NamingContextFile
99
private transient ServantManagerImpl theServantManagerImplHandle;
100
101     // All the INS (Interoperable Naming Service) methods are defined in this class
102
// All the calls to INS will be delegated to this class.
103
private transient com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl insImpl;
104
105     private transient NamingSystemException readWrapper ;
106
107     private transient NamingSystemException updateWrapper ;
108
109     private static POA JavaDoc biPOA = null;
110
111     /**
112      * Create a naming context servant.
113      * Runs the super constructor.
114      * @param orb an ORB object.
115      * @param objKey as String
116      * @param TheNameService as NameService
117      * @param TheServantManagerImpl as ServantManagerImpl
118      * @exception java.lang.Exception a Java exception.
119      */

120
121     public NamingContextImpl(ORB orb, String JavaDoc objKey,
122         NameService theNameService, ServantManagerImpl theServantManagerImpl )
123     throws Exception JavaDoc
124     {
125     super();
126
127     this.orb = orb;
128     readWrapper = NamingSystemException.get( orb,
129         CORBALogDomains.NAMING_READ ) ;
130     updateWrapper = NamingSystemException.get( orb,
131         CORBALogDomains.NAMING_UPDATE ) ;
132
133     debug = true ; // orb.namingDebugFlag ;
134
this.objKey = objKey;
135     theNameServiceHandle = theNameService;
136     theServantManagerImplHandle = theServantManagerImpl;
137     insImpl =
138             new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
139     }
140
141     com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl getINSImpl( )
142     {
143     if( insImpl == null )
144     {
145             // insImpl will be null if the NamingContext graph is rebuilt from
146
// the persistence store.
147
insImpl =
148                 new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
149     }
150     return insImpl;
151     }
152
153
154     public void setRootNameService( NameService theNameService ) {
155     theNameServiceHandle = theNameService;
156     }
157
158     public void setORB( ORB theOrb ) {
159     orb = theOrb;
160     }
161
162     public void setServantManagerImpl(
163         ServantManagerImpl theServantManagerImpl )
164     {
165     theServantManagerImplHandle = theServantManagerImpl;
166     }
167
168     public POA JavaDoc getNSPOA( ) {
169         return theNameServiceHandle.getNSPOA( );
170     }
171
172
173
174
175    /**
176    * Bind an object under a name in this NamingContext. If the name
177    * contains multiple (n) components, n-1 will be resolved in this
178    * NamingContext and the object bound in resulting NamingContext.
179    * An exception is thrown if a binding with the supplied name already
180    * exists. If the
181    * object to be bound is a NamingContext it will not participate in
182    * a recursive resolve.
183    * @param n a sequence of NameComponents which is the name under which
184    * the object will be bound.
185    * @param obj the object reference to be bound.
186    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
187    * components was supplied, but the first component could not be
188    * resolved.
189    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
190    * in resolving the n-1 components of the supplied name.
191    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
192    * is invalid (i.e., has length less than 1).
193    * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound The supplied name
194    * is already bound.
195    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
196    * @see doBind
197    */

198    public void bind(NameComponent[] n, org.omg.CORBA.Object JavaDoc obj)
199         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
200                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
201                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc,
202                org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc
203     {
204         if( obj == null ) {
205         throw updateWrapper.objectIsNull() ;
206         }
207
208         if (debug)
209             dprint("bind " + nameToString(n) + " to " + obj);
210         // doBind implements all four flavors of binding
211
NamingContextDataStore impl = (NamingContextDataStore)this;
212         doBind(impl,n,obj,false,BindingType.nobject);
213     }
214
215    /**
216    * Bind a NamingContext under a name in this NamingContext. If the name
217    * contains multiple (n) components, n-1 will be resolved in this
218    * NamingContext and the object bound in resulting NamingContext.
219    * An exception is thrown if a binding with the supplied name already
220    * exists. The NamingContext will participate in recursive resolving.
221    * @param n a sequence of NameComponents which is the name under which
222    * the object will be bound.
223    * @param obj the NamingContect object reference to be bound.
224    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
225    * components was supplied, but the first component could not be
226    * resolved.
227    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
228    * in resolving the n-1 components of the supplied name.
229    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
230    * is invalid (i.e., has length less than 1).
231    * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
232    * already bound under the supplied name.
233    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
234    * @see doBind
235    */

236    public void bind_context(NameComponent[] n, NamingContext nc)
237         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
238                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
239                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc,
240                org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc
241     {
242         if( nc == null ) {
243         throw updateWrapper.objectIsNull() ;
244         }
245         // doBind implements all four flavors of binding
246
NamingContextDataStore impl = (NamingContextDataStore)this;
247         doBind(impl,n,nc,false,BindingType.ncontext);
248     }
249
250  /**
251    * Bind an object under a name in this NamingContext. If the name
252    * contains multiple (n) components, n-1 will be resolved in this
253    * NamingContext and the object bound in resulting NamingContext.
254    * If a binding under the supplied name already exists it will be
255    * unbound first. If the
256    * object to be bound is a NamingContext it will not participate in
257    * a recursive resolve.
258    * @param n a sequence of NameComponents which is the name under which
259    * the object will be bound.
260    * @param obj the object reference to be bound.
261    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
262    * components was supplied, but the first component could not be
263    * resolved.
264    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
265    * in resolving the n-1 components of the supplied name.
266    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
267    * is invalid (i.e., has length less than 1).
268    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
269    * @see doBind
270    */

271    public void rebind(NameComponent[] n, org.omg.CORBA.Object JavaDoc obj)
272         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
273                      org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
274                      org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
275     {
276         if( obj == null )
277         {
278         throw updateWrapper.objectIsNull() ;
279         }
280         try {
281             if (debug)
282                 dprint("rebind " + nameToString(n) + " to " + obj);
283             // doBind implements all four flavors of binding
284
NamingContextDataStore impl = (NamingContextDataStore)this;
285             doBind(impl,n,obj,true,BindingType.nobject);
286         } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc ex) {
287             // This should not happen
288
throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
289         }
290     }
291
292    /**
293    * Bind a NamingContext under a name in this NamingContext. If the name
294    * contains multiple (n) components, the first n-1 components will be
295    * resolved in this
296    * NamingContext and the object bound in resulting NamingContext.
297    * If a binding under the supplied name already exists it will be
298    * unbound first. The NamingContext will participate in recursive resolving.
299    * @param n a sequence of NameComponents which is the name under which
300    * the object will be bound.
301    * @param obj the object reference to be bound.
302    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
303    * components was supplied, but the first component could not be
304    * resolved.
305    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
306    * in resolving the n-1 components of the supplied name.
307    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
308    * is invalid (i.e., has length less than 1).
309    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
310    * @see doBind
311    */

312    public void rebind_context(NameComponent[] n, NamingContext nc)
313         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
314                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
315                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
316     {
317         try {
318             if (debug)
319                 dprint("rebind_context " + nameToString(n) + " to " + nc);
320             // doBind implements all four flavors of binding
321
NamingContextDataStore impl = (NamingContextDataStore)this;
322             doBind(impl,n,nc,true,BindingType.ncontext);
323         } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc ex) {
324             // This should not happen
325
throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
326         }
327     }
328
329    /**
330    * Resolve a name in this NamingContext and return the object reference
331    * bound to the name. If the name contains multiple (n) components,
332    * the first component will be resolved in this NamingContext and the
333    * remaining components resolved in the resulting NamingContext, provided
334    * that the NamingContext bound to the first component of the name was
335    * bound with bind_context().
336    * @param n a sequence of NameComponents which is the name to be resolved.
337    * @return the object reference bound under the supplied name.
338    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
339    * components was supplied, but the first component could not be
340    * resolved.
341    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
342    * in resolving the n-1 components of the supplied name.
343    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
344    * is invalid (i.e., has length less than 1).
345    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
346    * @see doResolve
347    */

348    public org.omg.CORBA.Object JavaDoc resolve(NameComponent[] n)
349         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
350                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
351                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
352     {
353         if (debug)
354             dprint("resolve " + nameToString(n));
355         // doResolve actually resolves
356
NamingContextDataStore impl = (NamingContextDataStore)this;
357         return doResolve(impl,n);
358     }
359
360    /**
361    * Remove a binding from this NamingContext. If the name contains
362    * multiple (n) components, the first n-1 components will be resolved
363    * from this NamingContext and the final component unbound in
364    * the resulting NamingContext.
365    * @param n a sequence of NameComponents which is the name to be unbound.
366    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
367    * components was supplied, but the first component could not be
368    * resolved.
369    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
370    * in resolving the n-1 components of the supplied name.
371    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
372    * is invalid (i.e., has length less than 1).
373    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
374    * @see doUnbind
375    */

376    public void unbind(NameComponent[] n)
377         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
378                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
379                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
380     {
381         if (debug)
382             dprint("unbind " + nameToString(n));
383         // doUnbind actually unbinds
384
NamingContextDataStore impl = (NamingContextDataStore)this;
385         doUnbind(impl,n);
386     }
387
388    /**
389    * List the contents of this NamingContest. A sequence of bindings
390    * is returned (a BindingList) containing up to the number of requested
391    * bindings, and a BindingIterator object reference is returned for
392    * iterating over the remaining bindings.
393    * @param how_many The number of requested bindings in the BindingList.
394    * @param bl The BindingList as an out parameter.
395    * @param bi The BindingIterator as an out parameter.
396    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
397    * @see BindingListHolder
398    * @see BindingIteratorImpl
399    */

400     public void list(int how_many, BindingListHolder bl, BindingIteratorHolder bi)
401     {
402         if (debug)
403             dprint("list(" + how_many + ")");
404         // List actually generates the list
405
NamingContextDataStore impl = (NamingContextDataStore)this;
406         synchronized (impl) {
407             impl.List(how_many,bl,bi);
408         }
409         if (debug && bl.value != null)
410             dprint("list(" + how_many + ") -> bindings[" + bl.value.length +
411                    "] + iterator: " + bi.value);
412     }
413
414
415    /**
416    * Create a NamingContext object and return its object reference.
417    * @return an object reference for a new NamingContext object implemented
418    * by this Name Server.
419    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
420    */

421     public synchronized NamingContext new_context()
422     {
423         // Create actually creates a new naming context
424
if (debug)
425             dprint("new_context()");
426         NamingContextDataStore impl = (NamingContextDataStore)this;
427         synchronized (impl) {
428             return impl.NewContext();
429         }
430     }
431
432
433    /**
434    * Create a new NamingContext, bind it in this Naming Context and return
435    * its object reference. This is equivalent to using new_context() followed
436    * by bind_context() with the supplied name and the object reference for
437    * the newly created NamingContext.
438    * @param n a sequence of NameComponents which is the name to be unbound.
439    * @return an object reference for a new NamingContext object implemented
440    * by this Name Server, bound to the supplied name.
441    * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
442    * already bound under the supplied name.
443    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
444    * components was supplied, but the first component could not be
445    * resolved.
446    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
447    * in resolving the n-1 components of the supplied name.
448    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
449    * is invalid (i.e., has length less than 1).
450    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
451    * @see new_context
452    * @see bind_context
453    */

454     public NamingContext bind_new_context(NameComponent[] n)
455         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
456                org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc,
457                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
458                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
459     {
460         NamingContext nc = null;
461         NamingContext rnc = null;
462         try {
463             if (debug)
464                 dprint("bind_new_context " + nameToString(n));
465             // The obvious solution:
466
nc = this.new_context();
467             this.bind_context(n,nc);
468             rnc = nc;
469             nc = null;
470         } finally {
471             try {
472                 if(nc != null)
473                     nc.destroy();
474             } catch (org.omg.CosNaming.NamingContextPackage.NotEmpty JavaDoc e) {
475             }
476         }
477         return rnc;
478     }
479
480     /**
481    * Destroy this NamingContext object. If this NamingContext contains
482    * no bindings, the NamingContext is deleted.
483    * @exception org.omg.CosNaming.NamingContextPackage.NotEmpty This NamingContext
484    * is not empty (i.e., contains bindings).
485    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
486    */

487     public void destroy()
488         throws org.omg.CosNaming.NamingContextPackage.NotEmpty JavaDoc
489     {
490         if (debug)
491             dprint("destroy ");
492         NamingContextDataStore impl = (NamingContextDataStore)this;
493         synchronized (impl) {
494             if (impl.IsEmpty() == true)
495                 // The context is empty so it can be destroyed
496
impl.Destroy();
497             else
498                 // This context is not empty!
499
throw new org.omg.CosNaming.NamingContextPackage.NotEmpty JavaDoc();
500         }
501     }
502
503       /**
504    * Implements all four flavors of binding. It uses Resolve() to
505    * check if a binding already exists (for bind and bind_context), and
506    * unbind() to ensure that a binding does not already exist.
507    * If the length of the name is 1, then Bind() is called with
508    * the name and the object to bind. Otherwise, the first component
509    * of the name is resolved in this NamingContext and the appropriate
510    * form of bind passed to the resulting NamingContext.
511    * This method is static for maximal reuse - even for extended naming
512    * context implementations where the recursive semantics still apply.
513    * @param impl an implementation of NamingContextDataStore
514    * @param n a sequence of NameComponents which is the name under which
515    * the object will be bound.
516    * @param obj the object reference to be bound.
517    * @param rebind Replace an existing binding or not.
518    * @param bt Type of binding (as object or as context).
519    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
520    * components was supplied, but the first component could not be
521    * resolved.
522    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
523    * in resolving the first component of the supplied name.
524    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
525    * is invalid (i.e., has length less than 1).
526    * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
527    * already bound under the supplied name.
528    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
529    * @see resolve
530    * @see unbind
531    * @see bind
532    * @see bind_context
533    * @see rebind
534    * @see rebind_context
535    */

536     private void doBind(NamingContextDataStore impl,
537                               NameComponent[] n,
538                               org.omg.CORBA.Object JavaDoc obj,
539                               boolean rebind,
540                               org.omg.CosNaming.BindingType JavaDoc bt)
541         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
542                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
543                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc,
544                org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc
545     {
546         // Valid name?
547
if (n.length < 1)
548             throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
549
550     // At bottom level?
551
if (n.length == 1) {
552             // The identifier must be set
553
if( (n[0].id.length() == 0) && (n[0].kind.length() == 0) )
554                 throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
555
556             // Ensure synchronization of backend
557
synchronized (impl) {
558                 // Yes: bind object in this context under the name
559
BindingTypeHolder bth = new BindingTypeHolder();
560                 if (rebind) {
561                     org.omg.CORBA.Object JavaDoc objRef = impl.Resolve( n[0], bth );
562                     if( objRef != null ) {
563                         // Refer Naming Service Doc:00-11-01 section 2.2.3.4
564
// If there is an object already bound with the name
565
// and the binding type is not ncontext a NotFound
566
// Exception with a reason of not a context has to be
567
// raised.
568
// Fix for bug Id: 4384628
569
if ( bth.value.value() == BindingType.nobject.value() ) {
570                             if ( bt.value() == BindingType.ncontext.value() ) {
571                                 throw new NotFound(NotFoundReason.not_context, n);
572                             }
573                         } else {
574                             // Previously a Context was bound and now trying to
575
// bind Object. It is invalid.
576
if ( bt.value() == BindingType.nobject.value() ) {
577                                 throw new NotFound(NotFoundReason.not_object, n);
578                             }
579                         }
580                         impl.Unbind(n[0]);
581                     }
582                 } else {
583                     if (impl.Resolve(n[0],bth) != null)
584                         throw new org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc();
585                 }
586
587                 // Now there are no other bindings under this name
588
impl.Bind(n[0],obj,bt);
589             }
590         } else {
591             // No: bind in a different context
592
NamingContext context = resolveFirstAsContext(impl,n);
593
594             // Compute tail
595
NameComponent[] tail = new NameComponent[n.length - 1];
596             System.arraycopy(n,1,tail,0,n.length-1);
597             
598       // How should we propagate the bind
599
switch (bt.value()) {
600             case BindingType._nobject:
601                 {
602                     // Bind as object
603
if (rebind)
604                         context.rebind(tail,obj);
605                     else
606                         context.bind(tail,obj);
607                 }
608                 break;
609             case BindingType._ncontext:
610                 {
611                     // Narrow to a naming context using Java casts. It must work.
612
NamingContext objContext = (NamingContext)obj;
613                     // Bind as context
614
if (rebind)
615                         context.rebind_context(tail,objContext);
616                     else
617                         context.bind_context(tail,objContext);
618                 }
619                 break;
620             default:
621                 // This should not happen
622
throw updateWrapper.namingCtxBadBindingtype() ;
623             }
624         }
625     }
626
627
628    /**
629    * Implements resolving names in this NamingContext. The first component
630    * of the supplied name is resolved in this NamingContext by calling
631    * Resolve(). If there are no more components in the name, the
632    * resulting object reference is returned. Otherwise, the resulting object
633    * reference must have been bound as a context and be narrowable to
634    * a NamingContext. If this is the case, the remaining
635    * components of the name is resolved in the resulting NamingContext.
636    * This method is static for maximal reuse - even for extended naming
637    * context implementations where the recursive semantics still apply.
638    * @param impl an implementation of NamingContextDataStore
639    * @param n a sequence of NameComponents which is the name to be resolved.
640    * @return the object reference bound under the supplied name.
641    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
642    * components was supplied, but the first component could not be
643    * resolved.
644    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
645    * in resolving the first component of the supplied name.
646    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
647    * is invalid (i.e., has length less than 1).
648    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
649    * @see resolve
650    */

651     public static org.omg.CORBA.Object JavaDoc doResolve(NamingContextDataStore impl,
652                                                  NameComponent[] n)
653         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
654                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
655                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
656     {
657         org.omg.CORBA.Object JavaDoc obj = null;
658         BindingTypeHolder bth = new BindingTypeHolder();
659
660         // Length must be greater than 0
661
if (n.length < 1)
662             throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
663
664         // The identifier must be set
665
if (n.length == 1) {
666             synchronized (impl) {
667                 // Resolve first level in this context
668
obj = impl.Resolve(n[0],bth);
669             }
670             if (obj == null) {
671                 // Object was not found
672
throw new org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc(NotFoundReason.missing_node,n);
673             }
674             return obj;
675         } else {
676             // n.length > 1
677
if ( (n[1].id.length() == 0) && (n[1].kind.length() == 0 ) )
678                 throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
679
680             NamingContext context = resolveFirstAsContext(impl,n);
681
682             // Compute restOfName = name[1..length]
683
NameComponent[] tail = new NameComponent[n.length -1];
684             System.arraycopy(n,1,tail,0,n.length-1);
685
686             // Resolve rest of name in context
687
return context.resolve(tail);
688         }
689     }
690
691     /**
692    * Implements unbinding bound names in this NamingContext. If the
693    * name contains only one component, the name is unbound in this
694    * NamingContext using Unbind(). Otherwise, the first component
695    * of the name is resolved in this NamingContext and
696    * unbind passed to the resulting NamingContext.
697    * This method is static for maximal reuse - even for extended naming
698    * context implementations where the recursive semantics still apply.
699    * @param impl an implementation of NamingContextDataStore
700    * @param n a sequence of NameComponents which is the name to be unbound.
701    * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
702    * components was supplied, but the first component could not be
703    * resolved.
704    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
705    * in resolving the n-1 components of the supplied name.
706    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
707    * is invalid (i.e., has length less than 1).
708    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
709    * @see resolve
710    */

711     public static void doUnbind(NamingContextDataStore impl,
712                                 NameComponent[] n)
713         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
714                org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
715                org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
716     {
717     // Name valid?
718
if (n.length < 1)
719             throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
720
721         // Unbind here?
722
if (n.length == 1) {
723             // The identifier must be set
724
if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) )
725                 throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
726
727             org.omg.CORBA.Object JavaDoc objRef = null;
728             synchronized (impl) {
729                 // Yes: unbind in this context
730
objRef = impl.Unbind(n[0]);
731             }
732
733             if (objRef == null)
734                 // It was not bound
735
throw new org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc(NotFoundReason.missing_node,n);
736             // Done
737
return;
738         } else {
739             // No: unbind in a different context
740

741       // Resolve first - must be resolveable
742
NamingContext context = resolveFirstAsContext(impl,n);
743         
744             // Compute tail
745
NameComponent[] tail = new NameComponent[n.length - 1];
746             System.arraycopy(n,1,tail,0,n.length-1);
747
748       // Propagate unbind to this context
749
context.unbind(tail);
750         }
751     }
752
753      /**
754    * Implements resolving a NameComponent in this context and
755    * narrowing it to CosNaming::NamingContext. It will throw appropriate
756    * exceptions if not found or not narrowable.
757    * @param impl an implementation of NamingContextDataStore
758    * @param n a NameComponents which is the name to be found.
759    * @exception org.omg.CosNaming.NamingContextPackage.NotFound The
760    * first component could not be resolved.
761    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
762    * in resolving the first component of the supplied name.
763    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
764    * @see resolve
765    */

766     protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl,
767                                                          NameComponent[] n)
768         throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc {
769         org.omg.CORBA.Object JavaDoc topRef = null;
770         BindingTypeHolder bth = new BindingTypeHolder();
771         NamingContext context = null;
772
773         synchronized (impl) {
774             // Resolve first - must be resolveable
775
topRef = impl.Resolve(n[0],bth);
776             if (topRef == null) {
777         // It was not bound
778
throw new org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc(NotFoundReason.missing_node,n);
779             }
780         }
781
782         // Was it bound as a context?
783
if (bth.value != BindingType.ncontext) {
784             // It was not a context
785
throw new org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc(NotFoundReason.not_context,n);
786         }
787
788         // Narrow to a naming context
789
try {
790             context = NamingContextHelper.narrow(topRef);
791         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
792             // It was not a context
793
throw new org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc(NotFoundReason.not_context,n);
794         }
795
796         // Hmm. must be ok
797
return context;
798     }
799
800     public static String JavaDoc nameToString(NameComponent[] name)
801     {
802         StringBuffer JavaDoc s = new StringBuffer JavaDoc("{");
803         if (name != null || name.length > 0) {
804             for (int i=0;i<name.length;i++) {
805                 if (i>0)
806                     s.append(",");
807                 s.append("[").
808                     append(name[i].id).
809                     append(",").
810                     append(name[i].kind).
811                     append("]");
812             }
813         }
814         s.append("}");
815         return s.toString();
816     }
817
818     // Debugging aids.
819
private static boolean debug ;
820
821     private static void dprint(String JavaDoc msg) {
822         NamingUtils.dprint("NamingContextImpl(" +
823                            Thread.currentThread().getName() + " at " +
824                            System.currentTimeMillis() +
825                            " ems): " + msg);
826     }
827
828
829     /**
830     * Implements all flavors of binding( bind and bindcontext)
831     * This method will be called from the superclass's doBind( ) method
832     * which takes care of all the conditions before calling this method.
833     * i.e., It checks whether the Name is already Bounded, Then in the
834     * case of rebind it calls Unbind first.
835     * This method does one level binding only, To have n-level binding
836     * with compound names, doBind( ) calls this method recursively.
837     * @param n a sequence of NameComponents which is the name under which
838     * the object will be bound.
839     * @param obj the object reference to be bound.
840     * @param bt Type of binding (as object or as context).
841     * @exception org.omg.CosNaming.NamingContextPackage.NotFound raised
842     * if the NameComoponent list is invalid
843     * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
844     * Could not proceed in resolving the Name from the given NameComponent
845     * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object
846     * is already bound under the supplied name.
847     * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
848     * system exceptions
849     * @see Resolve
850     * @see Unbind
851     */

852     public void Bind(NameComponent n, org.omg.CORBA.Object JavaDoc obj, BindingType bt)
853     {
854     if( obj == null ) {
855         // Raise a Valid Exception and Return
856
return;
857     }
858
859     InternalBindingKey key = new InternalBindingKey(n);
860     InternalBindingValue value;
861
862     try {
863         if( bt.value() == BindingType._nobject ) {
864         // If the BindingType is an ObjectRef then Stringify this ref and
865
// Store it in InternalBindingValue instance. This is required
866
// because the Object References has to be stored in file
867
value = new InternalBindingValue(bt, orb.object_to_string(obj) );
868         value.setObjectRef( obj );
869         } else {
870         // If the BindingType is a NamingContext then get it's object key
871
// from the NameService and store it in the Internal Binding Value instance
872
String JavaDoc theNCKey = theNameServiceHandle.getObjectKey( obj );
873         value = new InternalBindingValue( bt, theNCKey );
874         value.setObjectRef( obj );
875         }
876
877         InternalBindingValue oldValue =
878         (InternalBindingValue)this.theHashtable.put(key,value);
879
880         if( oldValue != null) {
881         // There was an entry with this name in the Hashtable and hence throw CTX_ALREADY_BOUND
882
// exception
883
throw updateWrapper.namingCtxRebindAlreadyBound() ;
884         } else {
885         try {
886             // Everything went smooth so update the NamingContext file with the
887
// latest Hashtable image
888
theServantManagerImplHandle.updateContext( objKey, this );
889         } catch( Exception JavaDoc e ) {
890             // Something went wrong while updating the context
891
// so speak the error
892
throw updateWrapper.bindUpdateContextFailed( e ) ;
893         }
894         }
895     } catch( Exception JavaDoc e ) {
896         // Something went wrong while Binding the Object Reference
897
// Speak the error again.
898
throw updateWrapper.bindFailure( e ) ;
899     }
900     }
901
902     /**
903     * This method resolves the NamingContext or Object Reference for one level
904     * The doResolve( ) method calls Resolve( ) recursively to resolve n level
905     * Names.
906     * @param n a sequence of NameComponents which is the name to be resolved.
907     * @param bt Type of binding (as object or as context).
908     * @return the object reference bound under the supplied name.
909     * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
910     * or a Corba Object reference not found under this Name
911     * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
912     * in resolving the the supplied name.
913     * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
914     * is invalid (i.e., has length less than 1).
915     * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
916     * @see Bind
917     */

918     public Object JavaDoc Resolve(NameComponent n, BindingTypeHolder bth)
919     throws SystemException JavaDoc
920     {
921     if( ( n.id.length() == 0 ) &&( n.kind.length() == 0 ) ) {
922         // If the NameComponent list has no entry then it means the current
923
// context was requested
924
bth.value = BindingType.ncontext;
925         return theNameServiceHandle.getObjectReferenceFromKey(
926         this.objKey );
927     }
928
929     InternalBindingKey key = new InternalBindingKey(n);
930     InternalBindingValue value =
931             (InternalBindingValue) this.theHashtable.get(key);
932
933     if( value == null ) {
934         // No entry was found for the given name and hence return NULL
935
// NamingContextDataStore throws appropriate exception if
936
// required.
937
return null;
938     }
939
940     Object JavaDoc theObjectFromStringifiedReference = null;
941     bth.value = value.theBindingType;
942
943     try {
944         // Check whether the entry found in the Hashtable starts with NC
945
// Which means it's a name context. So get the NamingContext reference
946
// from ServantManager, which would either return from the cache or
947
// read it from the File.
948
if( value.strObjectRef.startsWith( "NC" ) ) {
949         bth.value = BindingType.ncontext;
950         return theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
951         } else {
952         // Else, It is a Object Reference. Check whether Object Reference
953
// can be obtained directly, If not then convert the stringified
954
// reference to object and return.
955
theObjectFromStringifiedReference = value.getObjectRef( );
956
957         if (theObjectFromStringifiedReference == null ) {
958             try {
959             theObjectFromStringifiedReference =
960             orb.string_to_object( value.strObjectRef );
961             value.setObjectRef( theObjectFromStringifiedReference );
962             } catch( Exception JavaDoc e ) {
963             throw readWrapper.resolveConversionFailure(
964                 CompletionStatus.COMPLETED_MAYBE, e );
965             }
966         }
967         }
968     } catch ( Exception JavaDoc e ) {
969         throw readWrapper.resolveFailure(
970         CompletionStatus.COMPLETED_MAYBE, e );
971     }
972
973     return theObjectFromStringifiedReference;
974     }
975
976    /**
977    * This method Unbinds the NamingContext or Object Reference for one level
978    * The doUnbind( ) method from superclass calls Unbind() to recursively
979    * Unbind using compound Names.
980    * @param n a sequence of NameComponents which is the name to be resolved.
981    * @return the object reference bound under the supplied name.
982    * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
983    * or a Corba Object reference not found under this Name
984    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
985    * in resolving the the supplied name.
986    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
987    * is invalid (i.e., has length less than 1).
988    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
989    * @see Bind
990    */

991
992     public Object JavaDoc Unbind(NameComponent n) throws SystemException JavaDoc
993     {
994     try {
995         InternalBindingKey key = new InternalBindingKey(n);
996         InternalBindingValue value = null;
997
998         try {
999         value = (InternalBindingValue) this.theHashtable.remove(key);
1000        } catch( Exception JavaDoc e ) {
1001        // Ignore the exception in Hashtable.remove
1002
}
1003
1004        theServantManagerImplHandle.updateContext( objKey, this );
1005
1006        if( value == null ) {
1007        return null;
1008        }
1009
1010        if( value.strObjectRef.startsWith( "NC" ) ) {
1011        theServantManagerImplHandle.readInContext( value.strObjectRef );
1012        Object JavaDoc theObjectFromStringfiedReference =
1013        theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
1014        return theObjectFromStringfiedReference;
1015        } else {
1016        Object JavaDoc theObjectFromStringifiedReference = value.getObjectRef( );
1017
1018        if( theObjectFromStringifiedReference == null ) {
1019            theObjectFromStringifiedReference =
1020            orb.string_to_object( value.strObjectRef );
1021        }
1022
1023        return theObjectFromStringifiedReference;
1024        }
1025    } catch( Exception JavaDoc e ) {
1026        throw updateWrapper.unbindFailure( CompletionStatus.COMPLETED_MAYBE, e );
1027    }
1028    }
1029
1030   /**
1031   * List the contents of this NamingContext. It creates a new
1032   * PersistentBindingIterator object and passes it a clone of the
1033   * hash table and an orb object. It then uses the
1034   * newly created object to return the required number of bindings.
1035   * @param how_many The number of requested bindings in the BindingList.
1036   * @param bl The BindingList as an out parameter.
1037   * @param bi The BindingIterator as an out parameter.
1038   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
1039   */

1040
1041    public void List(int how_many, BindingListHolder bl,
1042             BindingIteratorHolder bi) throws SystemException JavaDoc
1043    {
1044        if( biPOA == null ) {
1045            createbiPOA( );
1046        }
1047        try {
1048            PersistentBindingIterator bindingIterator =
1049                new PersistentBindingIterator(this.orb,
1050                (Hashtable JavaDoc)this.theHashtable.clone(), biPOA);
1051            // Have it set the binding list
1052
bindingIterator.list(how_many,bl);
1053
1054            byte[] objectId = biPOA.activate_object( bindingIterator );
1055            org.omg.CORBA.Object JavaDoc obj = biPOA.id_to_reference( objectId );
1056
1057            // Get the object reference for the binding iterator servant
1058
org.omg.CosNaming.BindingIterator JavaDoc bindingRef =
1059                org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
1060
1061            bi.value = bindingRef;
1062        } catch (org.omg.CORBA.SystemException JavaDoc e) {
1063            throw e;
1064        } catch( Exception JavaDoc e ) {
1065        throw readWrapper.transNcListGotExc( e ) ;
1066        }
1067    }
1068
1069    private synchronized void createbiPOA( ) {
1070        if( biPOA != null ) {
1071            return;
1072        }
1073        try {
1074            POA JavaDoc rootPOA = (POA JavaDoc) orb.resolve_initial_references(
1075        ORBConstants.ROOT_POA_NAME );
1076            rootPOA.the_POAManager().activate( );
1077
1078            int i = 0;
1079            Policy JavaDoc[] poaPolicy = new Policy JavaDoc[3];
1080            poaPolicy[i++] = rootPOA.create_lifespan_policy(
1081                LifespanPolicyValue.TRANSIENT);
1082            poaPolicy[i++] = rootPOA.create_id_assignment_policy(
1083                IdAssignmentPolicyValue.SYSTEM_ID);
1084            poaPolicy[i++] = rootPOA.create_servant_retention_policy(
1085                ServantRetentionPolicyValue.RETAIN);
1086            biPOA = rootPOA.create_POA("BindingIteratorPOA", null, poaPolicy );
1087            biPOA.the_POAManager().activate( );
1088        } catch( Exception JavaDoc e ) {
1089        throw readWrapper.namingCtxBindingIteratorCreate( e ) ;
1090        }
1091    }
1092
1093
1094   /**
1095   * Create a NamingContext object and return its object reference.
1096   * @return an object reference for a new NamingContext object implemented
1097   * by this Name Server.
1098   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
1099   */

1100    public NamingContext NewContext() throws SystemException JavaDoc
1101    {
1102    try {
1103        return theNameServiceHandle.NewContext( );
1104    } catch( org.omg.CORBA.SystemException JavaDoc e ) {
1105        throw e;
1106    } catch( Exception JavaDoc e ) {
1107        throw updateWrapper.transNcNewctxGotExc( e ) ;
1108    }
1109     }
1110
1111
1112   /**
1113   * Destroys the NamingContext.
1114   */

1115    public void Destroy() throws SystemException JavaDoc
1116    {
1117    // XXX note that orb.disconnect is illegal here, since the
1118
// POA is used. However, there may be some associated state
1119
// that needs to be cleaned up in ServerManagerImpl which we will
1120
// look into further at another time.
1121
/*
1122    // XXX This needs to be replaced by cleaning up the
1123    // file that backs up the naming context. No explicit
1124    // action is necessary at the POA level, since this is
1125    // created with the non-retain policy.
1126    /*
1127    try { orb.disconnect(
1128        theNameServiceHandle.getObjectReferenceFromKey( this.objKey ) );
1129    } catch( org.omg.CORBA.SystemException e ) {
1130        throw e;
1131    } catch( Exception e ) {
1132        throw updateWrapper.transNcDestroyGotEx( e ) ;
1133    }
1134    */

1135    }
1136
1137    /**
1138    * This operation creates a stringified name from the array of Name
1139    * components.
1140    * @param n Name of the object <p>
1141    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1142    * Indicates the name does not identify a binding.<p>
1143    *
1144    */

1145    public String JavaDoc to_string(org.omg.CosNaming.NameComponent JavaDoc[] n)
1146         throws org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
1147    {
1148        // Name valid?
1149
if ( (n == null ) || (n.length == 0) )
1150        {
1151                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1152        }
1153
1154        String JavaDoc theStringifiedName = getINSImpl().convertToString( n );
1155
1156        if( theStringifiedName == null )
1157        {
1158                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1159        }
1160
1161        return theStringifiedName;
1162    }
1163
1164    /**
1165    * This operation converts a Stringified Name into an equivalent array
1166    * of Name Components.
1167    * @param sn Stringified Name of the object <p>
1168    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1169    * Indicates the name does not identify a binding.<p>
1170    *
1171    */

1172    public org.omg.CosNaming.NameComponent JavaDoc[] to_name(String JavaDoc sn)
1173         throws org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
1174    {
1175        // Name valid?
1176
if ( (sn == null ) || (sn.length() == 0) )
1177        {
1178                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1179        }
1180        org.omg.CosNaming.NameComponent JavaDoc[] theNameComponents =
1181                getINSImpl().convertToNameComponent( sn );
1182        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
1183        {
1184                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1185        }
1186        for( int i = 0; i < theNameComponents.length; i++ ) {
1187            // If there is a name component whose id and kind null or
1188
// zero length string, then an invalid name exception needs to be
1189
// raised.
1190
if ( ( ( theNameComponents[i].id == null )
1191                 ||( theNameComponents[i].id.length() == 0 ) )
1192               &&( ( theNameComponents[i].kind == null )
1193                 ||( theNameComponents[i].kind.length() == 0 ) ) ) {
1194                throw new InvalidName();
1195            }
1196        }
1197        return theNameComponents;
1198    }
1199
1200    /**
1201    * This operation creates a URL based "iiopname://" format name
1202    * from the Stringified Name of the object.
1203    * @param addr internet based address of the host machine where
1204    * Name Service is running <p>
1205    * @param sn Stringified Name of the object <p>
1206    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1207    * Indicates the name does not identify a binding.<p>
1208    * @exception org.omg.CosNaming.NamingContextPackage.InvalidAddress
1209    * Indicates the internet based address of the host machine is
1210    * incorrect <p>
1211    *
1212    */

1213
1214    public String JavaDoc to_url(String JavaDoc addr, String JavaDoc sn)
1215        throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress JavaDoc,
1216               org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
1217    {
1218        // Name valid?
1219
if ( (sn == null ) || (sn.length() == 0) )
1220        {
1221                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1222        }
1223        if( addr == null )
1224        {
1225                throw new org.omg.CosNaming.NamingContextExtPackage.InvalidAddress JavaDoc();
1226        }
1227        String JavaDoc urlBasedAddress = null;
1228        try {
1229            urlBasedAddress = getINSImpl().createURLBasedAddress( addr, sn );
1230        } catch (Exception JavaDoc e ) {
1231            urlBasedAddress = null;
1232        }
1233        // Extra check to see that corba name url created is valid as per
1234
// INS spec grammer.
1235
try {
1236            INSURLHandler.getINSURLHandler().parseURL( urlBasedAddress );
1237        } catch( BAD_PARAM JavaDoc e ) {
1238            throw new
1239                org.omg.CosNaming.NamingContextExtPackage.InvalidAddress JavaDoc();
1240        }
1241        return urlBasedAddress;
1242    }
1243
1244    /**
1245     * This operation resolves the Stringified name into the object
1246     * reference.
1247     * @param sn Stringified Name of the object <p>
1248     * @exception org.omg.CosNaming.NamingContextPackage.NotFound
1249     * Indicates there is no object reference for the given name. <p>
1250     * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
1251     * Indicates that the given compound name is incorrect <p>
1252     * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1253     * Indicates the name does not identify a binding.<p>
1254     *
1255     */

1256    public org.omg.CORBA.Object JavaDoc resolve_str(String JavaDoc sn)
1257        throws org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc,
1258               org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc,
1259               org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc
1260    {
1261        org.omg.CORBA.Object JavaDoc theObject = null;
1262        // Name valid?
1263
if ( (sn == null ) || (sn.length() == 0) )
1264        {
1265                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1266        }
1267        org.omg.CosNaming.NameComponent JavaDoc[] theNameComponents =
1268                getINSImpl().convertToNameComponent( sn );
1269        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
1270        {
1271                throw new org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc();
1272        }
1273        theObject = resolve( theNameComponents );
1274        return theObject;
1275    }
1276  
1277   /**
1278   * This is a Debugging Method
1279   */

1280    public boolean IsEmpty()
1281    {
1282    return this.theHashtable.isEmpty();
1283    }
1284
1285   /**
1286   * This is a Debugging Method
1287   */

1288    public void printSize( )
1289    {
1290    System.out.println( "Hashtable Size = " + theHashtable.size( ) );
1291    java.util.Enumeration JavaDoc e = theHashtable.keys( );
1292    for( ; e.hasMoreElements(); )
1293    {
1294          InternalBindingValue thevalue =
1295            (InternalBindingValue) this.theHashtable.get(e.nextElement());
1296        if( thevalue != null )
1297        {
1298            System.out.println( "value = " + thevalue.strObjectRef);
1299        }
1300    }
1301    }
1302
1303}
1304
Popular Tags