public abstract class

GenericURLContext

extends Object
implements Context
java.lang.Object
   ↳ com.sun.jndi.toolkit.url.GenericURLContext
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

This abstract class is a generic URL context that accepts as the name argument either a string URL or a Name whose first component is a URL. It resolves the URL to a target context and then continues the operation using the remaining name in the target context as if the first component names a junction. A subclass must define getRootURLContext() to process the URL into head/tail pieces. If it wants to control how URL strings are parsed and compared for the rename() operation, then it should override getNonRootURLSuffixes() and urlEquals().

Summary

[Expand]
Inherited Constants
From interface javax.naming.Context
Fields
protected Hashtable myEnv
Public Constructors
GenericURLContext(Hashtable env)
Public Methods
Object addToEnvironment(String propName, Object propVal)
Adds a new environment property to the environment of this context.
void bind(Name name, Object obj)
Binds a name to an object.
void bind(String name, Object obj)
Binds a name to an object.
void close()
Closes this context.
String composeName(String name, String prefix)
Composes the name of this context with a name relative to this context.
Name composeName(Name name, Name prefix)
Composes the name of this context with a name relative to this context.
Context createSubcontext(Name name)
Creates and binds a new context.
Context createSubcontext(String name)
Creates and binds a new context.
void destroySubcontext(Name name)
Destroys the named context and removes it from the namespace.
void destroySubcontext(String name)
Destroys the named context and removes it from the namespace.
Hashtable getEnvironment()
Retrieves the environment in effect for this context.
String getNameInNamespace()
Retrieves the full name of this context within its own namespace.
NameParser getNameParser(Name name)
Retrieves the parser associated with the named context.
NameParser getNameParser(String name)
Retrieves the parser associated with the named context.
NamingEnumeration<NameClassPair> list(String name)
Enumerates the names bound in the named context, along with the class names of objects bound to them.
NamingEnumeration<NameClassPair> list(Name name)
Enumerates the names bound in the named context, along with the class names of objects bound to them.
NamingEnumeration<Binding> listBindings(Name name)
Enumerates the names bound in the named context, along with the objects bound to them.
NamingEnumeration<Binding> listBindings(String name)
Enumerates the names bound in the named context, along with the objects bound to them.
Object lookup(String name)
Retrieves the named object.
Object lookup(Name name)
Retrieves the named object.
Object lookupLink(String name)
Retrieves the named object, following links except for the terminal atomic component of the name.
Object lookupLink(Name name)
Retrieves the named object, following links except for the terminal atomic component of the name.
void rebind(String name, Object obj)
Binds a name to an object, overwriting any existing binding.
void rebind(Name name, Object obj)
Binds a name to an object, overwriting any existing binding.
Object removeFromEnvironment(String propName)
Removes an environment property from the environment of this context.
void rename(String oldName, String newName)
Binds a new name to the object bound to an old name, and unbinds the old name.
void rename(Name name, Name newName)
Binds a new name to the object bound to an old name, and unbinds the old name.
void unbind(Name name)
Unbinds the named object.
void unbind(String name)
Unbinds the named object.
Protected Methods
Context getContinuationContext(Name n)
Gets the context in which to continue the operation.
abstract ResolveResult getRootURLContext(String url, Hashtable env)
Resolves 'name' into a target context with remaining name.
String getURLPrefix(String url)
Finds the prefix of a URL.
Name getURLSuffix(String prefix, String url)
Returns the suffix of the url.
boolean urlEquals(String url1, String url2)
Determines whether two URLs are the same.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.naming.Context

Fields

protected Hashtable myEnv

Public Constructors

public GenericURLContext (Hashtable env)

Public Methods

public Object addToEnvironment (String propName, Object propVal)

Adds a new environment property to the environment of this context. If the property already exists, its value is overwritten. See class description for more details on environment properties.

