public class

RegistryContext

extends Object
implements Context Referenceable
java.lang.Object
   ↳ com.sun.jndi.rmi.registry.RegistryContext

Class Overview

A RegistryContext is a context representing a remote RMI registry.

Summary

Constants
String SECURITY_MGR
[Expand]
Inherited Constants
From interface javax.naming.Context
Public Constructors
RegistryContext(String host, int port, Hashtable env)
Returns a context for the registry at a given host and port.
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)
If the object to be bound is both Remote and Referenceable, binds the object itself, not its Reference.
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.
Reference getReference()
Returns an RMI registry reference for this context.
NamingEnumeration list(String name)
Enumerates the names bound in the named context, along with the class names of objects bound to them.
NamingEnumeration list(Name name)
Enumerates the names bound in the named context, along with the class names of objects bound to them.
NamingEnumeration listBindings(Name name)
Enumerates the names bound in the named context, along with the objects bound to them.
NamingEnumeration 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 name, String newName)
Binds a new name to the object bound to an old name, and unbinds the old name.
void rename(Name oldName, Name newName)
Rename is implemented by this sequence of operations: lookup, bind, unbind.
void unbind(Name name)
Unbinds the named object.
void unbind(String name)
Unbinds the named object.
static NamingException wrapRemoteException(RemoteException re)
Wrap a RemoteException inside a NamingException.
Protected Methods
void finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.naming.Context
From interface javax.naming.Referenceable

Constants

public static final String SECURITY_MGR

Constant Value: "java.naming.rmi.security.manager"

Public Constructors

public RegistryContext (String host, int port, Hashtable env)

Returns a context for the registry at a given host and port. If "host" is null, uses default host. If "port" is non-positive, uses default port. Cloning of "env" is handled by caller; see comments within RegistryContextFactory.getObjectInstance(), for example.

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)

If the object to be bound is both Remote and Referenceable, binds the object itself, not its Reference.

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 Reference getReference ()

Returns an RMI registry reference for this context.

If this context was created from a reference, that reference is returned. Otherwise, an exception is thrown if the registry's host is "localhost" or the default (null). Although this could possibly make for a valid reference, it's far more likely to be an easily made error.

Returns
  • The non-null Reference of this object.

public NamingEnumeration 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 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 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 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 name, 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
name 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 oldName, Name newName)

Rename is implemented by this sequence of operations: lookup, bind, unbind. The sequence is not performed atomically.

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 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

public static NamingException wrapRemoteException (RemoteException re)

Wrap a RemoteException inside a NamingException.

Protected Methods

protected void finalize ()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.