FileDocCategorySizeDatePackage
TransientContext.javaAPI DocGlassfish v2 API23425Fri May 04 22:35:08 BST 2007com.sun.enterprise.naming

TransientContext

public class TransientContext extends Object implements Context, Serializable
Class to implement multiple level of subcontexts in SerialContext. To use this class a new object of class InitialContext (env) should be instantiated. The env i.e the Environment is initialised with SerialInitContextFactory An example for using this is in /test/subcontext

Fields Summary
static Logger
_logger
public static final boolean
debug
Hashtable
myEnv
private Hashtable
bindings
static NameParser
myParser
Constructors Summary
public TransientContext()

    
      
    
Methods Summary
public java.lang.ObjectaddToEnvironment(java.lang.String propName, java.lang.Object propVal)
Add the property name and value to the environment.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (myEnv == null) {
            myEnv = new Hashtable(5, 0.75f);
        }
        return myEnv.put(propName, propVal);
    
public voidbind(java.lang.String name, java.lang.Object obj)
Bind the object to the specified name.

exception
NamingException if there is a naming exception.
exception
RemoteException if there is an RMI exception.

	Name n = new CompositeName(name);
	if (n.size() < 1) {
	    throw new InvalidNameException("Cannot bind empty name");
	}
	if(n.size() == 1) { // bottom
	    doBindOrRebind(n.toString(), obj, false);
	} else {
	    String suffix = n.getSuffix(1).toString();
	    Context ctx;
	    try {
		ctx = resolveContext(n.get(0));
	    } catch (NameNotFoundException e){
		ctx = createSubcontext (n.get (0));
	    }
	    ctx.bind(suffix, obj);
	}
    
public voidbind(javax.naming.Name name, java.lang.Object obj)
Bind the object to the specified name.

exception
NamingException if there is a naming exception.
exception
RemoteException if there is an RMI exception.

	bind(name.toString(), obj);
    
public voidclose()
Invalidate the current environment.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        myEnv = null;
    
public java.lang.StringcomposeName(java.lang.String name, java.lang.String prefix)
Compose a new name specified by name and prefix.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception
return
null

        return null;
    
public javax.naming.NamecomposeName(javax.naming.Name name, javax.naming.Name prefix)
Compose a new name specified by name and prefix.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception
return
Name result of the concatenation

        Name result = (Name)(prefix.clone());
        result.addAll(name);
        return result;
    
public javax.naming.ContextcreateSubcontext(java.lang.String name)
Create a subcontext with the specified name.

return
the created subcontext.
exception
NamingException if there is a naming exception.
exception
RMIException if there is an RMI exception.

	return drillDownAndCreateSubcontext (name);
    
public javax.naming.ContextcreateSubcontext(javax.naming.Name name)
Create a subcontext with the specified name.

return
the created subcontext.
exception
NamingException if there is a naming exception.
exception
RMIException if there is an RMI exception.

	return createSubcontext(name.toString());
    
public voiddestroySubcontext(java.lang.String name)
Destroy the subcontext with the specified name.

exception
NamingException if there is a naming exception.
exception
RMIException if there is an RMI exception.

	drillDownAndDestroySubcontext (name);
    
public voiddestroySubcontext(javax.naming.Name name)
Destroy the subcontext with the specified name.

exception
NamingException if there is a naming exception.
exception
RMIException if there is an RMI exception.

	destroySubcontext(name.toString());
    
private voiddoBindOrRebind(java.lang.String name, java.lang.Object obj, boolean rebind)
Binds or rebinds the object specified by name

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (name.equals("")) {
            throw new InvalidNameException("Cannot bind empty name");
        }
	if(!rebind) {
            if (bindings.get(name) != null) {
                throw new NameAlreadyBoundException(
						    "Use rebind to override");
            }
	}
        bindings.put(name, obj);
    
private java.lang.ObjectdoLookup(java.lang.String name)
Lookup the specified name in the current objects hashtable.

return
the object or context bound to the name.
exception
NamingException if there is a naming exception.
exception
RemoteException if there is an RMI exception.

	Object answer = bindings.get(name);
	if (answer == null) {
            throw new NameNotFoundException(name + " not found");
        }
        return answer;
    
private voiddoUnbind(java.lang.String name)
Unbinds the object specified by name. Traverses down the context tree and unbinds the object if required.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (name.equals("")) {
            throw new InvalidNameException("Cannot unbind empty name");
        }
        if (bindings.get(name) == null) {
	    throw new NameNotFoundException(
					    "Cannot find name to unbind");
        }
	bindings.remove(name);
    
