KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > naming > SerialContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.naming;
24
25 import java.util.*;
26 import java.io.*;
27 import javax.naming.*;
28 import org.omg.CORBA.ORB JavaDoc;
29 import com.sun.enterprise.util.ORBManager;
30 import com.sun.enterprise.Switch;
31 import com.sun.enterprise.naming.java.javaURLContext;
32 import javax.rmi.PortableRemoteObject JavaDoc;
33 import java.rmi.RemoteException JavaDoc;
34 import org.omg.CosNaming.NamingContext JavaDoc;
35 import org.omg.CosNaming.NameComponent JavaDoc;
36 import org.omg.CosNaming.NamingContextHelper JavaDoc;
37 import com.sun.enterprise.server.ondemand.entry.*;
38
39 import java.util.logging.*;
40 import com.sun.logging.*;
41
42
43 /**
44  * This is a JNDI Context implementation for storing serializable objects.
45  * This is the default Context for the J2EE RI. Lookups of unqualified
46  * names (i.e. names not starting with "java:", "corbaname:" etc)
47  * are serviced by SerialContext. The namespace is implemented in
48  * the J2EE server in the SerialContextProviderImpl object, which is
49  * accessed over RMI-IIOP from clients.
50  */

51 public class SerialContext implements Context {
52
53     static Logger _logger=LogDomains.getLogger(LogDomains.JNDI_LOGGER);
54
55     static private NameParser myParser = new SerialNameParser();
56
57     private Hashtable myEnv;
58     private SerialContextProvider provider;
59     private static Hashtable providerCache = new Hashtable();
60     private String JavaDoc myName;
61     private javaURLContext javaUrlContext = null;
62
63     private final static String JavaDoc JAVA_URL = "java:";
64     private InitialContext cosContext;
65     private static Boolean JavaDoc threadlock = new Boolean JavaDoc(true);
66
67     private static ThreadLocal JavaDoc stickyContext = new ThreadLocal JavaDoc();
68
69     /**
70      * set and get methods for preserving stickiness.
71      * This is a temporary solution
72      * to store the sticky IC as a thread local variable.
73      * This sticky IC will be used by all classes that require a context
74      * object to do lookup (if LB is enabled)
75      * SerialContext.lookup() sets a value for the thread local variable
76      * (stickyContext) before performing th lookup in case LB is enabled.
77      * If not, the thread local variable is null.
78      * At the end of the SerialContext.lookup() method, the thread local
79      * variable gets set to null.
80      * So actually speaking, more than being a global variable for the
81      * entire thread, its global only during the execution of the
82      * SerialContext.lookup() method. bug 5050591
83      * This will be cleaned for the next release.
84      *
85      */

86     public static void setSticky(ThreadLocalIC var) {
87         stickyContext.set(var);
88     }
89
90     public static ThreadLocalIC getSticky() {
91         return (ThreadLocalIC) stickyContext.get();
92     }
93   
94   /**
95    * This method is called from SerialInitContextFactory & S1ASCtxFactory
96    * to check if sticky context is set.
97    */

98     public static Context getStickyContext() {
99         return getSticky().getStickyContext();
100     }
101
102
103     /**
104      * method to narrow down the provider.
105      * common code that is called from getProvider()
106      */

107     private SerialContextProvider narrowProvider(org.omg.CORBA.Object JavaDoc ref)
108                        throws Exception JavaDoc {
109
110         NamingContext JavaDoc nctx = NamingContextHelper.narrow(ref);
111     NameComponent JavaDoc[] path =
112     { new NameComponent JavaDoc("SerialContextProvider", "") };
113     synchronized (threadlock) {
114         provider = (SerialContextProvider)
115           PortableRemoteObject.narrow(nctx.resolve(path),
116                       SerialContextProvider.class);
117     }
118     return provider;
119     }
120
121
122     private SerialContextProvider getProvider()
123     throws NamingException {
124
125     try {
126         if (provider == null) {
127         if (Switch.getSwitch().getContainerType() ==
128             Switch.EJBWEB_CONTAINER) {
129             if (_logger.isLoggable(Level.FINE)) {
130             _logger.fine("lookup call inside the server VM...");
131             }
132             provider = Switch.getSwitch().getProviderManager().getLocalProvider();
133             
134         } else {
135             if (_logger.isLoggable(Level.FINE)) {
136             _logger.fine("lookup call outside the server VM...");
137             }
138             
139             // get SerialContextProvider from naming service
140

141             // Get orb to use for connecting to NameService
142
ORB JavaDoc orb = (ORB JavaDoc) myEnv.get(ORBManager.JNDI_CORBA_ORB_PROPERTY);
143             
144             if ( orb == null ) {
145             orb = ORBManager.getORB();
146             }
147             
148             if (_logger.isLoggable(Level.FINE))
149             print(orb);
150             
151             org.omg.CORBA.Object JavaDoc ref = null;
152             //if the following is not null, then we are in EE world
153
//else PE
154
if (myEnv.get("com.sun.appserv.ee.iiop.endpointslist") != null) {
155             
156             ref = orb.string_to_object((String JavaDoc)(myEnv.get(
157                          "com.sun.appserv.ee.iiop.endpointslist")));
158             provider = narrowProvider(ref);
159             
160             } else {
161             provider = (SerialContextProvider) providerCache.get(orb);
162             if (provider == null) {
163                 ref = orb.resolve_initial_references("NameService");
164                 provider = narrowProvider(ref);
165                 providerCache.put(orb, provider);
166             }
167             }
168         }
169         }
170     } catch (Exception JavaDoc ex) {
171         setSticky(null);
172         CommunicationException ce = new CommunicationException
173         ("Can't find SerialContextProvider");
174         ce.initCause(ex);
175         throw ce;
176     }
177     
178     return provider;
179     }
180     
181     //internal API for logging
182
public void print(ORB JavaDoc orb) {
183         _logger.fine("SerialContext ==> SerialContext instance created : " + this);
184
185     if (orb != null) {
186         _logger.fine("SerialContext ==> ORB instance : " + orb);
187
188         String JavaDoc host = ((com.sun.corba.ee.impl.orb.ORBImpl)orb).
189           getORBData().getORBInitialHost();
190         int port = ((com.sun.corba.ee.impl.orb.ORBImpl)orb).
191           getORBData().getORBInitialPort();
192         
193         _logger.fine("SerialContext ==> ORB HOST : " + host +
194                    ", ORB PORT : " + port);
195     } else _logger.fine("orb is null");
196     }
197
198     /**
199      * Constructor for the context. Initializes the object reference
200      * to the remote provider object.
201      */

202     public SerialContext(Hashtable environment) throws NamingException {
203      
204         myEnv = (environment != null)
205         ? (Hashtable)(environment.clone())
206         : null;
207       
208     // Dont initialize provider now, this throws an exception
209
// if J2EEServer is not yet started. Get it lazily when needed.
210
//provider = SerialContext.getProvider(myEnv);
211

212     this.myName = "";
213     if (_logger.isLoggable(Level.FINE))
214         _logger.fine("SerialContext ==> SerialContext instance created : " + this);
215     javaUrlContext = new javaURLContext(myEnv, this);
216     }
217     
218     /**
219      * This constructor takes the component id as an argument. All
220      * name arguments to operations are prepended by the component id.
221      */

222     public SerialContext(String JavaDoc name, Hashtable env) throws NamingException {
223     this(env);
224     this.myName = name;
225     }
226
227
228     /**
229      * The getNameInNamespace API is not supported in this context.
230      * @exception NamingException if there is a naming exception.
231      */

232     public String JavaDoc getNameInNamespace() throws NamingException {
233     return myName;
234     }
235
236     /**
237      * method to check if the name to look up starts with "java:"
238      */

239     private boolean isjavaURL(String JavaDoc name) {
240      
241         if (name.startsWith(JAVA_URL)) {
242         return true;
243     } else return false;
244     }
245
246     /**
247      * Generates an entry context and give it to ondemand initialization framework.
248      */

249     public void generateEntryContext(Object JavaDoc context) {
250         ServerEntryHelper.generateJndiEntryContext((String JavaDoc) context);
251     }
252
253     /**
254      * method for checking the count and decrementing it
255      * also resets the sticky context to null if count is 0
256      */

257     private void resetSticky() {
258         if (getSticky() != null) {
259         getSticky().decrementCount();
260     
261         if (getSticky().getStickyCount() == 0) {
262             setSticky(null);
263         }
264     }
265     }
266     
267     /**
268      * Lookup the specified name in the context.
269      * Returns the resolved object.
270      * @return the resolved object.
271      * @exception NamingException if there is a naming exception.
272      */

273     public Object JavaDoc lookup(String JavaDoc name) throws NamingException {
274
275         //Before enything call ondemand initialization framework.
276
generateEntryContext(name);
277
278         /**
279      * In case a user is creating an IC with env passed
280      * in constructor; env specifies endpoints in some form
281      * in that case, the sticky IC should be stores as a thread local
282      * variable.
283      *
284      */

285         if (myEnv.get("com.sun.appserv.ee.iiop.endpointslist") != null) {
286         if (getSticky() == null) {
287             ThreadLocalIC threadLocal = new ThreadLocalIC(this,1);
288         setSticky(threadLocal);
289         } else getSticky().incrementCount();
290     }
291
292         if (_logger.isLoggable(Level.FINE))
293         _logger.fine("SerialContext ==> doing lookup with " + this);
294         if (name.equals("")) {
295         resetSticky();
296             // Asking to look up this context itself. Create and return
297
// a new instance with its own independent environment.
298
return (new SerialContext(myName, myEnv));
299         }
300     name = getRelativeName(name);
301         if (_logger.isLoggable(Level.FINE))
302         _logger.fine("SerialContext ==> looking up : " + name);
303
304         try {
305         if (isjavaURL(name)) {
306             resetSticky();
307         return javaUrlContext.lookup(name);
308         } else {
309         Object JavaDoc obj = getProvider().lookup(name);
310         if(obj instanceof Context) {
311             resetSticky();
312             return new SerialContext(name, myEnv);
313         }
314         Object JavaDoc retObj =
315             javax.naming.spi.NamingManager.getObjectInstance(obj,
316                                      new CompositeName(name),
317                                      null, myEnv);
318         resetSticky();
319
320         return retObj;
321         }
322     } catch (NamingException nnfe) {
323         setSticky(null);
324         throw nnfe;
325     } catch (Exception JavaDoc ex) {
326         setSticky(null);
327             _logger.log(Level.SEVERE,
328                         "enterprise_naming.serialctx_communication_exception",
329                         ex);
330         //temp fix for 6320008
331
//this should be removed once we change the transient NS implementation to persistent
332
if (ex instanceof java.rmi.MarshalException JavaDoc &&
333         ex.getCause() instanceof org.omg.CORBA.COMM_FAILURE JavaDoc) {
334             provider = null;
335         _logger.fine("Resetting provider to NULL. Will get new obj ref for provider since previous obj ref was stale...");
336         return lookup(name);
337         } else {
338             CommunicationException ce =
339           new CommunicationException("serial context communication ex");
340         ce.initCause(ex);
341         throw ce;
342         }
343     }
344     
345     }
346
347     /**
348
349      * Lookup the specifed name in the context.
350      * Returns the resolved object.
351      * @return the resolved object.
352      * @exception NamingException if there is a naming exception.
353      */

354     public Object JavaDoc lookup(Name name) throws NamingException {
355         // Flat namespace; no federation; just call string version
356
return lookup(name.toString());
357     }
358
359     /**
360      * Bind the object to the specified name.
361      * @param the name that the object is being bound to.
362      * @param the object that is being bound.
363      * @exception NamingException if there is a naming exception.
364      */

365     public void bind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
366
367     name = getRelativeName(name);
368     if (isjavaURL(name)) {
369         javaUrlContext.bind(name, obj);
370     } else {
371         try {
372             getProvider().bind(name, obj);
373         } catch (RemoteException JavaDoc ex) {
374             throw new CommunicationException(ex.toString());
375         }
376     }
377     }
378
379     /**
380      * Bind the object to the specified name.
381      * @param the name that the object is being bound to.
382      * @param the object that is being bound.
383      * @exception NamingException if there is a naming exception.
384      */

