WebLogic Server Components

Sample Code

The following code is an example of creating an initial context to WebLogic JNDI from a stand-alone client:

HashMap env = new HashMap();

env.put (Context.PROVIDER_URL, "t3://localhost:7001/");

env.put (Context.INITIAL_CONTEXT_FACTORY,

"weblogic.jndi.WLInitialContextFactory");

Context initContext = new InitialContext (env);

...

Once an initial context is created, sub-contexts can be created, objects can be bound, and objects can be retrieved using the initial context. For example the following segment of code retrieves a Topic object:

Topic topic

=(Topic)initContext.lookup("sbyn.inTopicToSunMicrosystemsTopic");

...

Here's an example of how to bind a Sun Microsystems Queue object:

Queue queue = null;

try {

queue = new STCQueue("inQueueToSunMicrosystemsQueue");

initContext.bind ("sbyn.ToSunMicrosystemsQueue", queue);

}

catch (NameAlreadyBoundException ex)

{

try

{

if (queue != null)

initContext.rebind ("sbyn.ToSunMicrosystemsQueue", queue);

}

catch (Exception ex)

{

throw ex;

}

}