Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.media.naming
Class MemoryContext  view MemoryContext download MemoryContext.java

java.lang.Object
  extended byorg.media.naming.MemoryContext
All Implemented Interfaces:
javax.naming.Context

public class MemoryContext
extends java.lang.Object
implements javax.naming.Context

An in-memory JNDI service provider. Binds objects into a namespace held entirely in memory, supporting serializable, remoteable and local objects. The in-memory service provider is particularly useful for holding resource factories (the JNDI ENC) and exposing run-time services and configuration objects.

An instance of MemoryContext constructed with no environment attribute will use it's namespace and serve as the root of that namespace. Such a namespace is no accessible except through the creating context, and is garbage collected when all such contexts are no longer referenced. If necessary the root context can be duplicated using lookup( "" ).

If the environment attribute Context.PROVIDER_URL>Context.PROVIDER_URL 55 is set, the context will reference a node in a namespace shared by all such contexts. That tree is statically held in memory for the life time of the virtual machine.

This class was inspired by the tyrex.naming package from the Tyrex project. All credits for the good stuff should go to Assaf Arkin and the Exolab group, all the bad stuff blame it on me :).

Version:
$Revision: 1.2 $ $Date: 2001/06/04 10:23:21 $

Field Summary
private  MemoryBinding _bindings
          Holds the bindings associated with this context.
private  java.util.Hashtable _env
          The environment attributes used to construct this context.
private  boolean _readOnly
          True if this context has been set read-only.
static javax.naming.NameParser DefaultNameParser
          The default name parser for this context.
static java.lang.String NameSeparator
          The default name separator for this context is '/'.
static java.lang.String ReadOnly
          Environment attribute to set a context read-only.
 
Fields inherited from interface javax.naming.Context
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
 
Constructor Summary
  MemoryContext(java.util.Hashtable env)
          Construct a new context with the specified environment attributes.
(package private) MemoryContext(MemoryBinding bindings, java.util.Hashtable env)
          Construct a new context with the specified bindings and environment attributes.
 
Method Summary
 java.lang.Object addToEnvironment(java.lang.String name, java.lang.Object value)
           
 void bind(javax.naming.Name name, java.lang.Object value)
           
 void bind(java.lang.String name, java.lang.Object value)
           
 void close()
           
 javax.naming.Name composeName(javax.naming.Name name, javax.naming.Name prefix)
           
 java.lang.String composeName(java.lang.String name, java.lang.String prefix)
           
 javax.naming.Context createSubcontext(javax.naming.Name name)
           
 javax.naming.Context createSubcontext(java.lang.String name)
           
(package private)  void debug(java.io.PrintWriter writer)
           
 void destroySubcontext(javax.naming.Name name)
           
 void destroySubcontext(java.lang.String name)
           
 MemoryBinding getBindings()
          Returns the bindings represented by this context.
 java.util.Hashtable getEnvironment()
           
 java.lang.String getNameInNamespace()
           
 javax.naming.NameParser getNameParser(javax.naming.Name name)
           
 javax.naming.NameParser getNameParser(java.lang.String name)
           