385     public void bind(Name name, Object JavaDoc obj) throws NamingException {
386         // Flat namespace; no federation; just call string version
387
bind(name.toString(), obj);
388     }
389
390     /**
391      * Rebind the object to the specified name.
392      * @param the name that the object is being bound to.
393      * @param the object that is being bound.
394      * @exception NamingException if there is a naming exception.
395      */

396     public void rebind(String JavaDoc name, Object JavaDoc obj) throws NamingException {
397     
398     name = getRelativeName(name);
399     if (isjavaURL(name)) {
400         javaUrlContext.rebind(name, obj);
401     } else {
402         try {
403             getProvider().rebind(name, obj);
404         } catch (RemoteException JavaDoc ex) {
405           throw new CommunicationException(ex.toString());
406         }
407     }
408     }
409
410     /**
411      * Rebind the object to the specified name.
412      * @param the name that the object is being bound to.
413      * @param the object that is being bound.
414      * @exception NamingException if there is a naming exception.
415      */

416     public void rebind(Name name, Object JavaDoc obj) throws NamingException {
417         // Flat namespace; no federation; just call string version
418
rebind(name.toString(), obj);
419     }
420
421     /**
422      * Unbind the object with the specified name.
423      * @param the name that is being unbound.
424      * @exception NamingException if there is a naming exception.
425      */

