FileDocCategorySizeDatePackage
InitialLdapContext.javaAPI DocJava SE 5 API6798Fri Aug 26 14:57:40 BST 2005javax.naming.ldap

InitialLdapContext

public class InitialLdapContext extends InitialDirContext implements LdapContext
This class is the starting context for performing LDAPv3-style extended operations and controls.

See javax.naming.InitialContext and javax.naming.InitialDirContext for details on synchronization, and the policy for how an initial context is created.

Request Controls

When you create an initial context (InitialLdapContext), you can specify a list of request controls. These controls will be used as the request controls for any implicit LDAP "bind" operation performed by the context or contexts derived from the context. These are called connection request controls. Use getConnectControls() to get a context's connection request controls.

The request controls supplied to the initial context constructor are not used as the context request controls for subsequent context operations such as searches and lookups. Context request controls are set and updated by using setRequestControls().

As shown, there can be two different sets of request controls associated with a context: connection request controls and context request controls. This is required for those applications needing to send critical controls that might not be applicable to both the context operation and any implicit LDAP "bind" operation. A typical user program would do the following:

InitialLdapContext lctx = new InitialLdapContext(env, critConnCtls);
lctx.setRequestControls(critModCtls);
lctx.modifyAttributes(name, mods);
Controls[] respCtls = lctx.getResponseControls();
It specifies first the critical controls for creating the initial context (critConnCtls), and then sets the context's request controls (critModCtls) for the context operation. If for some reason lctx needs to reconnect to the server, it will use critConnCtls. See the LdapContext interface for more discussion about request controls.

Service provider implementors should read the "Service Provider" section in the LdapContext class description for implementation details.

author
Rosanna Lee
author
Scott Seligman
author
Vincent Ryan
version
1.12 04/07/16
see
LdapContext
see
javax.naming.InitialContext
see
javax.naming.directory.InitialDirContext
see
javax.naming.spi.NamingManager#setInitialContextFactoryBuilder
since
1.3

Fields Summary
private static final String
BIND_CONTROLS_PROPERTY
Constructors Summary
public InitialLdapContext()
Constructs an initial context using no environment properties or connection request controls. Equivalent to new InitialLdapContext(null, null).

throws
NamingException if a naming exception is encountered


                       	           
        
	super(null);
    
public InitialLdapContext(Hashtable environment, Control[] connCtls)
Constructs an initial context using environment properties and connection request controls. See javax.naming.InitialContext for a discussion of environment properties.

This constructor will not modify its parameters or save references to them, but may save a clone or copy.

connCtls is used as the underlying context instance's connection request controls. See the class description for details.

param
environment environment used to create the initial DirContext. Null indicates an empty environment.
param
connCtls connection request controls for the initial context. If null, no connection request controls are used.
throws
NamingException if a naming exception is encountered
see
#reconnect
see
LdapContext#reconnect

	super(true); // don't initialize yet

	// Clone environment since caller owns it.
	Hashtable env = (environment == null)
	    ? new Hashtable(11)
	    : (Hashtable)environment.clone();

	// Put connect controls into environment.  Copy them first since
	// caller owns the array.
	if (connCtls != null) {
	    Control[] copy = new Control[connCtls.length];
	    System.arraycopy(connCtls, 0, copy, 0, connCtls.length);
	    env.put(BIND_CONTROLS_PROPERTY, copy);
	}
	// set version to LDAPv3
	env.put("java.naming.ldap.version", "3");

	// Initialize with updated environment
	init(env);
    
Methods Summary
public javax.naming.ldap.ExtendedResponseextendedOperation(javax.naming.ldap.ExtendedRequest request)

	return getDefaultLdapInitCtx().extendedOperation(request);
    
public javax.naming.ldap.Control[]getConnectControls()

	return getDefaultLdapInitCtx().getConnectControls();
    
private javax.naming.ldap.LdapContextgetDefaultLdapInitCtx()
Retrieves the initial LDAP context.

return
The non-null cached initial context.
exception
NotContextException If the initial context is not an instance of LdapContext.
exception
NamingException If a naming exception was encountered.

	Context answer = getDefaultInitCtx();

	if (!(answer instanceof LdapContext)) {
	    if (answer == null) {
		throw new NoInitialContextException();
	    } else {
		throw new NotContextException(
		    "Not an instance of LdapContext");
	    }
	}
	return (LdapContext)answer;
    
public javax.naming.ldap.Control[]getRequestControls()

	return getDefaultLdapInitCtx().getRequestControls();
    
public javax.naming.ldap.Control[]getResponseControls()

	return getDefaultLdapInitCtx().getResponseControls();
    
public javax.naming.ldap.LdapContextnewInstance(javax.naming.ldap.Control[] reqCtls)

	    return getDefaultLdapInitCtx().newInstance(reqCtls);
    
public voidreconnect(javax.naming.ldap.Control[] connCtls)

	getDefaultLdapInitCtx().reconnect(connCtls);
    
public voidsetRequestControls(javax.naming.ldap.Control[] requestControls)

	    getDefaultLdapInitCtx().setRequestControls(requestControls);