private  java.lang.Object internalLookup(javax.naming.Name name, boolean resolveLinkRef)
           
 javax.naming.NamingEnumeration list(javax.naming.Name name)
           
 javax.naming.NamingEnumeration list(java.lang.String name)
           
 javax.naming.NamingEnumeration listBindings(javax.naming.Name name)
           
 javax.naming.NamingEnumeration listBindings(java.lang.String name)
           
 java.lang.Object lookup(javax.naming.Name name)
           
 java.lang.Object lookup(java.lang.String name)
           
 java.lang.Object lookupLink(javax.naming.Name name)
           
 java.lang.Object lookupLink(java.lang.String name)
           
 void rebind(javax.naming.Name name, java.lang.Object value)
           
 void rebind(java.lang.String name, java.lang.Object value)
           
 java.lang.Object removeFromEnvironment(java.lang.String name)
           
 void rename(javax.naming.Name oldName, javax.naming.Name newName)
           
 void rename(java.lang.String oldName, java.lang.String newName)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 void unbind(javax.naming.Name name)
           
 void unbind(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ReadOnly

public static final java.lang.String ReadOnly
Environment attribute to set a context read-only. The value must be a string equal to true. Once the context has been set read-only, it cannot be reset to read-write.

See Also:
Constant Field Values

NameSeparator

public static final java.lang.String NameSeparator
The default name separator for this context is '/'.

See Also:
Constant Field Values

DefaultNameParser

public static final javax.naming.NameParser DefaultNameParser
The default name parser for this context.


_bindings

private final MemoryBinding _bindings
Holds the bindings associated with this context. Multiple contexts may share the same binding. The binding is selected based on the Context.PROVIDER_URL>Context.PROVIDER_URL 55 attribute. The context's name in the name space is know to the bindings.


_env

private final java.util.Hashtable _env
The environment attributes used to construct this context. Will be passed on to all contexts constructed by this context.


_readOnly

private boolean _readOnly
True if this context has been set read-only. Once it has been set read-only, it cannot revert to writable and all contexts returns by this context are read-only.

Constructor Detail

MemoryContext

public MemoryContext(java.util.Hashtable env)
              throws javax.naming.NamingException
Construct a new context with the specified environment attributes. The environment property Context.PROVIDER_URL>Context.PROVIDER_URL 55 names the underlying bindings. If the property is absent, the returned context has it's own binding space which is not shared with other contexts created in this manner.


MemoryContext

MemoryContext(MemoryBinding bindings,
              java.util.Hashtable env)
Construct a new context with the specified bindings and environment attributes.

Method Detail

lookup

public java.lang.Object lookup(java.lang.String name)
                        throws javax.naming.NamingException
Specified by:
lookup in interface javax.naming.Context

lookup

public java.lang.Object lookup(javax.naming.Name name)
                        throws javax.naming.NamingException
Specified by:
lookup in interface javax.naming.Context

lookupLink

public java.lang.Object lookupLink(java.lang.String name)
                            throws javax.naming.NamingException
Specified by:
lookupLink in interface javax.naming.Context

lookupLink

public java.lang.Object lookupLink(javax.naming.Name name)
                            throws javax.naming.NamingException
Specified by:
lookupLink in interface javax.naming.Context

internalLookup

private java.lang.Object internalLookup(javax.naming.Name name,
                                        boolean resolveLinkRef)
                                 throws javax.naming.NamingException

bind

public void bind(java.lang.String name,
                 java.lang.Object value)
          throws javax.naming.NamingException
Specified by:
bind in interface javax.naming.Context

bind

public void bind(javax.naming.Name name,
                 java.lang.Object value)
          throws javax.naming.NamingException
Specified by:
bind in interface javax.naming.Context

rebind

public void rebind(java.lang.String name,
                   java.lang.Object value)
            throws javax.naming.NamingException
Specified by:
rebind in interface javax.naming.Context

rebind

public void rebind(javax.naming.Name name,
                   java.lang.Object value)
            throws javax.naming.NamingException
Specified by:
rebind in interface javax.naming.Context

unbind

public void unbind(java.lang.String name)
            throws javax.naming.NamingException
Specified by:
unbind in interface javax.naming.Context

unbind

public void unbind(javax.naming.Name name)
            throws javax.naming.NamingException
Specified by:
unbind in interface javax.naming.Context

rename

public void rename(java.lang.String oldName,
                   java.lang.String newName)
            throws javax.naming.NamingException
Specified by:
rename in interface javax.naming.Context

rename

public void rename(javax.naming.Name oldName,
                   javax.naming.Name newName)
            throws javax.naming.NamingException
Specified by:
rename in interface javax.naming.Context

list

public javax.naming.NamingEnumeration list(java.lang.String name)
                                    throws javax.naming.NamingException
Specified by:
list in interface javax.naming.Context

list

public javax.naming.NamingEnumeration list(javax.naming.Name name)
                                    throws javax.naming.NamingException
Specified by:
list in interface javax.naming.Context

listBindings

public javax.naming.NamingEnumeration listBindings(java.lang.String name)
                                            throws javax.naming.NamingException
Specified by:
listBindings in interface javax.naming.Context

listBindings

public javax.naming.NamingEnumeration listBindings(javax.naming.Name name)
                                            throws javax.naming.NamingException
Specified by:
listBindings in interface javax.naming.Context

createSubcontext

public javax.naming.Context createSubcontext(java.lang.String name)
                                      throws javax.naming.NamingException
Specified by:
createSubcontext in interface javax.naming.Context

createSubcontext

public javax.naming.Context createSubcontext(javax.naming.Name name)
                                      throws javax.naming.NamingException
Specified by:
createSubcontext in interface javax.naming.Context

destroySubcontext

public void destroySubcontext(java.lang.String name)
                       throws javax.naming.NamingException
Specified by:
destroySubcontext in interface javax.naming.Context

destroySubcontext

public void destroySubcontext(javax.naming.Name name)
                       throws javax.naming.NamingException
Specified by:
destroySubcontext in interface javax.naming.Context

getNameParser

public javax.naming.NameParser getNameParser(java.lang.String name)
                                      throws javax.naming.NamingException
Specified by:
getNameParser in interface javax.naming.Context

getNameParser

public javax.naming.NameParser getNameParser(javax.naming.Name name)
                                      throws javax.naming.NamingException
Specified by:
getNameParser in interface javax.naming.Context

composeName

public javax.naming.Name composeName(javax.naming.Name name,
                                     javax.naming.Name prefix)
                              throws javax.naming.NamingException
Specified by:
composeName in interface javax.naming.Context

composeName

public java.lang.String composeName(java.lang.String name,
                                    java.lang.String prefix)
Specified by:
composeName in interface javax.naming.Context

getNameInNamespace

public java.lang.String getNameInNamespace()
                                    throws javax.naming.NamingException
Specified by:
getNameInNamespace in interface javax.naming.Context

addToEnvironment

public java.lang.Object addToEnvironment(java.lang.String name,
                                         java.lang.Object value)
                                  throws javax.naming.NamingException
Specified by:
addToEnvironment in interface javax.naming.Context

getEnvironment

public java.util.Hashtable getEnvironment()
Specified by:
getEnvironment in interface javax.naming.Context

removeFromEnvironment

public java.lang.Object removeFromEnvironment(java.lang.String name)
Specified by:
removeFromEnvironment in interface javax.naming.Context

close

public void close()
Specified by:
close in interface javax.naming.Context

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


getBindings

public MemoryBinding getBindings()
Returns the bindings represented by this context. Used when assigning a memory context into the ENC.


debug

void debug(java.io.PrintWriter writer)