426     public void unbind(String JavaDoc name) throws NamingException {
427     name = getRelativeName(name);
428     if (isjavaURL(name)) {
429         javaUrlContext.unbind(name);
430     } else {
431         try {
432             getProvider().unbind(name);
433         } catch (RemoteException JavaDoc ex) {
434             throw new CommunicationException(ex.toString());
435         }
436     }
437     }
438
439     /**
440      * Unbind the object with the specified name.
441      * @param the name that is being unbound.
442      * @exception NamingException if there is a naming exception.
443      */

444     public void unbind(Name name) throws NamingException {
445         // Flat namespace; no federation; just call string version
446
unbind(name.toString());
447     }
448
449     /**
450      * Rename the bound object.
451      * @param the old name that the object is bound as.
452      * @param the new name that the object will be bound as.
453      * @exception NamingException if there is a naming exception.
454      */

455     public void rename(String JavaDoc oldname, String JavaDoc newname) throws NamingException {
456     oldname = getRelativeName(oldname);
457     newname = getRelativeName(newname);
458     if (isjavaURL(oldname)) {
459         javaUrlContext.rename(oldname, newname);
460     } else {
461         try {
462             getProvider().rename(oldname, newname);
463         } catch (RemoteException JavaDoc ex) {
464             throw new CommunicationException(ex.toString());
465         }
466     }
467     }
468
469     /**
470      * Rename the bound object.
471      * @param the old name that the object is bound as.
472      * @param the new name that the object will be bound as.
473      * @exception NamingException if there is a naming exception.
474      */

