The javax.naming package contains the core
interfaces, classes, and exceptions for performing naming operations
with JNDI. Context represents named objects in a
naming system, while InitialContext provides an
entry point into a naming system. Binding is the
association between a name and an object in a naming
system. NamingException is the root of a large
collection of naming exceptions defined by JNDI. Figure 22-1 shows
the classes and interfaces of the javax.naming
package, while Figure 22-2 shows the exception hierarchy.
Figure 22-1. The classes and interfaces of the javax.naming package
Figure 22-2. The exception hierarchy of the javax.naming package
AuthenticationException
JNDI 1.1
javax.naming
serializable checked
Thrown when JNDI encounters an error authenticating to the naming system, such as when a bad username or password is used.
public class AuthenticationException extends NamingSecurityException {
//
Public Constructors
public AuthenticationException ();
public AuthenticationException (String explanation);
This class represents the association between a name and an object. The listBindings() method of Context returns a NamingEnumeration of Binding objects.
public class Binding extends NameClassPair {
//
Public Constructors
public Binding (String name, Object obj);
public Binding (String name, String className, Object obj);
public Binding (String name, Object obj, boolean isRelative);
public Binding (String name, String className, Object obj, boolean isRelative);
This class represents a sequence of names that span multiple namespaces. Each component of a CompositeName is a String name. The CompositeName does not know to which naming system each name component belongs. JNDI uses the forward slash character ("/") to separate constituent name components.
public class CompositeName implements Name {
//
Public Constructors
public CompositeName ();
public CompositeName (String n) throws InvalidNameException;
This interface represents an object in a naming system. A Context keeps track of a set of name-to-object bindings for its subordinates in the naming system, so it defines methods to examine and update these bindings. The lookup() method looks up a subordinate object, while list() and listBindings() provide access to all of the subordinates.
A Context only knows about its subordinates, not about itself or what is above it in the naming system. Thus, there are no methods to get the name of a Context or move up in the naming hierarchy.
public abstract interface Context {
//
Public Constants
public static final String AUTHORITATIVE ;
="java.naming.authoritative"
public static final String BATCHSIZE ;
="java.naming.batchsize"
public static final String DNS_URL ;
="java.naming.dns.url"
public static final String INITIAL_CONTEXT_FACTORY ;
="java.naming.factory.initial"
public static final String LANGUAGE ;
="java.naming.language"
public static final String OBJECT_FACTORIES ;
="java.naming.factory.object"
public static final String PROVIDER_URL ;
="java.naming.provider.url"
public static final String REFERRAL ;
="java.naming.referral"
public static final String SECURITY_AUTHENTICATION ;
="java.naming.security.authentication"
public static final String SECURITY_CREDENTIALS ;
="java.naming.security.credentials"
public static final String SECURITY_PRINCIPAL ;
="java.naming.security.principal"
public static final String SECURITY_PROTOCOL ;
="java.naming.security.protocol"
public static final String URL_PKG_PREFIXES ;
="java.naming.factory.url.pkgs"
//
Public Instance Methods
public abstract Object addToEnvironment (String propName, Object propVal) throws NamingException;
public abstract void bind (Name name, Object obj) throws NamingException;
public abstract void bind (String name, Object obj) throws NamingException;
public abstract void close () throws NamingException;
public abstract Name composeName (Name name, Name prefix) throws NamingException;
public abstract String composeName (String name, String prefix) throws NamingException;
public abstract javax.naming.Context createSubcontext (Name name) throws NamingException;
public abstract javax.naming.Context createSubcontext (String name) throws NamingException;
public abstract void destroySubcontext (Name name) throws NamingException;
public abstract void destroySubcontext (String name) throws NamingException;
public abstract java.util.Hashtable getEnvironment () throws NamingException;
public abstract NameParser getNameParser (Name name) throws NamingException;
public abstract NameParser getNameParser (String name) throws NamingException;
public abstract NamingEnumeration list (Name name) throws NamingException;
public abstract NamingEnumeration list (String name) throws NamingException;
public abstract NamingEnumeration listBindings (Name name) throws NamingException;
public abstract NamingEnumeration listBindings (String name) throws NamingException;
public abstract Object lookup (Name name) throws NamingException;
public abstract Object lookup (String name) throws NamingException;
public abstract Object lookupLink (Name name) throws NamingException;
public abstract Object lookupLink (String name) throws NamingException;
public abstract void rebind (Name name, Object obj) throws NamingException;
public abstract void rebind (String name, Object obj) throws NamingException;
public abstract Object removeFromEnvironment (String propName) throws NamingException;
public abstract void rename (Name oldName, Name newName) throws NamingException;
public abstract void rename (String oldName, String newName) throws NamingException;
public abstract void unbind (Name name) throws NamingException;
public abstract void unbind (String name) throws NamingException;
Passed To: CannotProceedException.setAltNameCtx(), javax.naming.spi.NamingManager.getObjectInstance(), javax.naming.spi.ObjectFactory.getObjectInstance()
This class represents the starting point for accessing a naming system.
Typically, you set the value of the
java.naming.factory.initial property (represented by
the constant Context.INITIAL_CONTEXT_FACTORY) to the
fully qualified package name of a factory class in a JNDI service
provider. This factory class creates an
InitialContext that is appropriate for the naming
system you are using.
public class InitialContext implements javax.naming.Context {
//
Public Constructors
public InitialContext () throws NamingException;
public InitialContext (java.util.Hashtable environment) throws NamingException;
//
Methods implementing Context
public Object addToEnvironment (String propName, Object propVal) throws NamingException;
public void bind (String name, Object obj) throws NamingException;
public void bind (Name name, Object obj) throws NamingException;
public void close () throws NamingException;
public String composeName (String name, String prefix) throws NamingException;
public Name composeName (Name name, Name prefix) throws NamingException;
public javax.naming.Context createSubcontext (String name) throws NamingException;
public javax.naming.Context createSubcontext (Name name) throws NamingException;
public void destroySubcontext (Name name) throws NamingException;
public void destroySubcontext (String name) throws NamingException;
public java.util.Hashtable getEnvironment () throws NamingException;
public NameParser getNameParser (String name) throws NamingException;
public NameParser getNameParser (Name name) throws NamingException;
public NamingEnumeration list (Name name) throws NamingException;
public NamingEnumeration list (String name) throws NamingException;
public NamingEnumeration listBindings (Name name) throws NamingException;
public NamingEnumeration listBindings (String name) throws NamingException;
public Object lookup (Name name) throws NamingException;
public Object lookup (String name) throws NamingException;
public Object lookupLink (Name name) throws NamingException;
public Object lookupLink (String name) throws NamingException;
public void rebind (Name name, Object obj) throws NamingException;
public void rebind (String name, Object obj) throws NamingException;
public Object removeFromEnvironment (String propName) throws NamingException;
public void rename (Name oldName, Name newName) throws NamingException;
public void rename (String oldName, String newName) throws NamingException;
public void unbind (Name name) throws NamingException;
public void unbind (String name) throws NamingException;
This interface represents the name of an object in a naming system. A Name can be either a compound name or a composite name. This interface is used primarily by developers who are writing JNDI service providers, not by JNDI application developers. As an application developer, you can use String objects instead of Name objects to specify names in Context and javax.naming.directory.DirContext method calls.
public abstract interface Name extends Cloneable, Serializable {
//
Public Instance Methods
public abstract Name add (String comp) throws InvalidNameException;
public abstract Name add (int posn, String comp) throws InvalidNameException;
public abstract Name addAll (Name suffix) throws InvalidNameException;
public abstract Name addAll (int posn, Name n) throws InvalidNameException;
public abstract Object clone ();
public abstract int compareTo (Object obj);
public abstract boolean endsWith (Name n);
public abstract String get (int posn);
public abstract java.util.Enumeration getAll ();
public abstract Name getPrefix (int posn);
public abstract Name getSuffix (int posn);
public abstract boolean isEmpty ();
public abstract Object remove (int posn) throws InvalidNameException;
public abstract int size ();
public abstract boolean startsWith (Name n);
}
Hierarchy: (Name(Cloneable,Serializable))
Implementations: CompositeName, CompoundName
Passed To: Too many methods to list.
Returned By: Too many methods to list.
Type Of: CannotProceedException.{altName, remainingNewName}, LinkException.{linkRemainingName, linkResolvedName}, NamingException.{remainingName, resolvedName}, javax.naming.spi.ResolveResult.remainingName
NameAlreadyBoundException
JNDI 1.1
javax.naming
serializable checked
Thrown when a binding operation fails because the name is already bound.
public class NameAlreadyBoundException extends NamingException {
//
Public Constructors
public NameAlreadyBoundException ();
public NameAlreadyBoundException (String explanation);
This class represents the name and class of an object bound to a Context. The list() method of Context returns an NamingEnumeration of NameClassPair objects. Note that NameClassPair does not represent the object itself; that is the job of its subclass Binding.
public class NameClassPair implements Serializable {
//
Public Constructors
public NameClassPair (String name, String className);
public NameClassPair (String name, String className, boolean isRelative);
//
Public Instance Methods
public String getClassName ();
public String getName ();
public boolean isRelative ();
public void setClassName (String name);
public void setName (String name);
public void setRelative (boolean r);
//
Public methods overriding Object
public String toString ();
}
Hierarchy: Object-->NameClassPair(Serializable)
Subclasses: javax.naming.Binding
NameNotFoundException
JNDI 1.1
javax.naming
serializable checked
Thrown when a component of a name cannot be resolved because it is not bound.
public class NameNotFoundException extends NamingException {
//
Public Constructors
public NameNotFoundException ();
public NameNotFoundException (String explanation);
This interface is for parsing names from a hierarchical namespace.
A NameParser knows the syntactic information, such as
left-to-right orientation and the name separator, needed to parse
names.
public abstract interface NameParser {
//
Public Instance Methods
public abstract Name parse (String name) throws NamingException;
}
Returned By: javax.naming.Context.getNameParser(), InitialContext.getNameParser()
NamingEnumeration
JNDI 1.1
javax.naming
This interface represents a list of items returned from a JNDI operation. It extends java.util.Enumeration, so a NamingEnumeration can be treated as a normal enumeration.
public abstract interface NamingEnumeration extends java.util.Enumeration {
//
Public Instance Methods
public abstract boolean hasMore () throws NamingException;
public abstract Object next () throws NamingException;
The base class of all exceptions thrown by Context and javax.naming.directory.DirContext methods. NamingException can include information about where the operation failed, such as the portion of a name that has been resolved and the portion that remains to be resolved. A NamingException can also include a root cause exception, which is the exception object that caused the naming exception to be thrown.
public class NamingException extends Exception {
//
Public Constructors
public NamingException ();
public NamingException (String explanation);
//
Public Instance Methods
public void appendRemainingComponent (String name);
Thrown when the provider's implementation of Context does not support a method that has been invoked (e.g., trying to list the subordinates of a leaf object like a print job that by definition cannot have any children).
public class OperationNotSupportedException extends NamingException {
//
Public Constructors
public OperationNotSupportedException ();
public OperationNotSupportedException (String explanation);
This abstract class represents the address of a communications end point. It is used by Reference to represent the communication mechanism and address of a reference. Concrete implementations support addresses such as URLs, DNS names, and IP addresses.
public abstract class RefAddr implements Serializable {
//
Protected Constructors
protected RefAddr (String addrType);
//
Public Instance Methods
public abstract Object getContent ();
public String getType ();
//
Public methods overriding Object
public boolean equals (Object obj);
public int hashCode ();
public String toString ();
//
Protected Instance Fields
protected String addrType ;
}
Hierarchy: Object-->RefAddr(Serializable)
Subclasses: BinaryRefAddr, StringRefAddr
Passed To: javax.naming.Reference.{add(), Reference()}
Returned By: javax.naming.Reference.get()
Reference
JNDI 1.1
javax.naming
cloneable serializable
This class represents an object external to a naming system that is referred to by an object in the naming system. A Reference contains an address for retrieving the object from its naming system. The address is a communications end point that enables JNDI to contact the object. The address can be any concrete subclass of RefAddr, such as a StringRefAddr for representing a URL or DNS name. A Reference also contains the class name of the referenced object.
public class Reference implements Cloneable, Serializable {
//
Public Constructors
public Reference (String className);
public Reference (String className, RefAddr addr);
public Reference (String className, String factory, String factoryLocation);
public Reference (String className, RefAddr addr, String factory, String factoryLocation);