All Examples This Package
java.lang.Object | +----examples.jndi.WebLogicContextExample
The example first creates a default naming context, then binds an object into that context under a newly created subcontext, and finally looks up the object. Note that the binding created here will be available for the life of the server to any client that obtains a WebLogic InitialContext through the same server.
Build the example:
$ javac -d %CLIENT_CLASSES% WebLogicContextExample.java
$ java examples.jndi.WebLogicContextExample t3://hostname:portwhere:
Try running this example a second time within the same WebLogic Server session. Note that although the JDNI binding has already been created (the first time you ran this example), no exception in thrown when the subcontext is re-created. WebLogic's context implementation does not throw an exception if the object that is bound to an existing name is identical to the current object that is bound to that name. This example generates a unique string (using the date) for the bound object. When binding this object for the second time, an NameAlreadyBoundException is thrown since the object is not identical to the object that is currently bound to the same name. Now, the rebind() method must be used to successfully bind the new object.
The key to creating an InitialContext is correctly specifying the required properties. The java.naming.factory.initial property (referred to here via the static InitialContext.INITIAL_CONTEXT_FACTORY) specifies the factory that is used to create the context. Other properties (like java.naming.provider.url) are used to pass on parameters to the specified factory.
These properties can either be provided as system properties or passed explicitly to the InitialContext constructor. This example creates and passes the properties explicitly for clarity. Note that passing the properties explicitly is the only alternative when working in an applet, since an applet is not allowed to modify or read all system properties.
@author Copyright (c) 1998-2000 by BEA Systems, Inc. All Rights Reserved.
public WebLogicContextExample()
public static void main(String args[])
All Examples This Package