475     public void rename(Name oldname, Name newname)
476             throws NamingException {
477         // Flat namespace; no federation; just call string version
478
rename(oldname.toString(), newname.toString());
479     }
480
481     /**
482      * List the contents of the specified context.
483      * @return an enumeration of the contents.
484      * @param the context name.
485      * @exception NamingException if there is a naming exception.
486      */

487     public NamingEnumeration list(String JavaDoc name) throws NamingException {
488         if (name.equals("")) {
489             // listing this context
490
try {
491                 Hashtable bindings = getProvider().list(myName);
492                 return new RepNames(bindings);
493             } catch (RemoteException JavaDoc ex) {
494                 throw new CommunicationException(ex.toString());
495             }
496         }
497
498     name = getRelativeName(name);
499     if (isjavaURL(name)) {
500         return javaUrlContext.list(name);
501     } else {
502         // Perhaps 'name' names a context
503
Object JavaDoc target = lookup(name);
504         if (target instanceof Context) {
505             return ((Context)target).list("");
506         }
507         throw new NotContextException(name + " cannot be listed");
508     }
509     }
510
511     /**
512      * List the contents of the specified context.
513      * @return an enumeration of the contents.
514      * @param the context name.
515      * @exception NamingException if there is a naming exception.
516      */

517     public NamingEnumeration list(Name name)
518             throws NamingException {
519         // Flat namespace; no federation; just call string version
520
return list(name.toString());
521     }
522
523     /**
524      * List the bindings in the specified context.
525      * @return an enumeration of the bindings.
526      * @param the context name.
527      * @exception NamingException if there is a naming exception.
528      */

529     public NamingEnumeration listBindings(String JavaDoc name)
530             throws NamingException {
531         if (name.equals("")) {
532             // listing this context
533
try {
534                 Hashtable bindings = getProvider().list(myName);
535                 return new RepBindings(bindings);
536             } catch (RemoteException JavaDoc ex) {
537                 CommunicationException ce =
538                     new CommunicationException(ex.toString());
539                 ce.initCause(ex);
540                 throw ce;
541             }
542         }
543
544     name = getRelativeName(name);
545     if (isjavaURL(name)) {
546         return javaUrlContext.listBindings(name);
547     } else {
548         // Perhaps 'name' names a context
549
Object JavaDoc target = lookup(name);
550         if (target instanceof Context) {
551             return ((Context)target).listBindings("");
552         }
553         throw new NotContextException(name + " cannot be listed");
554     }
555     }
556
557     /**
558      * List the bindings in the specified context.
559      * @return an enumeration of the bindings.
560      * @param the context name.
561      * @exception NamingException if there is a naming exception.
562      */