public javax.naming.ContextdrillDownAndCreateSubcontext(java.lang.String name)
Handles making nested subcontexts i.e. if you want abcd/efg/hij. It will go subcontext efg in abcd (if not present already - it will create it) and then make subcontext hij

return
the created subcontext.
exception
NamingException if there is a Naming exception

	Name n = new CompositeName (name);
	if (n.size () < 1){
	    throw new InvalidNameException ("Cannot create empty subcontext");
	}
	if (n.size() == 1){ // bottom
	    if (bindings.containsKey (name)){
		throw new NameAlreadyBoundException ("Subcontext " +
						     name + "already present");
	    }
	   
	    TransientContext ctx = null; 
	    ctx = new TransientContext ();
	    bindings.put (name, ctx);
	    return ctx;
	} else {
	    String suffix = n.getSuffix(1).toString();
	    Context retCtx, ctx; // the created context
	    try {
		ctx = resolveContext(n.get(0));
	    } catch (NameNotFoundException e){
		ctx = new TransientContext ();
	    }
	    retCtx = ctx.createSubcontext (suffix);
	    bindings.put (n.get(0), ctx);
	    return retCtx; 
	}
    
public voiddrillDownAndDestroySubcontext(java.lang.String name)
Handles deleting nested subcontexts i.e. if you want delete abcd/efg/hij. It will go subcontext efg in abcd it will delete it) and then delete subcontext hij

exception
NamingException if there is a naming exception

	Name n = new CompositeName (name);
	if (n.size () < 1){
	    throw new InvalidNameException ("Cannot destoy empty subcontext");
	}
	if (n.size() == 1){ // bottom
	    if (bindings.containsKey (name)){
		bindings.remove (name);
	    }
	    else{
		throw new NameNotFoundException ("Subcontext: " + name +
						" not found");
	    }
	} else {
	    String suffix = n.getSuffix(1).toString();
	    Context ctx; // the context to drill down from
	    ctx = resolveContext(n.get(0));
	    ctx.destroySubcontext (suffix);
	}
    
public java.util.HashtablegetEnvironment()
List the current environment.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (myEnv == null) {
            // Must return non-null
            myEnv = new Hashtable(3, 0.75f);
        }
        return myEnv;
    
public java.lang.StringgetNameInNamespace()
Operation not supported.

        throw new OperationNotSupportedException("getNameInNamespace() " +
						 "not implemented");
    
public javax.naming.NameParsergetNameParser(java.lang.String name)
List the NameParser specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        return myParser;
    
public javax.naming.NameParsergetNameParser(javax.naming.Name name)
List the NameParser specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        // Flat namespace; no federation; just call string version
        return getNameParser(name.toString());
    
public java.util.Hashtablelist()
list the objects stored by the current context

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	return bindings;
    
public javax.naming.NamingEnumerationlist(javax.naming.Name name)
List the objects specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        return list(name.toString());
    
public javax.naming.NamingEnumerationlist(java.lang.String name)
List the objects specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	if(debug) {
	    print(bindings);
	}
	if(name.equals(""))
	    return new RepNames(bindings);
	
	Object target = lookup(name);
	if(target instanceof Context) {
	    return ((Context)target).list("");
	}
	throw new NotContextException(name + " cannot be listed");
    
public javax.naming.NamingEnumerationlistBindings(java.lang.String name)
List the bindings of objects present in name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	if(name.equals(""))
	    return new RepBindings(bindings);

	Object target = lookup(name);
	if(target instanceof Context) {
	    return ((Context)target).listBindings("");
	}
	throw new NotContextException(name + " cannot be listed");
    
public javax.naming.NamingEnumerationlistBindings(javax.naming.Name name)
List the binding of objects specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	return listBindings(name.toString());
    
public java.util.HashtablelistContext(java.lang.String name)
List the objects specified by name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	if(debug) {
	    print(bindings);
	}
	if(name.equals(""))
	    return bindings;
	
	Object target = lookup(name);
	if(target instanceof TransientContext) {
	    return ((TransientContext)target).listContext("");
	}
	throw new NotContextException(name + " cannot be listed");
    
public java.lang.Objectlookup(java.lang.String name)
Lookup the specified name.

return
the object or context bound to the name.
exception
NamingException if there is a naming exception.
exception
RemoteException if there is an RMI exception.

	Name n = new CompositeName(name);
	if (n.size() < 1) {
	    throw new InvalidNameException("Cannot bind empty name");
	}
	if(n.size() == 1) { // bottom
	    return doLookup(n.toString());
	} else {
	    String suffix = n.getSuffix(1).toString();
	    TransientContext ctx = resolveContext(n.get(0));
	    return ctx.lookup(suffix);
	}
    
