FileDocCategorySizeDatePackage
javaURLContext.javaAPI DocGlassfish v2 API17926Fri May 04 22:35:10 BST 2007com.sun.enterprise.naming.java

javaURLContext

public final class javaURLContext extends Object implements Context, Cloneable
This class is a context implementation for the java:comp namespace. The context determines the component id from the invocation manager of the component that is invoking the method and then looks up the object in that component's local namespace.

Fields Summary
static Logger
_logger
private static final String
ORB_STRING
private static final String
HANDLE_DELEGATE
private static final String
USER_TX
private static final String
EJB_CONTEXT
private static final String
EJB_TIMER_SERVICE
private static final String
TRANSACTION_SYNC_REGISTRY
private static final String
TRANSACTION_MGR
public static final String
APPSERVER_TRANSACTION_MGR
private static final boolean
debug
private NamingManagerImpl
namingManager
private Hashtable
myEnv
private String
myName
private SerialContext
serialContext
Constructors Summary
public javaURLContext(Hashtable environment)
Create a context with the specified environment.

    
                 
       
	  
    
        myEnv = (environment != null) ? (Hashtable)(environment.clone()) : null;
	if (namingManager == null ) {
	  namingManager = (NamingManagerImpl)
	    Switch.getSwitch().getNamingManager();
	}	
    
public javaURLContext(String name, Hashtable env)
Create a context with the specified name+environment. Called only from NamingManagerImpl.

	this(env);
	this.myName = name;
    
public javaURLContext(Hashtable env, SerialContext serialContext)
this constructor is called from SerialContext class

	this(env);
	this.serialContext = serialContext;
    
Methods Summary
public com.sun.enterprise.naming.java.javaURLContextaddStickyContext(SerialContext serialContext)
add SerialContext to preserve stickiness to cloned instance why clone() : to avoid the case of multiple threads modifying the context returned for ctx.lookup("java:com/env/ejb")

	try {
	    javaURLContext jCtx = (javaURLContext)this.clone();
	    jCtx.serialContext = serialContext;
	    return jCtx;
	} catch (java.lang.CloneNotSupportedException ex) {	   
	     NamingException ne = new NamingException("problem with cloning javaURLContext instance");
	     ne.initCause(ex);
	     throw ne;
	}
    
public java.lang.ObjectaddToEnvironment(java.lang.String propName, java.lang.Object propVal)
Add a property to the environment.

        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 an object in the namespace. Binds the reference to the actual object in either the cosnaming or serial context.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidbind(javax.naming.Name name, java.lang.Object obj)
Bind an object in the namespace. Binds the reference to the actual object in either the cosnaming or serial context.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidclose()
New JNDI 1.2 operation.

        myEnv = null;
    
public java.lang.StringcomposeName(java.lang.String name, java.lang.String prefix)

        Name result = composeName(new CompositeName(name),
                                  new CompositeName(prefix));
        return result.toString();
    
public javax.naming.NamecomposeName(javax.naming.Name name, javax.naming.Name prefix)

        Name result = (Name)(prefix.clone());
        result.addAll(name);
        return result;
    
public javax.naming.ContextcreateSubcontext(java.lang.String name)

	throw new NamingException("java:comp namespace cannot be modified");
    
public javax.naming.ContextcreateSubcontext(javax.naming.Name name)

	throw new NamingException("java:comp namespace cannot be modified");
    
public voiddestroySubcontext(java.lang.String name)
The destroySubcontext operation is not supported by this context. It throws an OperationNotSupportedException.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voiddestroySubcontext(javax.naming.Name name)
The destroySubcontext operation is not supported by this context. It throws an OperationNotSupportedException.

	throw new NamingException("java:comp namespace cannot be modified");
    
public java.util.HashtablegetEnvironment()
Get the context's environment.

        if (myEnv == null) {
            // Must return non-null
            myEnv = new Hashtable(3, 0.75f);
        }
        return myEnv;
    
public java.lang.StringgetNameInNamespace()
Return the name of this context within the namespace. The name can be passed as an argument to (new InitialContext()).lookup() to reproduce this context.

        return myName;
    
public javax.naming.NameParsergetNameParser(java.lang.String name)
Return the name parser for the specified name.

return
the NameParser instance.
exception
NamingException if there is an exception.

	if ( namingManager == null )
	    throw new NamingException();
        return namingManager.getNameParser();
    
public javax.naming.NameParsergetNameParser(javax.naming.Name name)
Return the name parser for the specified name.

return
the NameParser instance.
exception
NamingException if there is an exception.

        // Flat namespace; no federation; just call string version
        return getNameParser(name.toString());
    
public javax.naming.NamingEnumerationlist(java.lang.String name)
Lists the contents of a context or subcontext. The operation is delegated to the serial context.

return
an enumeration of the contents of the context.
exception
NamingException if there is a naming exception.

        if (name.equals("")) {
            // listing this context
	    if ( namingManager == null )
		throw new NamingException();
	    return namingManager.list(myName);
        } 

        // Check if 'name' names a context
        Object target = lookup(name);
        if (target instanceof Context) {
            return ((Context)target).list("");
        }
        throw new NotContextException(name + " cannot be listed");
    
public javax.naming.NamingEnumerationlist(javax.naming.Name name)
Lists the contents of a context or subcontext. The operation is delegated to the serial context.

return
an enumeration of the contents of the context.
exception
NamingException if there is a naming exception.

        // Flat namespace; no federation; just call string version
        return list(name.toString());
    
