|
WebLogic Server 6.0 Code Examples, BEA Systems, Inc. | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--examples.jndi.WebLogicContextExample
This example illustrates how to obtain and use a WebLogic naming context. The same code will work on both a client and a server. If it is run on a client, it will delegate to a remote context running on the server specified by java.naming.provider.url. If it is run on the server specified by the java.naming.provider.url, a local context is used. If it is run on some other server, the context will again delegate to a context located on the server specified by java.naming.provider.url.
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.
The following sections cover what to do:
$ javac -d %CLIENT_CLASSES% WebLogicContextExample.java
In your development shell, run the client with the following command:
$ java examples.jndi.WebLogicContextExample t3://hostname:portwhere:
Try running this example a second time within the same WebLogic Server session. Note that although the JNDI binding has already been created (the first time you ran this example), no exception in thrown when the subcontext is recreated. 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.
Constructor Summary | |
WebLogicContextExample()
|
Method Summary | |
static void |
main(java.lang.String[] args)
Runs this example from the command line. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public WebLogicContextExample()
Method Detail |
public static void main(java.lang.String[] args)
|
Documentation is available at http://e-docs.bea.com/wls/docs60 |
|||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |