com.ca.commons.jndi.beans
Class FixedDirContextFactory

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

public final class FixedDirContextFactory
extends Object
implements DirContextFactory

A directory context factory that always produces the same context instance. This approach minimizes the cost of creating a new context, as this is only done once. Use of this class assumes that a context will remain valid for the entire life of the JNDIBeanStore object that is using this factory.

There are two ways to configure this factory. Either provide a pre-existing context directly via the setContext(javax.naming.directory.DirContext) method, or provide a JNDI environment to the setJNDIEnv(java.util.Properties) method.

See Also:
JNDIBeanStore

Constructor Summary
FixedDirContextFactory()
           
 
Method Summary
 void close()
          Closes this factory's directory context.
 DirContext getContext()
          Returns the directory context previously established by either the setJNDIEnv or setContext methods.
 void returnContext(DirContext ctx)
          Called to indicate that a DirContext previously provided by this factory is no longer needed.
 void setContext(DirContext ctx)
          Sets the directory context to be returned by this factory.
 void setJNDIEnv(Properties props)
          Sets the JNDI environment to use to create this factory's context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedDirContextFactory

public FixedDirContextFactory()
Method Detail

setJNDIEnv

public void setJNDIEnv(Properties props)
                throws NamingException
Sets the JNDI environment to use to create this factory's context. This method immediately uses the environment to create the context that will be returned by all subsequent calls to getContext. If this method is called, the setContext method should not be called.

Parameters:
props - A JNDI environment.
Throws:
NamingException - If the DirContext could not be created.
See Also:
InitialDirContext.InitialDirContext(java.util.Hashtable), getContext()

setContext

public void setContext(DirContext ctx)
Sets the directory context to be returned by this factory. If this method is called, the setJNDIEnv method shoudl not be called.


getContext

public DirContext getContext()
Returns the directory context previously established by either the setJNDIEnv or setContext methods.

Specified by:
getContext in interface DirContextFactory
See Also:
DirContextFactory.returnContext(javax.naming.directory.DirContext)

returnContext

public void returnContext(DirContext ctx)
Description copied from interface: DirContextFactory
Called to indicate that a DirContext previously provided by this factory is no longer needed.

Specified by:
returnContext in interface DirContextFactory
Parameters:
ctx - The DirContext previously returned by the getContext method.
See Also:
DirContextFactory.getContext()

close

public void close()
           throws NamingException
Closes this factory's directory context.

Specified by:
close in interface DirContextFactory
Throws:
NamingException - If an exception is thrown by the DirContext.close metohd.
See Also:
Context.close()


Created 2011-07-14 13:27 EST