563     public NamingEnumeration listBindings(Name name)
564             throws NamingException {
565         // Flat namespace; no federation; just call string version
566
return listBindings(name.toString());
567     }
568
569     /**
570      * Destroy the specified subcontext.
571      * @param the name of the subcontext.
572      * @exception NamingException if there is a naming exception.
573      */

574     public void destroySubcontext(String JavaDoc name) throws NamingException {
575     name = getRelativeName (name);
576     if (isjavaURL(name)) {
577         javaUrlContext.destroySubcontext(name);
578     } else {
579         try {
580             getProvider().destroySubcontext(name);
581         } catch(RemoteException JavaDoc e) {
582             CommunicationException ce =
583           new CommunicationException(e.toString());
584         ce.initCause(e);
585         throw ce;
586         }
587     }
588     }
589
590     /**
591      * Destroy the specified subcontext.
592      * @param the name of the subcontext.
593      * @exception NamingException if there is a naming exception.
594      */

595     public void destroySubcontext(Name name) throws NamingException {
596         // Flat namespace; no federation; just call string version
597
destroySubcontext(name.toString());
598     }
599
600     /**
601      * Create the specified subcontext.
602      * @return the created subcontext.
603      * @param the name of the subcontext.
604      * @exception NamingException if there is a naming exception.
605      */

606     public Context createSubcontext(String JavaDoc name)
607             throws NamingException {
608     Context c = null;
609     name = getRelativeName (name);
610     if (isjavaURL(name)) {
611         return javaUrlContext.createSubcontext(name);
612     } else {
613         try {
614             c = getProvider().createSubcontext(name);
615         /* this simulates the transient context structure on the
616          * client side. Have to do this - as reference to
617          * Transient Context is not resolved properly due to rmi
618          */

619         if (c instanceof Context){
620             c = new SerialContext (name, myEnv);
621         }
622         } catch(RemoteException JavaDoc e) {
623             CommunicationException ce =
624           new CommunicationException(e.toString());
625         ce.initCause(e);
626         throw ce;
627         }
628         return c;
629     }
630     }
631
632     /**
633      * Create the specified subcontext.
634      * @return the created subcontext.
635      * @param the name of the subcontext.
636      * @exception NamingException if there is a naming exception.
637      */

638     public Context createSubcontext(Name name) throws NamingException {
639         // Flat namespace; no federation; just call string version
640
return createSubcontext(name.toString());
641     }
642
643     /**
644      * Links are not treated specially.
645      * @param the name of the link.
646      * @return the resolved object.
647      * @exception NamingException if there is a naming exception.
648      */

649     public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException {
650     name = getRelativeName(name);
651     if (isjavaURL(name)) {
652         return javaUrlContext.lookupLink(name);
653     } else {
654             // This flat context does not treat links specially
655
return lookup(name);
656     }
657     }
658
659     /**
660      * Links are not treated specially.
661      * @param the name of the link.
662      * @return the resolved object.
663      * @exception NamingException if there is a naming exception.
664      */

665     public Object JavaDoc lookupLink(Name name) throws NamingException {
666         // Flat namespace; no federation; just call string version
667
return lookupLink(name.toString());
668     }
669
670     /**
671      * Allow access to the name parser object.
672      * @param String JNDI name, is ignored since there is only one Name
673      * Parser object.
674      * @exception NamingException
675      * @return NameParser object
676      */

677     public NameParser getNameParser(String JavaDoc name)
678             throws NamingException {
679         return myParser;
680     }
681
682     /**
683      * Allow access to the name parser object.
684      * @param String JNDI name, is ignored since there is only one Name
685      * Parser object.
686      * @exception NamingException
687      * @return NameParser object
688      */

689     public NameParser getNameParser(Name name) throws NamingException {
690         // Flat namespace; no federation; just call string version
691
return getNameParser(name.toString());
692     }
693
694     public String JavaDoc composeName(String JavaDoc name, String JavaDoc prefix)
695             throws NamingException {
696         Name result = composeName(new CompositeName(name),
697                                   new CompositeName(prefix));
698         return result.toString();
699     }
700
701     public Name composeName(Name name, Name prefix)
702             throws NamingException {
703         Name result = (Name)(prefix.clone());
704         result.addAll(name);
705         return result;
706     }
707
708     /**
709      * Add to the environment for the current context.
710      * @exception NamingException if there is a naming exception.
711      */