Parameters
propName the name of the environment property to add; may not be null
propVal the value of the property to add; may not be null
Returns
  • the previous value of the property, or null if the property was not in the environment before

public void bind (Name name, Object obj)

Binds a name to an object. All intermediate contexts and the target context (that named by all but terminal atomic component of the name) must already exist.

Parameters
name the name to bind; may not be empty
obj the object to bind; possibly null

public void bind (String name, Object obj)

Binds a name to an object. See bind(Name, Object) for details.

Parameters
name the name to bind; may not be empty
obj the object to bind; possibly null

public void close ()

Closes this context. This method releases this context's resources immediately, instead of waiting for them to be released automatically by the garbage collector.

This method is idempotent: invoking it on a context that has already been closed has no effect. Invoking any other method on a closed context is not allowed, and results in undefined behaviour.

public String composeName (String name, String prefix)

Composes the name of this context with a name relative to this context. See composeName(Name, Name) for details.

Parameters
name a name relative to this context
prefix the name of this context relative to one of its ancestors
Returns
  • the composition of prefix and name

public Name composeName (Name name, Name prefix)

Composes the name of this context with a name relative to this context. Given a name (name) relative to this context, and the name (prefix) of this context relative to one of its ancestors, this method returns the composition of the two names using the syntax appropriate for the naming system(s) involved. That is, if name names an object relative to this context, the result is the name of the same object, but relative to the ancestor context. None of the names may be null.

For example, if this context is named "wiz.com" relative to the initial context, then

  composeName("east", "wiz.com")  
might return "east.wiz.com". If instead this context is named "org/research", then
  composeName("user/jane", "org/research")        
might return "org/research/user/jane" while
  composeName("user/jane", "research")    
returns "research/user/jane".

Parameters
name a name relative to this context
prefix the name of this context relative to one of its ancestors
Returns
  • the composition of prefix and name

public Context createSubcontext (Name name)

Creates and binds a new context. Creates a new context with the given name and binds it in the target context (that named by all but terminal atomic component of the name). All intermediate contexts and the target context must already exist.

Parameters
name the name of the context to create; may not be empty
Returns
  • the newly created context

public Context createSubcontext (String name)

Creates and binds a new context. See createSubcontext(Name) for details.

Parameters
name the name of the context to create; may not be empty
Returns
  • the newly created context

public void destroySubcontext (Name name)

Destroys the named context and removes it from the namespace. Any attributes associated with the name are also removed. Intermediate contexts are not destroyed.

This method is idempotent. It succeeds even if the terminal atomic name is not bound in the target context, but throws NameNotFoundException if any of the intermediate contexts do not exist.

In a federated naming system, a context from one naming system may be bound to a name in another. One can subsequently look up and perform operations on the foreign context using a composite name. However, an attempt destroy the context using this composite name will fail with NotContextException, because the foreign context is not a "subcontext" of the context in which it is bound. Instead, use unbind() to remove the binding of the foreign context. Destroying the foreign context requires that the destroySubcontext() be performed on a context from the foreign context's "native" naming system.

Parameters
name the name of the context to be destroyed; may not be empty

public void destroySubcontext (String name)

Destroys the named context and removes it from the namespace. See destroySubcontext(Name) for details.

Parameters
name the name of the context to be destroyed; may not be empty

public Hashtable getEnvironment ()

Retrieves the environment in effect for this context. See class description for more details on environment properties.

The caller should not make any changes to the object returned: their effect on the context is undefined. The environment of this context may be changed using addToEnvironment() and removeFromEnvironment().

Returns
  • the environment of this context; never null

public String getNameInNamespace ()

Retrieves the full name of this context within its own namespace.

Many naming services have a notion of a "full name" for objects in their respective namespaces. For example, an LDAP entry has a distinguished name, and a DNS record has a fully qualified name. This method allows the client application to retrieve this name. The string returned by this method is not a JNDI composite name and should not be passed directly to context methods. In naming systems for which the notion of full name does not make sense, OperationNotSupportedException is thrown.