public java.lang.Objectlookup(javax.naming.Name name)
Lookup the specified name.

return
the object or context bound to the name.
exception
NamingException if there is a naming exception.
exception
RemoteException if there is an RMI exception.

	return lookup(name.toString());
    
public java.lang.ObjectlookupLink(java.lang.String name)
Lookup the name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        // This flat context does not treat links specially
        return lookup(name);
    
public java.lang.ObjectlookupLink(javax.naming.Name name)
Lookup name.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        // Flat namespace; no federation; just call string version
        return lookupLink(name.toString());
    
private static voidprint(java.util.Hashtable ht)
Print the current hashtable.

        for (Enumeration en = ht.keys(); en.hasMoreElements(); ) {
            Object key = en.nextElement();
            Object value = ht.get(key);
	          /** IASRI 4660742
            System.out.println("[" + key + ":" + key.getClass().getName() + 
                               ", " + value + ":" + value.getClass().getName()
                               + "]");
	          **/
	          // START OF IASRI 4660742
            if(_logger.isLoggable(Level.FINE)) {
	             _logger.log(Level.FINE,"[" + key + ":" + 
                        key.getClass().getName() +
                        ", " + value + ":" + value.getClass().getName() + "]");
            }
	          // END OF IASRI 4660742
        }
    
public voidrebind(java.lang.String name, java.lang.Object obj)
Rebinds the object specified by name

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	Name n = new CompositeName(name);
	if (n.size() < 1) {
	    throw new InvalidNameException("Cannot bind empty name");
	}
	if(n.size() == 1) { // bottom
	    doBindOrRebind(n.toString(), obj, true);
	} else {
	    String suffix = n.getSuffix(1).toString();
	    Context ctx=null;
	    try {
		ctx = resolveContext(n.get(0));
		ctx.rebind(suffix, obj);
	    } catch (NameNotFoundException e){
		ctx = createSubcontext (n.get(0));
		ctx.rebind(suffix, obj);
	    }
	}
    
public voidrebind(javax.naming.Name name, java.lang.Object obj)
Binds or rebinds the object specified by name

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	rebind(name.toString(), obj);
    
public java.lang.ObjectremoveFromEnvironment(java.lang.String propName)
Remove property from the environment.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (myEnv == null) {
            return null;
        }
        return myEnv.remove(propName);
    
public voidrename(javax.naming.Name oldname, javax.naming.Name newname)
Rename the object specified by oldname to newname

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	rename(oldname.toString(), newname.toString());
    
public voidrename(java.lang.String oldname, java.lang.String newname)
Rename the object specified by oldname to newname

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

        if (oldname.equals("") || newname.equals("")) {
            throw new InvalidNameException("Cannot rename empty name");
        }

        // Check if new name exists
        if (bindings.get(newname) != null) {
            throw new NameAlreadyBoundException(newname +
                                                " is already bound");
        }

        // Check if old name is bound
        Object oldBinding = bindings.remove(oldname);
        if (oldBinding == null) {
            throw new NameNotFoundException(oldname + " not bound");
        }

        bindings.put(newname, oldBinding);
    
private com.sun.enterprise.naming.TransientContextresolveContext(java.lang.String s)
Finds out if the subcontext specified is present in the current context

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	//TransientContext ctx = (TransientContext) bindings.get(s);
	TransientContext ctx;
	Object obj = bindings.get (s);
	if(obj  == null) {
	    throw new NameNotFoundException();
	}
	if (obj instanceof TransientContext){
	    ctx = (TransientContext) obj;
	}
	else {
	    throw new NameAlreadyBoundException (s);
	}
	return ctx;
    
public voidunbind(java.lang.String name)
Unbinds the object specified by name. Calls itself recursively to traverse down the context tree and unbind the object.

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	Name n = new CompositeName(name);
	if (n.size() < 1) {
	    throw new InvalidNameException("Cannot unbind empty name");
	}
	if(n.size() == 1) { // bottom
	    doUnbind(n.toString());
	} else {
	    String suffix = n.getSuffix(1).toString();
	    TransientContext ctx = resolveContext(n.get(0));
	    ctx.unbind(suffix);
	}
    
public voidunbind(javax.naming.Name name)
Unbinds the object specified by name

exception
NamingException if there is a naming exception
exception
RemoteException if there is a RMI exception

	unbind(name.toString());