import javax.jms.*; import javax.naming.*; import javax.naming.directory.*; ... java.util.Hashtable environment =new java.util.Hashtable(); environment.put(Context.INITIAL_CONTEXT_FACTORY, icf); environment.put(Context.PROVIDER_URL, url); Context ctx = new InitialContext(environment );where:
environment.put(Context.REFERRAL,"throw");Once an initial context is obtained, objects can be stored in and retrieved from the namespace. To store an object, use the bind() method:
ctx.bind(entryName, object);where 'entryName' is the name under which you want the object stored, and 'object' is the object to be stored, for example to store a factory under the name "ivtQCF":
ctx.bind("ivtQCF", factory);To store an object in a JNDI namespace, the object must satisfy either the javax.naming.Referenceable interface or the java.io.Serializable interface, depending on the JNDI provider you use. The MQeJNDIQueueConnectionFactory and MQeJMSJNDIQueueclasses implement both of these interfaces. To retrieve an object from the namespace, use thelookup() method:
object = ctx.lookup(entryName);where entryName is the name under which you want the object stored , for example, to retrieve a QueueConnectionFactory stored under the name "ivtQCF":
QueueConnectionFactory factory; factory = (QueueConnectionFactory)ctx.lookup("ivtQCF");
Parent topic: Using Java Naming and Directory Interface (JNDI)