public javax.naming.NamingEnumerationlistBindings(java.lang.String name)
Lists the bindings of a context or subcontext. The operation is delegated to the serial context.

return
an enumeration of the bindings of the context.
exception
NamingException if there is a naming exception.

        if (name.equals("")) {
            // listing this context
	    if ( namingManager == null )
		throw new NamingException();
	    return namingManager.listBindings(myName);
        } 

        // Perhaps 'name' names a context
        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)
Lists the bindings of a context or subcontext. The operation is delegated to the serial context.

return
an enumeration of the bindings of the context.
exception
NamingException if there is a naming exception.

        // Flat namespace; no federation; just call string version
        return listBindings(name.toString());
    
public java.lang.Objectlookup(java.lang.String name)
Lookup an object in the serial context.

return
the object that is being looked up.
exception
NamingException if there is a naming exception.

        if (_logger.isLoggable(Level.FINE))
	    _logger.log(Level.FINE,"In javaURLContext.lookup, name = "+name + " serialcontext..." + serialContext);
	    		
	if ( name.equals("") ) {
	    /** javadocs for Context.lookup:
	     * 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).
	     */
	    return new javaURLContext(myName, myEnv);
	}

	String fullName = name;
	if ( !myName.equals("") ) {
	    if ( myName.equals("java:") ) 
		fullName = myName + name;
	    else 
		fullName = myName + "/" + name;
	}

	try {
	    if ( fullName.startsWith("java:comp/env") ) {
		// name is in component specific namespace	     
	        return namingManager.lookup(fullName, serialContext);
	    }
	    else {
		// name is for a global object
		if( fullName.equals(ORB_STRING) ) {
		    // return the singleton ORB instance
		    return ORBManager.getORB();
		}
		else if ( fullName.equals(USER_TX) ) {
		    InvocationManager invMgr = Switch.getSwitch().getInvocationManager();
		    ComponentInvocation inv = null;
		    if (invMgr != null) { 
		        inv = invMgr.getCurrentInvocation();
		    }
		    if ((inv != null) && (inv.container != null)) {
		        if (inv.container instanceof BaseContainer) {
			    BaseContainer container = (BaseContainer) inv.container;
			    container.checkUserTransactionLookup(inv);
			}
		    }
		    // UserTransactionImpl is mutable so return new instance 
		    return new UserTransactionImpl(); 
		}
		else if ( fullName.equals(EJB_TIMER_SERVICE) ) {
		    // return the EJB Timer Service.  Only works for ejbs.
		    return Switch.getSwitch().getContainerFactory().
                        getEJBContextObject("javax.ejb.TimerService");
		} else if ( fullName.equals(EJB_CONTEXT) ) {
                    // return the EJB Timer Service.  Only works for ejbs.
		    return Switch.getSwitch().getContainerFactory().
                        getEJBContextObject("javax.ejb.EJBContext");
		} else if ( fullName.equals(HANDLE_DELEGATE) ) {
		    return Switch.getSwitch().getHandleDelegate();
		}
		else if ( fullName.equals(TRANSACTION_MGR) ) {
		    return Switch.getSwitch().getContainerFactory().getTransactionMgr();
		}
		else if ( fullName.equals(APPSERVER_TRANSACTION_MGR) ) {
		    return com.sun.enterprise.transaction.TransactionManagerHelper.getTransactionManager();
		}
		else if ( fullName.equals(TRANSACTION_SYNC_REGISTRY) ) {
		    return TransactionSynchronizationRegistryImpl.getInstance();
		}
		else {
		    // try NamingManager		  
		  return namingManager.lookup(fullName, serialContext);
		}
	    }
	} catch ( NamingException ex ) {
	    throw ex;
	} catch ( Exception ex ) {
	    throw (NamingException)(new NameNotFoundException("No object bound for "+fullName)).initCause(ex);
	}
    
public java.lang.Objectlookup(javax.naming.Name name)
Lookup a name in either the cosnaming or serial context.

return
the object that is being looked up.
exception
NamingException if there is a naming exception.

        // Flat namespace; no federation; just call string version
        return lookup(name.toString()); 
    
public java.lang.ObjectlookupLink(java.lang.String name)
This context does not treat links specially. A lookup operation is performed.

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

        // Flat namespace; no federation; just call string version
        return lookupLink(name.toString());
    
public voidrebind(javax.naming.Name name, java.lang.Object obj)
Rebind an object in the namespace. Rebinds the reference to the actual object in either the cosnaming or serial context.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidrebind(java.lang.String name, java.lang.Object obj)
Rebind an object in the namespace. Rebinds the reference to the actual object in either the cosnaming or serial context.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");
    
public java.lang.ObjectremoveFromEnvironment(java.lang.String propName)
Remove a property from the environment.

        if (myEnv == null) {
            return null;
        }
        return myEnv.remove(propName);
    
public voidrename(java.lang.String oldname, java.lang.String newname)
The rename operation is not supported by this context. It throws an OperationNotSupportedException.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidrename(javax.naming.Name oldname, javax.naming.Name newname)
The rename operation is not supported by this context. It throws an OperationNotSupportedException.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidunbind(java.lang.String name)
Unbind an object from the namespace.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");
    
public voidunbind(javax.naming.Name name)
Unbind an object from the namespace.

exception
NamingException if there is a naming exception.

	throw new NamingException("java:comp namespace cannot be modified");