com.ca.commons.jndi.beans
Class StandardDirContextFactory

java.lang.Object
  extended by com.ca.commons.jndi.beans.StandardDirContextFactory
All Implemented Interfaces:
DirContextFactory

public final class StandardDirContextFactory
extends Object
implements DirContextFactory

A directory context factory that creates a new context every time one is requested. Every time getContext is called, a new DirContext is created, using the JNDI environment specified in a previous call to setJNDIEnv. Note that setJNDIEnv must be used to initialize this factory before passing it to the JNDIBeanStoreFactory.newBeanStore(DirContextFactory) method.

Use of this factory is likely to cause unnecessary communication overhead in practice, so using FixedDirContextFactory is generally a better choice.

See Also:
FixedDirContextFactory

Constructor Summary
StandardDirContextFactory()
           
 
Method Summary
 void close()
          Indicates that the JNDIBeanStore using this factory has been closed down.
 DirContext getContext()
          Creates a new DirContext.
 Properties getJNDIEnv()
          Returns the JNDI environment that is being used to create new DirContext instances.
 void returnContext(DirContext ctx)
          Closes the specified DirContext.
 void setJNDIEnv(Properties jndiEnv)
          Sets the JNDI environment to use to create new DirContext instances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardDirContextFactory

public StandardDirContextFactory()
Method Detail

getJNDIEnv

public Properties getJNDIEnv()
Returns the JNDI environment that is being used to create new DirContext instances.

See Also:
InitialDirContext.InitialDirContext(java.util.Hashtable)

setJNDIEnv

public void setJNDIEnv(Properties jndiEnv)
Sets the JNDI environment to use to create new DirContext instances.

Parameters:
jndiEnv - The environment that will be passed to the InitialDirContext.InitialDirContext(java.util.Hashtable) method.

getContext

public DirContext getContext()
                      throws NamingException
Creates a new DirContext. The JNDI environment previously set via the setJNDIEnv method is used to create the new context.

Specified by:
getContext in interface DirContextFactory
Throws:
NamingException - If a DirContext could not be established for any reason.
See Also:
setJNDIEnv(java.util.Properties)

returnContext

public void returnContext(DirContext ctx)
                   throws NamingException
Closes the specified DirContext. As this factory always produces a brand new context, this method closes any context that is no longer being used.

Specified by:
returnContext in interface DirContextFactory
Parameters:
ctx - The context that is no longer in use.
Throws:
NamingException - If there was a problem cleaning up the context.
See Also:
Context.close()

close

public void close()
Description copied from interface: DirContextFactory
Indicates that the JNDIBeanStore using this factory has been closed down. An implementation should free up any resources it is using.

Specified by:
close in interface DirContextFactory
See Also:
JNDIBeanStore.close()


Created 2011-07-14 13:27 EST