Returns
  • this context's name in its own namespace; never null

public NameParser getNameParser (Name name)

Retrieves the parser associated with the named context. In a federation of namespaces, different naming systems will parse names differently. This method allows an application to get a parser for parsing names into their atomic components using the naming convention of a particular naming system. Within any single naming system, NameParser objects returned by this method must be equal (using the equals() test).

Parameters
name the name of the context from which to get the parser
Returns
  • a name parser that can parse compound names into their atomic components

public NameParser getNameParser (String name)

Retrieves the parser associated with the named context. See getNameParser(Name) for details.

Parameters
name the name of the context from which to get the parser
Returns
  • a name parser that can parse compound names into their atomic components

public NamingEnumeration<NameClassPair> list (String name)

Enumerates the names bound in the named context, along with the class names of objects bound to them. See list(Name) for details.

Parameters
name the name of the context to list
Returns
  • an enumeration of the names and class names of the bindings in this context. Each element of the enumeration is of type NameClassPair.

public NamingEnumeration<NameClassPair> list (Name name)

Enumerates the names bound in the named context, along with the class names of objects bound to them. The contents of any subcontexts are not included.

If a binding is added to or removed from this context, its effect on an enumeration previously returned is undefined.

Parameters
name the name of the context to list
Returns
  • an enumeration of the names and class names of the bindings in this context. Each element of the enumeration is of type NameClassPair.

public NamingEnumeration<Binding> listBindings (Name name)

Enumerates the names bound in the named context, along with the objects bound to them. The contents of any subcontexts are not included.

If a binding is added to or removed from this context, its effect on an enumeration previously returned is undefined.

Parameters
name the name of the context to list
Returns
  • an enumeration of the bindings in this context. Each element of the enumeration is of type Binding.

public NamingEnumeration<Binding> listBindings (String name)

Enumerates the names bound in the named context, along with the objects bound to them. See listBindings(Name) for details.

Parameters
name the name of the context to list
Returns
  • an enumeration of the bindings in this context. Each element of the enumeration is of type Binding.

public Object lookup (String name)

Retrieves the named object. See lookup(Name) for details.

Parameters
name the name of the object to look up
Returns
  • the object bound to name

public Object lookup (Name name)

Retrieves the named object. If name is empty, returns a new instance of this context (which represents the same naming context as this context, but its environment may be modified independently and it may be accessed concurrently).

Parameters
name the name of the object to look up
Returns
  • the object bound to name

public Object lookupLink (String name)

Retrieves the named object, following links except for the terminal atomic component of the name. See lookupLink(Name) for details.

Parameters
name the name of the object to look up
Returns
  • the object bound to name, not following the terminal link (if any)

public Object lookupLink (Name name)

Retrieves the named object, following links except for the terminal atomic component of the name. If the object bound to name is not a link, returns the object itself.

Parameters
name the name of the object to look up
Returns
  • the object bound to name, not following the terminal link (if any).

public void rebind (String name, Object obj)

Binds a name to an object, overwriting any existing binding. See rebind(Name, Object) for details.

Parameters
name the name to bind; may not be empty
obj the object to bind; possibly null

public void rebind (Name name, Object obj)

Binds a name to an object, overwriting any existing binding. All intermediate contexts and the target context (that named by all but terminal atomic component of the name) must already exist.

If the object is a DirContext, any existing attributes associated with the name are replaced with those of the object. Otherwise, any existing attributes associated with the name remain unchanged.

Parameters
name the name to bind; may not be empty
obj the object to bind; possibly null

public Object removeFromEnvironment (String propName)

Removes an environment property from the environment of this context. See class description for more details on environment properties.

Parameters
propName the name of the environment property to remove; may not be null
Returns
  • the previous value of the property, or null if the property was not in the environment

public void rename (String oldName, String newName)

