NamingContextImpl.java revision 673:6b017d166ac2
1/*
2 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.naming.pcosnaming;
27
28
29import org.omg.CORBA.Object;
30import org.omg.CORBA.SystemException;
31import org.omg.CORBA.BAD_PARAM;
32import org.omg.CORBA.CompletionStatus;
33import org.omg.CORBA.Policy;
34import org.omg.PortableServer.POA;
35import org.omg.PortableServer.LifespanPolicyValue;
36import org.omg.PortableServer.RequestProcessingPolicyValue;
37import org.omg.PortableServer.IdAssignmentPolicyValue;
38import org.omg.PortableServer.ServantRetentionPolicyValue;
39
40import org.omg.CosNaming.*;
41import org.omg.CosNaming.NamingContextPackage.*;
42import org.omg.CosNaming.NamingContextExtPackage.*;
43
44import com.sun.corba.se.impl.naming.cosnaming.NamingContextDataStore;
45import com.sun.corba.se.impl.naming.cosnaming.NamingUtils;
46
47import com.sun.corba.se.impl.naming.namingutil.INSURLHandler;
48
49import com.sun.corba.se.spi.orb.ORB;
50import com.sun.corba.se.spi.logging.CORBALogDomains;
51
52import com.sun.corba.se.impl.orbutil.ORBConstants;
53import com.sun.corba.se.impl.logging.NamingSystemException;
54
55import java.io.Serializable;
56import java.util.Hashtable;
57
58/**
59 * Class NamingContextImpl implements the org.omg.CosNaming::NamingContext and
60 * NamingContextExt interface.
61 * <p>
62 * The operations bind(), rebind(), bind_context() and rebind_context()
63 * are all really implemented by doBind(). resolve() is really implemented
64 * by doResolve(), unbind() by doUnbind(). list(), new_context() and
65 * destroy() uses the NamingContextDataStore interface directly. All the
66 * doX() methods are public static.
67 * They synchronize on the NamingContextDataStore object.
68 * <p>
69 * None of the methods here are Synchronized because These methods will be
70 * invoked from Super class's doBind( ), doResolve( ) which are already
71 * Synchronized.
72 */
73
74
75public class NamingContextImpl
76    extends NamingContextExtPOA
77    implements NamingContextDataStore, Serializable
78{
79
80    // The ORB is required to do string_to_object() operations
81    // All the references are stored in the files in the form of IOR strings
82    private transient ORB orb;
83
84    // The ObjectKey will be in the format NC<Index> which uniquely identifies
85    // The NamingContext internaly
86    private final String objKey;
87
88    // Hash table contains all the entries in the NamingContexts. The
89    // CORBA.Object references will be stored in the form of IOR strings
90    // and the Child Naming Contexts will have it's key as the entry in the
91    // table. This table is written into File everytime an update is made
92    // on this context.
93    private final Hashtable theHashtable = new Hashtable( );
94
95    // The NameServiceHandle is required to get the ObjectId from the
96    // NamingContext's references. These references are created using
97    // POA in the NameService.
98    private transient NameService theNameServiceHandle;
99
100    // ServantManager is the single point of contact to Read, Write and
101    // Update the NamingContextFile
102    private transient ServantManagerImpl theServantManagerImplHandle;
103
104    // All the INS (Interoperable Naming Service) methods are defined in this class
105    // All the calls to INS will be delegated to this class.
106    private transient com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl insImpl;
107
108    private transient NamingSystemException readWrapper ;
109
110    private transient NamingSystemException updateWrapper ;
111
112    private static POA biPOA = null;
113
114    /**
115     * Create a naming context servant.
116     * Runs the super constructor.
117     * @param orb an ORB object.
118     * @param objKey as String
119     * @param theNameService as NameService
120     * @param theServantManagerImpl as ServantManagerImpl
121     * @exception java.lang.Exception a Java exception.
122     */
123
124    public NamingContextImpl(ORB orb, String objKey,
125        NameService theNameService, ServantManagerImpl theServantManagerImpl  )
126        throws Exception
127    {
128        super();
129
130        this.orb = orb;
131        readWrapper = NamingSystemException.get( orb,
132            CORBALogDomains.NAMING_READ ) ;
133        updateWrapper = NamingSystemException.get( orb,
134            CORBALogDomains.NAMING_UPDATE ) ;
135
136        debug = true ; // orb.namingDebugFlag ;
137        this.objKey = objKey;
138        theNameServiceHandle = theNameService;
139        theServantManagerImplHandle = theServantManagerImpl;
140        insImpl =
141            new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
142    }
143
144    com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl getINSImpl( )
145    {
146        if( insImpl == null )
147        {
148            // insImpl will be null if the NamingContext graph is rebuilt from
149            // the persistence store.
150            insImpl =
151                new com.sun.corba.se.impl.naming.cosnaming.InterOperableNamingImpl();
152        }
153        return insImpl;
154    }
155
156
157    public void setRootNameService( NameService theNameService ) {
158        theNameServiceHandle = theNameService;
159    }
160
161    public void setORB( ORB theOrb ) {
162        orb = theOrb;
163    }
164
165    public void setServantManagerImpl(
166                ServantManagerImpl theServantManagerImpl )
167    {
168        theServantManagerImplHandle = theServantManagerImpl;
169    }
170
171    public POA getNSPOA( ) {
172        return theNameServiceHandle.getNSPOA( );
173    }
174
175
176
177
178   /**
179   * Bind an object under a name in this NamingContext. If the name
180   * contains multiple (n) components, n-1 will be resolved in this
181   * NamingContext and the object bound in resulting NamingContext.
182   * An exception is thrown if a binding with the supplied name already
183   * exists. If the
184   * object to be bound is a NamingContext it will not participate in
185   * a recursive resolve.
186   * @param n a sequence of NameComponents which is the name under which
187   * the object will be bound.
188   * @param obj the object reference to be bound.
189   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
190   * components was supplied, but the first component could not be
191   * resolved.
192   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
193   * in resolving the n-1 components of the supplied name.
194   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
195   * is invalid (i.e., has length less than 1).
196   * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound The supplied name
197   * is already bound.
198   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
199   * @see doBind
200   */
201   public void bind(NameComponent[] n, org.omg.CORBA.Object obj)
202        throws org.omg.CosNaming.NamingContextPackage.NotFound,
203               org.omg.CosNaming.NamingContextPackage.CannotProceed,
204               org.omg.CosNaming.NamingContextPackage.InvalidName,
205               org.omg.CosNaming.NamingContextPackage.AlreadyBound
206    {
207        if( obj == null ) {
208            throw updateWrapper.objectIsNull() ;
209        }
210
211        if (debug)
212            dprint("bind " + nameToString(n) + " to " + obj);
213        // doBind implements all four flavors of binding
214        NamingContextDataStore impl = (NamingContextDataStore)this;
215        doBind(impl,n,obj,false,BindingType.nobject);
216    }
217
218   /**
219   * Bind a NamingContext under a name in this NamingContext. If the name
220   * contains multiple (n) components, n-1 will be resolved in this
221   * NamingContext and the object bound in resulting NamingContext.
222   * An exception is thrown if a binding with the supplied name already
223   * exists. The NamingContext will participate in recursive resolving.
224   * @param n a sequence of NameComponents which is the name under which
225   * the object will be bound.
226   * @param nc the NamingContect object reference to be bound.
227   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
228   * components was supplied, but the first component could not be
229   * resolved.
230   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
231   * in resolving the n-1 components of the supplied name.
232   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
233   * is invalid (i.e., has length less than 1).
234   * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
235   * already bound under the supplied name.
236   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
237   * @see doBind
238   */
239   public void bind_context(NameComponent[] n, NamingContext nc)
240        throws org.omg.CosNaming.NamingContextPackage.NotFound,
241               org.omg.CosNaming.NamingContextPackage.CannotProceed,
242               org.omg.CosNaming.NamingContextPackage.InvalidName,
243               org.omg.CosNaming.NamingContextPackage.AlreadyBound
244    {
245        if( nc == null ) {
246            throw updateWrapper.objectIsNull() ;
247        }
248        // doBind implements all four flavors of binding
249        NamingContextDataStore impl = (NamingContextDataStore)this;
250        doBind(impl,n,nc,false,BindingType.ncontext);
251    }
252
253 /**
254   * Bind an object under a name in this NamingContext. If the name
255   * contains multiple (n) components, n-1 will be resolved in this
256   * NamingContext and the object bound in resulting NamingContext.
257   * If a binding under the supplied name already exists it will be
258   * unbound first. If the
259   * object to be bound is a NamingContext it will not participate in
260   * a recursive resolve.
261   * @param n a sequence of NameComponents which is the name under which
262   * the object will be bound.
263   * @param obj the object reference to be bound.
264   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
265   * components was supplied, but the first component could not be
266   * resolved.
267   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
268   * in resolving the n-1 components of the supplied name.
269   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
270   * is invalid (i.e., has length less than 1).
271   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
272   * @see doBind
273   */
274   public  void rebind(NameComponent[] n, org.omg.CORBA.Object obj)
275        throws       org.omg.CosNaming.NamingContextPackage.NotFound,
276                     org.omg.CosNaming.NamingContextPackage.CannotProceed,
277                     org.omg.CosNaming.NamingContextPackage.InvalidName
278    {
279        if( obj == null )
280        {
281            throw updateWrapper.objectIsNull() ;
282        }
283        try {
284            if (debug)
285                dprint("rebind " + nameToString(n) + " to " + obj);
286            // doBind implements all four flavors of binding
287            NamingContextDataStore impl = (NamingContextDataStore)this;
288            doBind(impl,n,obj,true,BindingType.nobject);
289        } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
290            // This should not happen
291            throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
292        }
293    }
294
295   /**
296   * Bind a NamingContext under a name in this NamingContext. If the name
297   * contains multiple (n) components, the first n-1 components will be
298   * resolved in this
299   * NamingContext and the object bound in resulting NamingContext.
300   * If a binding under the supplied name already exists it will be
301   * unbound first. The NamingContext will participate in recursive resolving.
302   * @param n a sequence of NameComponents which is the name under which
303   * the object will be bound.
304   * @param nc the object reference to be bound.
305   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
306   * components was supplied, but the first component could not be
307   * resolved.
308   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
309   * in resolving the n-1 components of the supplied name.
310   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
311   * is invalid (i.e., has length less than 1).
312   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
313   * @see doBind
314   */
315   public  void rebind_context(NameComponent[] n, NamingContext nc)
316        throws org.omg.CosNaming.NamingContextPackage.NotFound,
317               org.omg.CosNaming.NamingContextPackage.CannotProceed,
318               org.omg.CosNaming.NamingContextPackage.InvalidName
319    {
320        try {
321            if (debug)
322                dprint("rebind_context " + nameToString(n) + " to " + nc);
323            // doBind implements all four flavors of binding
324            NamingContextDataStore impl = (NamingContextDataStore)this;
325            doBind(impl,n,nc,true,BindingType.ncontext);
326        } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) {
327            // This should not happen
328            throw updateWrapper.namingCtxRebindAlreadyBound( ex ) ;
329        }
330    }
331
332   /**
333   * Resolve a name in this NamingContext and return the object reference
334   * bound to the name. If the name contains multiple (n) components,
335   * the first component will be resolved in this NamingContext and the
336   * remaining components resolved in the resulting NamingContext, provided
337   * that the NamingContext bound to the first component of the name was
338   * bound with bind_context().
339   * @param n a sequence of NameComponents which is the name to be resolved.
340   * @return the object reference bound under the supplied name.
341   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
342   * components was supplied, but the first component could not be
343   * resolved.
344   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
345   * in resolving the n-1 components of the supplied name.
346   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
347   * is invalid (i.e., has length less than 1).
348   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
349   * @see doResolve
350   */
351   public  org.omg.CORBA.Object resolve(NameComponent[] n)
352        throws org.omg.CosNaming.NamingContextPackage.NotFound,
353               org.omg.CosNaming.NamingContextPackage.CannotProceed,
354               org.omg.CosNaming.NamingContextPackage.InvalidName
355    {
356        if (debug)
357            dprint("resolve " + nameToString(n));
358        // doResolve actually resolves
359        NamingContextDataStore impl = (NamingContextDataStore)this;
360        return doResolve(impl,n);
361    }
362
363   /**
364   * Remove a binding from this NamingContext. If the name contains
365   * multiple (n) components, the first n-1 components will be resolved
366   * from this NamingContext and the final component unbound in
367   * the resulting NamingContext.
368   * @param n a sequence of NameComponents which is the name to be unbound.
369   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
370   * components was supplied, but the first component could not be
371   * resolved.
372   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
373   * in resolving the n-1 components of the supplied name.
374   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
375   * is invalid (i.e., has length less than 1).
376   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
377   * @see doUnbind
378   */
379   public  void unbind(NameComponent[] n)
380        throws org.omg.CosNaming.NamingContextPackage.NotFound,
381               org.omg.CosNaming.NamingContextPackage.CannotProceed,
382               org.omg.CosNaming.NamingContextPackage.InvalidName
383    {
384        if (debug)
385            dprint("unbind " + nameToString(n));
386        // doUnbind actually unbinds
387        NamingContextDataStore impl = (NamingContextDataStore)this;
388        doUnbind(impl,n);
389    }
390
391   /**
392   * List the contents of this NamingContest. A sequence of bindings
393   * is returned (a BindingList) containing up to the number of requested
394   * bindings, and a BindingIterator object reference is returned for
395   * iterating over the remaining bindings.
396   * @param how_many The number of requested bindings in the BindingList.
397   * @param bl The BindingList as an out parameter.
398   * @param bi The BindingIterator as an out parameter.
399   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
400   * @see BindingListHolder
401   * @see BindingIteratorImpl
402   */
403    public  void list(int how_many, BindingListHolder bl, BindingIteratorHolder bi)
404    {
405        if (debug)
406            dprint("list(" + how_many + ")");
407        // List actually generates the list
408        NamingContextDataStore impl = (NamingContextDataStore)this;
409        synchronized (impl) {
410            impl.List(how_many,bl,bi);
411        }
412        if (debug && bl.value != null)
413            dprint("list(" + how_many + ") -> bindings[" + bl.value.length +
414                   "] + iterator: " + bi.value);
415    }
416
417
418   /**
419   * Create a NamingContext object and return its object reference.
420   * @return an object reference for a new NamingContext object implemented
421   * by this Name Server.
422   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
423   */
424    public synchronized NamingContext new_context()
425    {
426        // Create actually creates a new naming context
427        if (debug)
428            dprint("new_context()");
429        NamingContextDataStore impl = (NamingContextDataStore)this;
430        synchronized (impl) {
431            return impl.NewContext();
432        }
433    }
434
435
436   /**
437   * Create a new NamingContext, bind it in this Naming Context and return
438   * its object reference. This is equivalent to using new_context() followed
439   * by bind_context() with the supplied name and the object reference for
440   * the newly created NamingContext.
441   * @param n a sequence of NameComponents which is the name to be unbound.
442   * @return an object reference for a new NamingContext object implemented
443   * by this Name Server, bound to the supplied name.
444   * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
445   * already bound under the supplied name.
446   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
447   * components was supplied, but the first component could not be
448   * resolved.
449   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
450   * in resolving the n-1 components of the supplied name.
451   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
452   * is invalid (i.e., has length less than 1).
453   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
454   * @see new_context
455   * @see bind_context
456   */
457    public  NamingContext bind_new_context(NameComponent[] n)
458        throws org.omg.CosNaming.NamingContextPackage.NotFound,
459               org.omg.CosNaming.NamingContextPackage.AlreadyBound,
460               org.omg.CosNaming.NamingContextPackage.CannotProceed,
461               org.omg.CosNaming.NamingContextPackage.InvalidName
462    {
463        NamingContext nc = null;
464        NamingContext rnc = null;
465        try {
466            if (debug)
467                dprint("bind_new_context " + nameToString(n));
468            // The obvious solution:
469            nc = this.new_context();
470            this.bind_context(n,nc);
471            rnc = nc;
472            nc = null;
473        } finally {
474            try {
475                if(nc != null)
476                    nc.destroy();
477            } catch (org.omg.CosNaming.NamingContextPackage.NotEmpty e) {
478            }
479        }
480        return rnc;
481    }
482
483    /**
484   * Destroy this NamingContext object. If this NamingContext contains
485   * no bindings, the NamingContext is deleted.
486   * @exception org.omg.CosNaming.NamingContextPackage.NotEmpty This NamingContext
487   * is not empty (i.e., contains bindings).
488   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
489   */
490    public  void destroy()
491        throws org.omg.CosNaming.NamingContextPackage.NotEmpty
492    {
493        if (debug)
494            dprint("destroy ");
495        NamingContextDataStore impl = (NamingContextDataStore)this;
496        synchronized (impl) {
497            if (impl.IsEmpty() == true)
498                // The context is empty so it can be destroyed
499                impl.Destroy();
500            else
501                // This context is not empty!
502                throw new org.omg.CosNaming.NamingContextPackage.NotEmpty();
503        }
504    }
505
506      /**
507   * Implements all four flavors of binding. It uses Resolve() to
508   * check if a binding already exists (for bind and bind_context), and
509   * unbind() to ensure that a binding does not already exist.
510   * If the length of the name is 1, then Bind() is called with
511   * the name and the object to bind. Otherwise, the first component
512   * of the name is resolved in this NamingContext and the appropriate
513   * form of bind passed to the resulting NamingContext.
514   * This method is static for maximal reuse - even for extended naming
515   * context implementations where the recursive semantics still apply.
516   * @param impl an implementation of NamingContextDataStore
517   * @param n a sequence of NameComponents which is the name under which
518   * the object will be bound.
519   * @param obj the object reference to be bound.
520   * @param rebind Replace an existing binding or not.
521   * @param bt Type of binding (as object or as context).
522   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
523   * components was supplied, but the first component could not be
524   * resolved.
525   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
526   * in resolving the first component of the supplied name.
527   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
528   * is invalid (i.e., has length less than 1).
529   * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object is
530   * already bound under the supplied name.
531   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
532   * @see resolve
533   * @see unbind
534   * @see bind
535   * @see bind_context
536   * @see rebind
537   * @see rebind_context
538   */
539    private void doBind(NamingContextDataStore impl,
540                              NameComponent[] n,
541                              org.omg.CORBA.Object obj,
542                              boolean rebind,
543                              org.omg.CosNaming.BindingType bt)
544        throws org.omg.CosNaming.NamingContextPackage.NotFound,
545               org.omg.CosNaming.NamingContextPackage.CannotProceed,
546               org.omg.CosNaming.NamingContextPackage.InvalidName,
547               org.omg.CosNaming.NamingContextPackage.AlreadyBound
548    {
549        // Valid name?
550        if (n.length < 1)
551            throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
552
553    // At bottom level?
554        if (n.length == 1) {
555            // The identifier must be set
556            if( (n[0].id.length() == 0) && (n[0].kind.length() == 0) )
557                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
558
559            // Ensure synchronization of backend
560            synchronized (impl) {
561                // Yes: bind object in this context under the name
562                BindingTypeHolder bth = new BindingTypeHolder();
563                if (rebind) {
564                    org.omg.CORBA.Object objRef = impl.Resolve( n[0], bth );
565                    if( objRef != null ) {
566                        // Refer Naming Service Doc:00-11-01 section 2.2.3.4
567                        // If there is an object already bound with the name
568                        // and the binding type is not ncontext a NotFound
569                        // Exception with a reason of not a context has to be
570                        // raised.
571                        // Fix for bug Id: 4384628
572                        if ( bth.value.value() == BindingType.nobject.value() ) {
573                            if ( bt.value() == BindingType.ncontext.value() ) {
574                                throw new NotFound(NotFoundReason.not_context, n);
575                            }
576                        } else {
577                            // Previously a Context was bound and now trying to
578                            // bind Object. It is invalid.
579                            if ( bt.value() == BindingType.nobject.value() ) {
580                                throw new NotFound(NotFoundReason.not_object, n);
581                            }
582                        }
583                        impl.Unbind(n[0]);
584                    }
585                } else {
586                    if (impl.Resolve(n[0],bth) != null)
587                        throw new org.omg.CosNaming.NamingContextPackage.AlreadyBound();
588                }
589
590                // Now there are no other bindings under this name
591                impl.Bind(n[0],obj,bt);
592            }
593        } else {
594            // No: bind in a different context
595            NamingContext context = resolveFirstAsContext(impl,n);
596
597            // Compute tail
598            NameComponent[] tail = new NameComponent[n.length - 1];
599            System.arraycopy(n,1,tail,0,n.length-1);
600
601      // How should we propagate the bind
602            switch (bt.value()) {
603            case BindingType._nobject:
604                {
605                    // Bind as object
606                    if (rebind)
607                        context.rebind(tail,obj);
608                    else
609                        context.bind(tail,obj);
610                }
611                break;
612            case BindingType._ncontext:
613                {
614                    // Narrow to a naming context using Java casts. It must work.
615                    NamingContext objContext = (NamingContext)obj;
616                    // Bind as context
617                    if (rebind)
618                        context.rebind_context(tail,objContext);
619                    else
620                        context.bind_context(tail,objContext);
621                }
622                break;
623            default:
624                // This should not happen
625                throw updateWrapper.namingCtxBadBindingtype() ;
626            }
627        }
628    }
629
630
631   /**
632   * Implements resolving names in this NamingContext. The first component
633   * of the supplied name is resolved in this NamingContext by calling
634   * Resolve(). If there are no more components in the name, the
635   * resulting object reference is returned. Otherwise, the resulting object
636   * reference must have been bound as a context and be narrowable to
637   * a NamingContext. If this is the case, the remaining
638   * components of the name is resolved in the resulting NamingContext.
639   * This method is static for maximal reuse - even for extended naming
640   * context implementations where the recursive semantics still apply.
641   * @param impl an implementation of NamingContextDataStore
642   * @param n a sequence of NameComponents which is the name to be resolved.
643   * @return the object reference bound under the supplied name.
644   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
645   * components was supplied, but the first component could not be
646   * resolved.
647   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
648   * in resolving the first component of the supplied name.
649   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
650   * is invalid (i.e., has length less than 1).
651   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
652   * @see resolve
653   */
654    public static org.omg.CORBA.Object doResolve(NamingContextDataStore impl,
655                                                 NameComponent[] n)
656        throws org.omg.CosNaming.NamingContextPackage.NotFound,
657               org.omg.CosNaming.NamingContextPackage.CannotProceed,
658               org.omg.CosNaming.NamingContextPackage.InvalidName
659    {
660        org.omg.CORBA.Object obj = null;
661        BindingTypeHolder bth = new BindingTypeHolder();
662
663        // Length must be greater than 0
664        if (n.length < 1)
665            throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
666
667        // The identifier must be set
668        if (n.length == 1) {
669            synchronized (impl) {
670                // Resolve first level in this context
671                obj = impl.Resolve(n[0],bth);
672            }
673            if (obj == null) {
674                // Object was not found
675                throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
676            }
677            return obj;
678        } else {
679            // n.length > 1
680            if ( (n[1].id.length() == 0) && (n[1].kind.length() == 0 ) )
681                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
682
683            NamingContext context = resolveFirstAsContext(impl,n);
684
685            // Compute restOfName = name[1..length]
686            NameComponent[] tail = new NameComponent[n.length -1];
687            System.arraycopy(n,1,tail,0,n.length-1);
688
689            // Resolve rest of name in context
690            return context.resolve(tail);
691        }
692    }
693
694    /**
695   * Implements unbinding bound names in this NamingContext. If the
696   * name contains only one component, the name is unbound in this
697   * NamingContext using Unbind(). Otherwise, the first component
698   * of the name is resolved in this NamingContext and
699   * unbind passed to the resulting NamingContext.
700   * This method is static for maximal reuse - even for extended naming
701   * context implementations where the recursive semantics still apply.
702   * @param impl an implementation of NamingContextDataStore
703   * @param n a sequence of NameComponents which is the name to be unbound.
704   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple
705   * components was supplied, but the first component could not be
706   * resolved.
707   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
708   * in resolving the n-1 components of the supplied name.
709   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
710   * is invalid (i.e., has length less than 1).
711   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
712   * @see resolve
713   */
714    public static void doUnbind(NamingContextDataStore impl,
715                                NameComponent[] n)
716        throws org.omg.CosNaming.NamingContextPackage.NotFound,
717               org.omg.CosNaming.NamingContextPackage.CannotProceed,
718               org.omg.CosNaming.NamingContextPackage.InvalidName
719    {
720        // Name valid?
721        if (n.length < 1)
722            throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
723
724        // Unbind here?
725        if (n.length == 1) {
726            // The identifier must be set
727            if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) )
728                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
729
730            org.omg.CORBA.Object objRef = null;
731            synchronized (impl) {
732                // Yes: unbind in this context
733                objRef = impl.Unbind(n[0]);
734            }
735
736            if (objRef == null)
737                // It was not bound
738                throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
739            // Done
740            return;
741        } else {
742            // No: unbind in a different context
743
744      // Resolve first  - must be resolveable
745            NamingContext context = resolveFirstAsContext(impl,n);
746
747            // Compute tail
748            NameComponent[] tail = new NameComponent[n.length - 1];
749            System.arraycopy(n,1,tail,0,n.length-1);
750
751      // Propagate unbind to this context
752            context.unbind(tail);
753        }
754    }
755
756     /**
757   * Implements resolving a NameComponent in this context and
758   * narrowing it to CosNaming::NamingContext. It will throw appropriate
759   * exceptions if not found or not narrowable.
760   * @param impl an implementation of NamingContextDataStore
761   * @param n a NameComponents which is the name to be found.
762   * @exception org.omg.CosNaming.NamingContextPackage.NotFound The
763   * first component could not be resolved.
764   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
765   * in resolving the first component of the supplied name.
766   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
767   * @see resolve
768   */
769    protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl,
770                                                         NameComponent[] n)
771        throws org.omg.CosNaming.NamingContextPackage.NotFound {
772        org.omg.CORBA.Object topRef = null;
773        BindingTypeHolder bth = new BindingTypeHolder();
774        NamingContext context = null;
775
776        synchronized (impl) {
777            // Resolve first  - must be resolveable
778            topRef = impl.Resolve(n[0],bth);
779            if (topRef == null) {
780                // It was not bound
781                throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);
782            }
783        }
784
785        // Was it bound as a context?
786        if (bth.value != BindingType.ncontext) {
787            // It was not a context
788            throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
789        }
790
791        // Narrow to a naming context
792        try {
793            context = NamingContextHelper.narrow(topRef);
794        } catch (org.omg.CORBA.BAD_PARAM ex) {
795            // It was not a context
796            throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);
797        }
798
799        // Hmm. must be ok
800        return context;
801    }
802
803    public static String nameToString(NameComponent[] name)
804    {
805        StringBuffer s = new StringBuffer("{");
806        if (name != null || name.length > 0) {
807            for (int i=0;i<name.length;i++) {
808                if (i>0)
809                    s.append(",");
810                s.append("[").
811                    append(name[i].id).
812                    append(",").
813                    append(name[i].kind).
814                    append("]");
815            }
816        }
817        s.append("}");
818        return s.toString();
819    }
820
821    // Debugging aids.
822    private static boolean debug ;
823
824    private static void dprint(String msg) {
825        NamingUtils.dprint("NamingContextImpl("  +
826                           Thread.currentThread().getName() + " at " +
827                           System.currentTimeMillis() +
828                           " ems): " + msg);
829    }
830
831
832    /**
833    * Implements all flavors of binding( bind and bindcontext)
834    * This method will be called from the superclass's doBind( ) method
835    * which takes care of all the conditions before calling this method.
836    * i.e., It checks whether the Name is already Bounded, Then in the
837    * case of rebind it calls Unbind first.
838    * This method does one level binding only, To have n-level binding
839    * with compound names, doBind( ) calls this method recursively.
840    * @param n a sequence of NameComponents which is the name under which
841    * the object will be bound.
842    * @param obj the object reference to be bound.
843    * @param bt Type of binding (as object or as context).
844    * @exception org.omg.CosNaming.NamingContextPackage.NotFound  raised
845    * if the NameComoponent list is invalid
846    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
847    * Could not proceed in resolving the Name from the given NameComponent
848    * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object
849    * is already bound under the supplied name.
850    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA
851    * system exceptions
852    * @see Resolve
853    * @see Unbind
854    */
855    public void Bind(NameComponent n, org.omg.CORBA.Object obj, BindingType bt)
856    {
857        if( obj == null ) {
858            // Raise a Valid Exception and Return
859            return;
860        }
861
862        InternalBindingKey key = new InternalBindingKey(n);
863        InternalBindingValue value;
864
865        try {
866            if( bt.value() == BindingType._nobject ) {
867                // If the BindingType is an ObjectRef then Stringify this ref and
868                // Store it in InternalBindingValue instance. This is required
869                // because the Object References has to be stored in file
870                value = new InternalBindingValue(bt, orb.object_to_string(obj) );
871                value.setObjectRef( obj );
872            } else {
873                // If the BindingType is a NamingContext then get it's object key
874                // from the NameService and store it in the Internal Binding Value instance
875                String theNCKey = theNameServiceHandle.getObjectKey( obj );
876                value = new InternalBindingValue( bt, theNCKey );
877                value.setObjectRef( obj );
878            }
879
880            InternalBindingValue oldValue =
881                (InternalBindingValue)this.theHashtable.put(key,value);
882
883            if( oldValue != null) {
884                // There was an entry with this name in the Hashtable and hence throw CTX_ALREADY_BOUND
885                // exception
886                throw updateWrapper.namingCtxRebindAlreadyBound() ;
887            } else {
888                try {
889                    // Everything went smooth so update the NamingContext file with the
890                    // latest Hashtable image
891                    theServantManagerImplHandle.updateContext( objKey, this );
892                } catch( Exception e ) {
893                    // Something went wrong while updating the context
894                    // so speak the error
895                    throw updateWrapper.bindUpdateContextFailed( e ) ;
896                }
897            }
898        } catch( Exception e ) {
899            // Something went wrong while Binding the Object Reference
900            // Speak the error again.
901            throw updateWrapper.bindFailure( e ) ;
902        }
903    }
904
905    /**
906    * This method resolves the NamingContext or Object Reference for one level
907    * The doResolve( ) method calls Resolve( ) recursively to resolve n level
908    * Names.
909    * @param n a sequence of NameComponents which is the name to be resolved.
910    * @param bth Type of binding (as object or as context).
911    * @return the object reference bound under the supplied name.
912    * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
913    * or a Corba Object reference not found under this Name
914    * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
915    * in resolving the the supplied name.
916    * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
917    * is invalid (i.e., has length less than 1).
918    * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
919    * @see Bind
920    */
921    public Object Resolve(NameComponent n, BindingTypeHolder bth)
922        throws SystemException
923    {
924        if( ( n.id.length() == 0 ) &&( n.kind.length() == 0 ) ) {
925            // If the NameComponent list has no entry then it means the current
926            // context was requested
927            bth.value = BindingType.ncontext;
928            return theNameServiceHandle.getObjectReferenceFromKey(
929                this.objKey );
930        }
931
932        InternalBindingKey key = new InternalBindingKey(n);
933        InternalBindingValue value =
934            (InternalBindingValue) this.theHashtable.get(key);
935
936        if( value == null ) {
937            // No entry was found for the given name and hence return NULL
938            // NamingContextDataStore throws appropriate exception if
939            // required.
940            return null;
941        }
942
943        Object theObjectFromStringifiedReference = null;
944        bth.value = value.theBindingType;
945
946        try {
947            // Check whether the entry found in the Hashtable starts with NC
948            // Which means it's a name context. So get the NamingContext reference
949            // from ServantManager, which would either return from the cache or
950            // read it from the File.
951            if( value.strObjectRef.startsWith( "NC" ) ) {
952                bth.value = BindingType.ncontext;
953                return theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
954            } else {
955                // Else, It is a Object Reference. Check whether Object Reference
956                // can be obtained directly, If not then convert the stringified
957                // reference to object and return.
958                theObjectFromStringifiedReference = value.getObjectRef( );
959
960                if (theObjectFromStringifiedReference == null ) {
961                    try {
962                        theObjectFromStringifiedReference =
963                        orb.string_to_object( value.strObjectRef );
964                        value.setObjectRef( theObjectFromStringifiedReference );
965                    } catch( Exception e ) {
966                        throw readWrapper.resolveConversionFailure(
967                            CompletionStatus.COMPLETED_MAYBE, e );
968                    }
969                }
970            }
971        } catch ( Exception e ) {
972            throw readWrapper.resolveFailure(
973                CompletionStatus.COMPLETED_MAYBE, e );
974        }
975
976        return theObjectFromStringifiedReference;
977    }
978
979   /**
980   * This method Unbinds the NamingContext or Object Reference for one level
981   * The doUnbind( ) method from superclass calls Unbind() to recursively
982   * Unbind using compound Names.
983   * @param n a sequence of NameComponents which is the name to be resolved.
984   * @return the object reference bound under the supplied name.
985   * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext
986   * or a Corba Object reference not found under this Name
987   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed
988   * in resolving the the supplied name.
989   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name
990   * is invalid (i.e., has length less than 1).
991   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
992   * @see Bind
993   */
994
995    public Object Unbind(NameComponent n) throws SystemException
996    {
997        try {
998            InternalBindingKey key = new InternalBindingKey(n);
999            InternalBindingValue value = null;
1000
1001            try {
1002                value = (InternalBindingValue) this.theHashtable.remove(key);
1003            } catch( Exception e ) {
1004                // Ignore the exception in Hashtable.remove
1005            }
1006
1007            theServantManagerImplHandle.updateContext( objKey, this );
1008
1009            if( value == null ) {
1010                return null;
1011            }
1012
1013            if( value.strObjectRef.startsWith( "NC" ) ) {
1014                theServantManagerImplHandle.readInContext( value.strObjectRef );
1015                Object theObjectFromStringfiedReference =
1016                theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );
1017                return theObjectFromStringfiedReference;
1018            } else {
1019                Object theObjectFromStringifiedReference = value.getObjectRef( );
1020
1021                if( theObjectFromStringifiedReference == null ) {
1022                    theObjectFromStringifiedReference =
1023                    orb.string_to_object( value.strObjectRef );
1024                }
1025
1026                return theObjectFromStringifiedReference;
1027            }
1028        } catch( Exception e ) {
1029            throw updateWrapper.unbindFailure( CompletionStatus.COMPLETED_MAYBE, e );
1030        }
1031    }
1032
1033   /**
1034   * List the contents of this NamingContext. It creates a new
1035   * PersistentBindingIterator object and passes it a clone of the
1036   * hash table and an orb object. It then uses the
1037   * newly created object to return the required number of bindings.
1038   * @param how_many The number of requested bindings in the BindingList.
1039   * @param bl The BindingList as an out parameter.
1040   * @param bi The BindingIterator as an out parameter.
1041   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
1042   */
1043
1044    public void List(int how_many, BindingListHolder bl,
1045                     BindingIteratorHolder bi) throws SystemException
1046    {
1047        if( biPOA == null ) {
1048            createbiPOA( );
1049        }
1050        try {
1051            PersistentBindingIterator bindingIterator =
1052                new PersistentBindingIterator(this.orb,
1053                (Hashtable)this.theHashtable.clone(), biPOA);
1054            // Have it set the binding list
1055            bindingIterator.list(how_many,bl);
1056
1057            byte[] objectId = biPOA.activate_object( bindingIterator );
1058            org.omg.CORBA.Object obj = biPOA.id_to_reference( objectId );
1059
1060            // Get the object reference for the binding iterator servant
1061            org.omg.CosNaming.BindingIterator bindingRef =
1062                org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
1063
1064            bi.value = bindingRef;
1065        } catch (org.omg.CORBA.SystemException e) {
1066            throw e;
1067        } catch( Exception e ) {
1068            throw readWrapper.transNcListGotExc( e ) ;
1069        }
1070    }
1071
1072    private synchronized void createbiPOA( ) {
1073        if( biPOA != null ) {
1074            return;
1075        }
1076        try {
1077            POA rootPOA = (POA) orb.resolve_initial_references(
1078                ORBConstants.ROOT_POA_NAME );
1079            rootPOA.the_POAManager().activate( );
1080
1081            int i = 0;
1082            Policy[] poaPolicy = new Policy[3];
1083            poaPolicy[i++] = rootPOA.create_lifespan_policy(
1084                LifespanPolicyValue.TRANSIENT);
1085            poaPolicy[i++] = rootPOA.create_id_assignment_policy(
1086                IdAssignmentPolicyValue.SYSTEM_ID);
1087            poaPolicy[i++] = rootPOA.create_servant_retention_policy(
1088                ServantRetentionPolicyValue.RETAIN);
1089            biPOA = rootPOA.create_POA("BindingIteratorPOA", null, poaPolicy );
1090            biPOA.the_POAManager().activate( );
1091        } catch( Exception e ) {
1092            throw readWrapper.namingCtxBindingIteratorCreate( e ) ;
1093        }
1094    }
1095
1096
1097   /**
1098   * Create a NamingContext object and return its object reference.
1099   * @return an object reference for a new NamingContext object implemented
1100   * by this Name Server.
1101   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.
1102   */
1103    public NamingContext NewContext() throws SystemException
1104    {
1105        try {
1106            return  theNameServiceHandle.NewContext( );
1107        } catch( org.omg.CORBA.SystemException e ) {
1108            throw e;
1109        } catch( Exception e ) {
1110            throw updateWrapper.transNcNewctxGotExc( e ) ;
1111        }
1112     }
1113
1114
1115   /**
1116   * Destroys the NamingContext.
1117   */
1118    public void Destroy() throws SystemException
1119    {
1120        // XXX note that orb.disconnect is illegal here, since the
1121        // POA is used.  However, there may be some associated state
1122        // that needs to be cleaned up in ServerManagerImpl which we will
1123        // look into further at another time.
1124        /*
1125        // XXX This needs to be replaced by cleaning up the
1126        // file that backs up the naming context.  No explicit
1127        // action is necessary at the POA level, since this is
1128        // created with the non-retain policy.
1129        /*
1130        try { orb.disconnect(
1131            theNameServiceHandle.getObjectReferenceFromKey( this.objKey ) );
1132        } catch( org.omg.CORBA.SystemException e ) {
1133            throw e;
1134        } catch( Exception e ) {
1135            throw updateWrapper.transNcDestroyGotEx( e ) ;
1136        }
1137        */
1138    }
1139
1140    /**
1141    * This operation creates a stringified name from the array of Name
1142    * components.
1143    * @param n Name of the object
1144    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1145    * Indicates the name does not identify a binding.
1146    */
1147    public String to_string(org.omg.CosNaming.NameComponent[] n)
1148         throws org.omg.CosNaming.NamingContextPackage.InvalidName
1149    {
1150        // Name valid?
1151        if ( (n == null ) || (n.length == 0) )
1152        {
1153                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1154        }
1155
1156        String theStringifiedName = getINSImpl().convertToString( n );
1157
1158        if( theStringifiedName == null )
1159        {
1160                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1161        }
1162
1163        return theStringifiedName;
1164    }
1165
1166    /**
1167    * This operation  converts a Stringified Name into an  equivalent array
1168    * of Name Components.
1169    * @param sn Stringified Name of the object
1170    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1171    * Indicates the name does not identify a binding.
1172    */
1173    public org.omg.CosNaming.NameComponent[] to_name(String sn)
1174         throws org.omg.CosNaming.NamingContextPackage.InvalidName
1175    {
1176        // Name valid?
1177        if  ( (sn == null ) || (sn.length() == 0) )
1178        {
1179                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1180        }
1181        org.omg.CosNaming.NameComponent[] theNameComponents =
1182                getINSImpl().convertToNameComponent( sn );
1183        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
1184        {
1185                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1186        }
1187        for( int i = 0; i < theNameComponents.length; i++ ) {
1188            // If there is a name component whose id and kind null or
1189            // zero length string, then an invalid name exception needs to be
1190            // raised.
1191            if ( ( ( theNameComponents[i].id  == null )
1192                 ||( theNameComponents[i].id.length() == 0 ) )
1193               &&( ( theNameComponents[i].kind == null )
1194                 ||( theNameComponents[i].kind.length() == 0 ) ) ) {
1195                throw new InvalidName();
1196            }
1197        }
1198        return theNameComponents;
1199    }
1200
1201    /**
1202    * This operation creates a URL based "iiopname://" format name
1203    * from the Stringified Name of the object.
1204    * @param addr internet based address of the host machine where
1205    *        Name Service is running
1206    * @param sn Stringified Name of the object
1207    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1208    * Indicates the name does not identify a binding.
1209    * @exception org.omg.CosNaming.NamingContextPackage.InvalidAddress
1210    * Indicates the internet based address of the host machine is
1211    * incorrect
1212    */
1213
1214    public String to_url(String addr, String sn)
1215        throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress,
1216               org.omg.CosNaming.NamingContextPackage.InvalidName
1217    {
1218        // Name valid?
1219        if  ( (sn == null ) || (sn.length() == 0) )
1220        {
1221                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1222        }
1223        if( addr == null )
1224        {
1225                throw new org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
1226        }
1227        String urlBasedAddress = null;
1228        try {
1229            urlBasedAddress = getINSImpl().createURLBasedAddress( addr, sn );
1230        } catch (Exception 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 e ) {
1238            throw new
1239                org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();
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
1248     * @exception org.omg.CosNaming.NamingContextPackage.NotFound
1249     * Indicates there is no object reference for the given name.
1250     * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed
1251     * Indicates that the given compound name is incorrect
1252     * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName
1253     * Indicates the name does not identify a binding.
1254     */
1255    public org.omg.CORBA.Object resolve_str(String sn)
1256        throws org.omg.CosNaming.NamingContextPackage.NotFound,
1257               org.omg.CosNaming.NamingContextPackage.CannotProceed,
1258               org.omg.CosNaming.NamingContextPackage.InvalidName
1259    {
1260        org.omg.CORBA.Object theObject = null;
1261        // Name valid?
1262        if  ( (sn == null ) || (sn.length() == 0) )
1263        {
1264                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1265        }
1266        org.omg.CosNaming.NameComponent[] theNameComponents =
1267                getINSImpl().convertToNameComponent( sn );
1268        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )
1269        {
1270                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();
1271        }
1272        theObject = resolve( theNameComponents );
1273        return theObject;
1274    }
1275
1276   /**
1277   * This is a Debugging Method
1278   */
1279    public boolean IsEmpty()
1280    {
1281        return this.theHashtable.isEmpty();
1282    }
1283
1284   /**
1285   * This is a Debugging Method
1286   */
1287    public void printSize( )
1288    {
1289        System.out.println( "Hashtable Size = " + theHashtable.size( ) );
1290        java.util.Enumeration e = theHashtable.keys( );
1291        for( ; e.hasMoreElements(); )
1292        {
1293              InternalBindingValue thevalue =
1294                        (InternalBindingValue) this.theHashtable.get(e.nextElement());
1295                if( thevalue != null )
1296                {
1297                        System.out.println( "value = " + thevalue.strObjectRef);
1298                }
1299        }
1300    }
1301
1302}
1303