The Artima Developer Community
Sponsored Link

Java Answers Forum
InitialContext.lookup() Problem

5 replies on 1 page. Most recent reply: Nov 11, 2005 8:40 AM by Xichen Li

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Xichen Li

Posts: 4
Nickname: jiucenglou
Registered: Nov, 2005

InitialContext.lookup() Problem Posted: Nov 10, 2005 9:55 PM
Reply to this message Reply
Advertisement
I am trying to figure out the mechanism of the InitialContext.lookup(). When I read the source code, it says as the following :

public Object lookup(String name) throws NamingException {
return getURLOrDefaultInitCtx(name).lookup(name);
}

While the "getURLOrDefaultInitCtx(name)" still returns a context reference, doesn't the code above look like an infinite loop?

I am confused!
Thanks!


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: InitialContext.lookup() Problem Posted: Nov 10, 2005 10:36 PM
Reply to this message Reply
That depends on what getURLOrDefaultInitCtx returns.

We can assume it will not return a InitialContext object.
Did you check what the lookup(..) implementation of InitialDirContext and InitialLdapContext returns?

Xichen Li

Posts: 4
Nickname: jiucenglou
Registered: Nov, 2005

Re: InitialContext.lookup() Problem Posted: Nov 10, 2005 10:42 PM
Reply to this message Reply
First of all, thank you very much.


I just browsed the api. The InitialDirContext and InitialLdapContext do not override the lookup() of the InitialContext.

Then what on earth can getURLOrDefaultInitCtx() return ?

Xichen Li

Posts: 4
Nickname: jiucenglou
Registered: Nov, 2005

Re: InitialContext.lookup() Problem Posted: Nov 10, 2005 10:53 PM
Reply to this message Reply
Also, after tracing the method calls, the exact type of what is returned depends on the following :

public Context getInitialContext(Hashtable environment)
throws NamingException;

of interface javax.naming.spi.InitialContextFactory.


I am more confused now.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: InitialContext.lookup() Problem Posted: Nov 11, 2005 1:37 AM
Reply to this message Reply
The two classes I mentioned where only examples from the API.

getURLOrDefaultInitCtx actually calls the getURLObject Method in NamingManager.

Did you actually try this method to see what it does, wich class the returned Object has?

You CAN read the whole Java source code to get your answer or you just try.

If you choose the first way, these are the key lines in NamingManager.getURLObject

ObjectFactory factory = (ObjectFactory)ResourceManager.getFactory( Context.URL_PKG_PREFIXES, environment, nameCtx, "." + scheme + "." + scheme + "URLContextFactory", defaultPkgPrefix);
factory.getObjectInstance(urlInfo, name, nameCtx, environment);

Xichen Li

Posts: 4
Nickname: jiucenglou
Registered: Nov, 2005

Re: InitialContext.lookup() Problem Posted: Nov 11, 2005 8:40 AM
Reply to this message Reply
Thanks very much again!
I have just finished my another try to struggle through the source code. :(
Feeling somewhat embarrassed to see kinds of concepts(e.g. the WeakReference in ref package and so on), I just have to say it might not yet be the time for me to work this out.
Anyway, thanks a lot. :) I will figure it out finally.

Flat View: This topic has 5 replies on 1 page
Topic: Tomcat problem Previous Topic   Next Topic Topic: MODEM Receive

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use