You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2002/10/17 18:45:14 UTC

cvs commit: jakarta-tomcat-connectors/naming/src/org/apache/naming/core BaseDirContext.java

costin      2002/10/17 09:45:14

  Modified:    naming/src/org/apache/naming/core BaseDirContext.java
  Log:
  Remove all 'simple context' code.
  
  Remove all 'base behavior' and special methods code.
  
  All that remains is base implementation for DirContext methods,
  using the simplified BaseNaming methods and/or default behavior.
  
  Revision  Changes    Path
  1.3       +3 -655    jakarta-tomcat-connectors/naming/src/org/apache/naming/core/BaseDirContext.java
  
  Index: BaseDirContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/naming/src/org/apache/naming/core/BaseDirContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseDirContext.java	8 Oct 2002 18:46:42 -0000	1.2
  +++ BaseDirContext.java	17 Oct 2002 16:45:14 -0000	1.3
  @@ -101,130 +101,14 @@
    * @author Remy Maucherat
    * @author Costin Manolache
    */
  -public class BaseDirContext implements DirContext {
  +public class BaseDirContext extends BaseContext implements DirContext {
   
  -    /**
  -     * Builds a base directory context.
  -     */
       public BaseDirContext() {
  -        this.env=new Hashtable();
  +        super();
       }
   
  -    /**
  -     * Builds a base directory context using the given environment.
  -     */
       public BaseDirContext(Hashtable env) {
  -        this.env=new Hashtable();
  -        if (env != null ) {
  -            Enumeration envEntries = env.keys();
  -            while (envEntries.hasMoreElements()) {
  -                String entryName = (String) envEntries.nextElement();
  -                this.env.put(entryName, env.get(entryName));
  -            }
  -        }
  -    }
  -
  -    // ----------------------------------------------------- Instance Variables
  -
  -    /**
  -     * Environment. All context config info.
  -     * XXX IntrospectionDirContext should call the right setters.
  -     */
  -    protected Hashtable env;
  -
  -    /**
  -     * Default name parser for this context.
  -     * XXX This should be combined with the Tomcat mapper, and
  -     * optimized for MessageBytes.
  -     */
  -    protected final NameParser nameParser = new NameParserImpl();
  -
  -    /**
  -     * Cached.
  -     * deprecated ? Should be implemented via notes or other mechanism.
  -     * Or via config.
  -     */
  -    protected boolean cached = true;
  -    protected int cacheTTL = 5000; // 5s
  -    protected int cacheObjectMaxSize = 32768; // 32 KB
  -
  -    
  -    /** Prefix used for URL-based namming lookup. It must be removed
  -     *  from all names.
  -     *  Deprecated ? Do we need it ?
  -     */
  -    protected String urlPrefix="";
  -
  -    // ------------------------------------------------------------- Properties
  -
  -    // XXX Introspection should be used to turn the Hashtable attributes
  -    // into setters.
  -    
  -    public void setURLPrefix( String s ) {
  -        urlPrefix=s;
  -    }
  -    
  -    /**
  -     * Set cached attribute. If false, this context will be skipped from caching
  -     */
  -    public void setCached(boolean cached) {
  -        this.cached = cached;
  -    }
  -
  -    /**
  -     * Is cached ?
  -     */
  -    public boolean isCached() {
  -        return cached;
  -    }
  -
  -
  -    /**
  -     * Set cache TTL.
  -     */
  -    public void setCacheTTL(int cacheTTL) {
  -        this.cacheTTL = cacheTTL;
  -    }
  -
  -
  -    /**
  -     * Get cache TTL.
  -     */
  -    public int getCacheTTL() {
  -        return cacheTTL;
  -    }
  -
  -
  -    /**
  -     * Set cacheObjectMaxSize.
  -     */
  -    public void setCacheObjectMaxSize(int cacheObjectMaxSize) {
  -        this.cacheObjectMaxSize = cacheObjectMaxSize;
  -    }
  -
  -
  -    /**
  -     * Get cacheObjectMaxSize.
  -     */
  -    public int getCacheObjectMaxSize() {
  -        return cacheObjectMaxSize;
  -    }
  -
  -    // -------------------- Lifecycle methods ? -------------------- 
  -
  -    /**
  -     * Allocate resources for this directory context.
  -     */
  -    public void allocate() {
  -        ; // No action taken by the default implementation
  -    }
  -
  -
  -    /**
  -     * Release any resources allocated for this directory context.
  -     */
  -    public void release() {
  -        ; // No action taken by the default implementation
  +        super();
       }
   
       // -------------------- Abstract methods -------------------- 
  @@ -287,524 +171,6 @@
           throw new OperationNotSupportedException();
       }
       
  -    // -------------------- Utils --------------------
  -    
  -
  -    /**
  -     * Returns true if writing is allowed on this context.
  -     */
  -    protected boolean isWritable(Name name) {
  -        return ContextAccessController.isWritable(name);
  -    }
  -
  -
  -    /**
  -     * Throws a naming exception is Context is not writable.
  -     */
  -    protected void checkWritable(Name n) 
  -        throws NamingException
  -    {
  -        if (!isWritable(n))
  -            throw new NamingException("read only");
  -    }
  -
  -    protected Name string2Name(String s ) throws InvalidNameException {
  -        // XXX uniq
  -        //        try {
  -            return new CompositeName( s );
  -//         } catch( InvalidNameException ex ) {
  -//             ex.printStackTrace();
  -//             return null;
  -//         }
  -    }
  -    
  -
  -    // -------------------- DirContext impl -------------------- 
  -    // Various things required by JNDI
  -    
  -    /**
  -     * 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).
  -     * 
  -     * @param name the name of the object to look up
  -     * @return the object bound to name
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object lookup(Name name)
  -        throws NamingException
  -    {
  -        return lookup(name, true, null );
  -    }
  -
  -    /**
  -     * Retrieves the named object.
  -     * 
  -     * @param name the name of the object to look up
  -     * @return the object bound to name
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object lookup(String name)
  -        throws NamingException
  -    {
  -        return lookup( string2Name(name), true , null);
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * 
  -     * @param name the name to bind; may not be empty
  -     * @param obj the object to bind; possibly null
  -     * @exception NameAlreadyBoundException if name is already bound
  -     * @exception InvalidAttributesException if object did not supply all 
  -     * mandatory attributes
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void bind(Name name, Object obj)
  -        throws NamingException
  -    {
  -        bind(name, obj, null, false);
  -    }
  -
  -
  -    /**
  -     * Binds a name to an object.
  -     * 
  -     * @param name the name to bind; may not be empty
  -     * @param obj the object to bind; possibly null
  -     * @exception NameAlreadyBoundException if name is already bound
  -     * @exception InvalidAttributesException if object did not supply all 
  -     * mandatory attributes
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void bind(String name, Object obj)
  -        throws NamingException
  -    {
  -        bind(string2Name(name), obj, null, false);
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * <p>
  -     * 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.
  -     * 
  -     * @param name the name to bind; may not be empty
  -     * @param obj the object to bind; possibly null
  -     * @exception InvalidAttributesException if object did not supply all 
  -     * mandatory attributes
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void rebind(Name name, Object obj)
  -        throws NamingException
  -    {
  -        bind(name, obj, null, true);
  -    }
  -
  -
  -    /**
  -     * Binds a name to an object, overwriting any existing binding.
  -     * 
  -     * @param name the name to bind; may not be empty
  -     * @param obj the object to bind; possibly null
  -     * @exception InvalidAttributesException if object did not supply all 
  -     * mandatory attributes
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void rebind(String name, Object obj)
  -        throws NamingException
  -    {
  -        bind(string2Name(name), obj, null, true);
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * <p>
  -     * 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. 
  -     * 
  -     * @param name the name to bind; may not be empty
  -     * @exception NameNotFoundException if an intermediate context does not 
  -     * exist
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void unbind(Name name)
  -        throws NamingException
  -    {
  -        unbind( name, false );
  -    }
  -    
  -    public void unbind(String name)
  -        throws NamingException
  -    {
  -        unbind( string2Name( name ), false);
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * 
  -     * @param oldName the name of the existing binding; may not be empty
  -     * @param newName the name of the new binding; may not be empty
  -     * @exception NameAlreadyBoundException if newName is already bound
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public  void rename(String oldName, String newName)
  -        throws NamingException
  -    {
  -        rename( string2Name( oldName ), string2Name( newName ));
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * <p>
  -     * If a binding is added to or removed from this context, its effect on 
  -     * an enumeration previously returned is undefined.
  -     * 
  -     * @param name the name of the context to list
  -     * @return an enumeration of the names and class names of the bindings in 
  -     * this context. Each element of the enumeration is of type NameClassPair.
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public NamingEnumeration list(String name)
  -        throws NamingException
  -    {
  -        return list(string2Name(name));
  -    }
  -
  -    public NamingEnumeration list(Name name)
  -        throws NamingException
  -    {
  -        throw new OperationNotSupportedException("list");
  -    }
  -
  -
  -    /**
  -     * Enumerates the names bound in the named context, along with the 
  -     * objects bound to them. The contents of any subcontexts are not 
  -     * included.
  -     * <p>
  -     * If a binding is added to or removed from this context, its effect on 
  -     * an enumeration previously returned is undefined.
  -     * 
  -     * @param name the name of the context to list
  -     * @return an enumeration of the bindings in this context. 
  -     * Each element of the enumeration is of type Binding.
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public NamingEnumeration listBindings(Name name)
  -        throws NamingException
  -    {
  -        throw new OperationNotSupportedException( "listBindings" );
  -    }
  -
  -    public NamingEnumeration listBindings(String name)
  -        throws NamingException
  -    {
  -        return listBindings( string2Name( 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.
  -     * <p>
  -     * 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.
  -     * 
  -     * @param name the name of the context to be destroyed; may not be empty
  -     * @exception NameNotFoundException if an intermediate context does not 
  -     * exist
  -     * @exception NotContextException if the name is bound but does not name 
  -     * a context, or does not name a context of the appropriate type
  -     */
  -    public void destroySubcontext(Name name)
  -        throws NamingException
  -    {
  -        unbind( name, true );
  -    }
  -
  -
  -    /**
  -     * Destroys the named context and removes it from the namespace.
  -     * 
  -     * @param name the name of the context to be destroyed; may not be empty
  -     * @exception NameNotFoundException if an intermediate context does not 
  -     * exist
  -     * @exception NotContextException if the name is bound but does not name 
  -     * a context, or does not name a context of the appropriate type
  -     */
  -    public  void destroySubcontext(String name)
  -        throws NamingException
  -    {
  -        unbind( string2Name( name ), true );
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * 
  -     * @param name the name of the context to create; may not be empty
  -     * @return the newly created context
  -     * @exception NameAlreadyBoundException if name is already bound
  -     * @exception InvalidAttributesException if creation of the subcontext 
  -     * requires specification of mandatory attributes
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Context createSubcontext(Name name)
  -        throws NamingException
  -    {
  -        return createSubcontext( name, null );
  -    }
  -
  -    public Context createSubcontext(String name)
  -        throws NamingException
  -    {
  -        return createSubcontext( string2Name( name ),null);
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * 
  -     * @param name the name of the object to look up
  -     * @return the object bound to name, not following the terminal link 
  -     * (if any).
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object lookupLink(Name name)
  -        throws NamingException {
  -        return lookup(name, false, null);
  -    }
  -
  -
  -    /**
  -     * Retrieves the named object, following links except for the terminal 
  -     * atomic component of the name.
  -     * 
  -     * @param name the name of the object to look up
  -     * @return the object bound to name, not following the terminal link 
  -     * (if any).
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object lookupLink(String name)
  -        throws NamingException
  -    {
  -        return lookupLink( string2Name(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).
  -     * 
  -     * @param name the name of the context from which to get the parser
  -     * @return a name parser that can parse compound names into their atomic 
  -     * components
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public NameParser getNameParser(Name name)
  -        throws NamingException {
  -
  -	while ((!name.isEmpty()) && (name.get(0).length() == 0))
  -	    name = name.getSuffix(1);
  -        if (name.isEmpty())
  -            return nameParser;
  -
  -        if (name.size() > 1) {
  -            Object obj = lookup(name.get(0));
  -            if (obj instanceof Context) {
  -                return ((Context) obj).getNameParser(name.getSuffix(1));
  -            } else {
  -                throw new NotContextException( name.toString());
  -            }
  -        }
  -
  -        return nameParser;
  -
  -    }
  -
  -
  -    /**
  -     * Retrieves the parser associated with the named context.
  -     * 
  -     * @param name the name of the context from which to get the parser
  -     * @return a name parser that can parse compound names into their atomic 
  -     * components
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public NameParser getNameParser(String name)
  -        throws NamingException
  -    {
  -        return getNameParser(new CompositeName(name));
  -    }
  -
  -    /**
  -     * Composes the name of this context with a name relative to this context.
  -     * <p>
  -     * 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.
  -     * 
  -     * @param name a name relative to this context
  -     * @param prefix the name of this context relative to one of its ancestors
  -     * @return the composition of prefix and name
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Name composeName(Name name, Name prefix)
  -        throws NamingException
  -    {
  -	prefix = (Name) name.clone();
  -	return prefix.addAll(name);
  -    }
  -
  -
  -    /**
  -     * Composes the name of this context with a name relative to this context.
  -     * 
  -     * @param name a name relative to this context
  -     * @param prefix the name of this context relative to one of its ancestors
  -     * @return the composition of prefix and name
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public String composeName(String name, String prefix)
  -        throws NamingException {
  -        return prefix + "/" + name;
  -    }
  -
  -
  -    /**
  -     * Adds a new environment property to the environment of this context. If 
  -     * the property already exists, its value is overwritten.
  -     * 
  -     * @param propName the name of the environment property to add; may not 
  -     * be null
  -     * @param propVal the value of the property to add; may not be null
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object addToEnvironment(String propName, Object propVal)
  -        throws NamingException
  -    {
  -        return env.put(propName, propVal);
  -    }
  -
  -
  -    /**
  -     * Removes an environment property from the environment of this context. 
  -     * 
  -     * @param propName the name of the environment property to remove; 
  -     * may not be null
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Object removeFromEnvironment(String propName)
  -        throws NamingException
  -    {
  -        return env.remove(propName);
  -    }
  -
  -
  -    /**
  -     * 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().
  -     * 
  -     * @return the environment of this context; never null
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public Hashtable getEnvironment()
  -        throws NamingException
  -    {
  -        return env;
  -    }
  -
  -
  -    /**
  -     * 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.
  -     * 
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public void close()
  -        throws NamingException
  -    {
  -        // We don't own the env., but the clone
  -        env.clear();
  -    }
  -
  -
  -    /**
  -     * Retrieves the full name of this context within its own namespace.
  -     * <p>
  -     * 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.
  -     * 
  -     * @return this context's name in its own namespace; never null
  -     * @exception OperationNotSupportedException if the naming system does 
  -     * not have the notion of a full name
  -     * @exception NamingException if a naming exception is encountered
  -     */
  -    public String getNameInNamespace()
  -        throws NamingException
  -    {
  -        throw new OperationNotSupportedException();
  -    }
  -
  -
       // ----------------------------------------------------- DirContext Methods
   
   
  @@ -1321,23 +687,5 @@
           throw new OperationNotSupportedException();
       }
   
  -    //-------------------- Helpers -------------------- 
  -
  -    /** Just a hack so that all DirContexts can be used as tasks.
  -     * They'll do nothing - the setters will be called ( just like
  -     * new Context(Hashtable) - since we use introspection ) and the
  -     * context can be registred as a reference in the Project ns.
  -     *
  -     * Then other tasks could manipulate it by name.
  -     *
  -     * In a future version of ant we should have the 'references'
  -     * pluggable and a possible impl should be JNDI.
  -     *
  -     * Alternative: there is a way to use tasks without this method,
  -     * but for now it's simpler.
  -     */
  -    public void execute() {
  -    }
  -    
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>