712     public Object JavaDoc addToEnvironment(String JavaDoc propName, Object JavaDoc propVal)
713             throws NamingException {
714         if (myEnv == null) {
715             myEnv = new Hashtable(5, 0.75f);
716         }
717         return myEnv.put(propName, propVal);
718     }
719
720     /**
721      * Remove from the environment for the current context.
722      * @exception NamingException if there is a naming exception.
723      */

724     public Object JavaDoc removeFromEnvironment(String JavaDoc propName)
725         throws NamingException {
726         if (myEnv == null) {
727             return null;
728         }
729         return myEnv.remove(propName);
730     }
731
732     /**
733      * Return the environment for the current context.
734      * @exception NamingException if there is a naming exception.
735      */

736     public Hashtable getEnvironment() throws NamingException {
737         if (myEnv == null) {
738             // Must return non-null
739
myEnv = new Hashtable(3, 0.75f);
740         }
741         return myEnv;
742     }
743
744     /**
745      * Set the environment for the current context to null when close is
746      * called.
747      * @exception NamingException if there is a naming exception.
748      */

749     public void close() throws NamingException {
750         myEnv = null;
751     }
752
753     private String JavaDoc getRelativeName(String JavaDoc name) {
754     if(!myName.equals("")) {
755         name = myName + "/" + name;
756     }
757     return name;
758     }
759
760     // Class for enumerating name/class pairs
761
class RepNames implements NamingEnumeration {
762         Hashtable bindings;
763         Enumeration names;
764
765         RepNames (Hashtable bindings) {
766             this.bindings = bindings;
767             this.names = bindings.keys();
768         }
769
770         public boolean hasMoreElements() {
771             return names.hasMoreElements();
772         }
773
774         public boolean hasMore() throws NamingException {
775             return hasMoreElements();
776         }
777
778         public Object JavaDoc nextElement() {
779             if(names.hasMoreElements())
780             {
781                 String JavaDoc name = (String JavaDoc)names.nextElement();
782                 String JavaDoc className = bindings.get(name).getClass().getName();
783                 return new NameClassPair(name, className);
784             }
785             else
786                 return null;
787         }
788
789         public Object JavaDoc next() throws NamingException {
790             return nextElement();
791         }
792
793         // New API for JNDI 1.2
794
public void close() throws NamingException {
795             throw new OperationNotSupportedException("close() not implemented");
796         }
797     }
798
799     // Class for enumerating bindings
800
class RepBindings implements NamingEnumeration {
801         Enumeration names;
802         Hashtable bindings;
803
804         RepBindings (Hashtable bindings) {
805             this.bindings = bindings;
806             this.names = bindings.keys();
807         }
808
809         public boolean hasMoreElements() {
810             return names.hasMoreElements();
811         }
812
813         public boolean hasMore() throws NamingException {
814             return hasMoreElements();
815         }
816
817         public Object JavaDoc nextElement() {
818             if(hasMoreElements())
819             {
820                 String JavaDoc name = (String JavaDoc)names.nextElement();
821                 return new Binding(name, bindings.get(name));
822             }
823             else
824                 return null;
825         }
826
827         public Object JavaDoc next() throws NamingException {
828             return nextElement();
829         }
830
831         // New API for JNDI 1.2
832
public void close() throws NamingException {
833             throw new OperationNotSupportedException("close() not implemented");
834         }
835     }
836
837
838   /**
839    * This is a temporary solution to store
840    * the sticky context as a threadlocal variable. bug 5050591
841    * context is the sticky context
842    * count is needed to know how many times the lookup method is being called
843    * from within the user code's ic.lookup(). e.g. JMS resource lookups (via ConnectorObjectFactory)
844    */

845    class ThreadLocalIC {
846
847         Context ctx;
848         int count = 0;
849
850         public ThreadLocalIC(Context ctx, int count) {
851         this.ctx = ctx;
852         this.count = count;
853     }
854
855         public void setStickyContext(Context ctx) {
856         ctx = ctx;
857     }
858     
859         public Context getStickyContext() {
860         return ctx;
861     }
862     
863         public void setStickyCount(int count) {
864         count = count;
865       
866     }
867
868         public int getStickyCount() {
869       return count;
870     }
871
872         public void incrementCount() {
873         count++;
874     }
875
876         public void decrementCount() {
877         count--;
878     }
879     }
880 };
881
882
883
Popular Tags