Binds a new name to the object bound to an old name, and unbinds the old name. See rename(Name, Name) for details.

Parameters
oldName the name of the existing binding; may not be empty
newName the name of the new binding; may not be empty

public void rename (Name name, Name newName)

Binds a new name to the object bound to an old name, and unbinds the old name. Both names are relative to this context. Any attributes associated with the old name become associated with the new name. Intermediate contexts of the old name are not changed.

Parameters
name the name of the existing binding; may not be empty
newName the name of the new binding; may not be empty

public void unbind (Name name)

Unbinds the named object. Removes the terminal atomic name in name from the target context--that named by all but the terminal atomic part of name.

This method is idempotent. It succeeds even if the terminal atomic name is not bound in the target context, but throws NameNotFoundException if any of the intermediate contexts do not exist.

Any attributes associated with the name are removed. Intermediate contexts are not changed.

Parameters
name the name to unbind; may not be empty

public void unbind (String name)

Unbinds the named object. See unbind(Name) for details.

Parameters
name the name to unbind; may not be empty

Protected Methods

protected Context getContinuationContext (Name n)

Gets the context in which to continue the operation. This method is called when this context is asked to process a multicomponent Name in which the first component is a URL. Treat the first component like a junction: resolve it and then use NamingManager.getContinuationContext() to get the target context in which to operate on the remainder of the name (n.getSuffix(1)).

protected abstract ResolveResult getRootURLContext (String url, Hashtable env)

Resolves 'name' into a target context with remaining name. For example, with a JNDI URL "jndi://dnsname/rest_name", this method resolves "jndi://dnsname/" to a target context, and returns the target context with "rest_name". The definition of "root URL" and how much of the URL to consume is implementation specific. If rename() is supported for a particular URL scheme, getRootURLContext(), getURLPrefix(), and getURLSuffix() must be in sync wrt how URLs are parsed and returned.

protected String getURLPrefix (String url)

Finds the prefix of a URL. Default implementation looks for slashes and then extracts prefixes using String.substring(). Subclass should override if this is not appropriate. This method is used only by rename(). If rename() is supported for a particular URL scheme, getRootURLContext(), getURLPrefix(), and getURLSuffix() must be in sync wrt how URLs are parsed and returned.

URL Prefix foo://host:port foo://host:port foo://host:port/rest/of/name foo://host:port foo:///rest/of/name foo:// foo:/rest/of/name foo: foo:rest/of/name foo:

protected Name getURLSuffix (String prefix, String url)

Returns the suffix of the url. The result should be identical to that of calling getRootURLContext().getRemainingName(), but without the overhead of doing anything with the prefix like creating a context.

This method returns a Name instead of a String because to give the provider an opportunity to return a Name (for example, for weakly separated naming systems like COS naming).

The default implementation uses skips 'prefix', calls UrlUtil.decode() on it, and returns the result as a single component CompositeName. Subclass should override if this is not appropriate. This method is used only by rename(). If rename() is supported for a particular URL scheme, getRootURLContext(), getURLPrefix(), and getURLSuffix() must be in sync wrt how URLs are parsed and returned.

For many URL schemes, this method is very similar to URL.getFile(), except getFile() will return a leading slash in the 2nd, 3rd, and 4th cases. For schemes like "ldap" and "iiop", the leading slash must be skipped before the name is an acceptable format for operation by the Context methods. For schemes that treat the leading slash as significant (such as "file"), the subclass must override getURLSuffix() to get the correct behavior. Remember, the behavior must match getRootURLContext(). URL Suffix foo://host:port foo://host:port/rest/of/name rest/of/name foo:///rest/of/name rest/of/name foo:/rest/of/name rest/of/name foo:rest/of/name rest/of/name

protected boolean urlEquals (String url1, String url2)

Determines whether two URLs are the same. Default implementation uses String.equals(). Subclass should override if this is not appropriate. This method is used by rename().