Craig,

I've attached a copy of CatalogFactoryBase. Its meant to go in the 'impl' package. It implements CatalogFactory along the lines of what we discused. I attempted to have my IDE use "unix" style linebreaks but you may want to check just to be sure.

Next I will start working on modifying ChainListener. My plan is for ChainListener to store the Catalog as the default Catalog in CatalogFactoryBase (in addition to storing it in the ServletContext which is already being done.) This way users can have two options open to them. If they need the Catalogs in their business logic (like I do) they will most likely use the new CatalogFactoryBase.

sean

/*
 * Copyright 1999-2004 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.chain.impl;

import java.util.Hashtable;
import org.apache.commons.chain.CatalogFactory;
import org.apache.commons.chain.Catalog;


/**
 * <p>A simple implementation of [EMAIL PROTECTED] CatalogFactory}.</p>
 *
 * @author Sean Schofield 
 * @version 
 */

public class CatalogFactoryBase implements CatalogFactory {
    
    // ------------------------------------------------------- Static Variables
    
    /**
     * <p>The singleton instance.</p>
     */
    private static CatalogFactoryBase instance = new CatalogFactoryBase();

    /**
     * <p>A default value to store an unamed [EMAIL PROTECTED] Catalog} in the local 
     * Hashtable.</p>
     */
    private static String DEFAULT_CATALOG = "DEFAULT_CATALOG";  
    
    // ----------------------------------------------------------- Constructors
    
    
    /**
     * <p>Constructs an instance of CatalogFactoryBase.  NOTE: This is private 
     * because it is not meant to be created directly outside of the class.  
     * Use the <code>getInstance()</code> method instead.</p>
     */
    private CatalogFactoryBase() {}
    
    
    // ----------------------------------------------------- Instance Variables
    
    
    /**
     * <p>The Hashtable of [EMAIL PROTECTED] Catalog}s, keyed by the object's 
     * ClassLoader.</p>
     */
    protected Hashtable loaderTable = new Hashtable();
    
    
    // --------------------------------------------------------- Public Methods
    
    /**
     * <p>Gets the singleton instance of CatalogFactoryBase.</p>
     * 
     * @return the singleton instance of CatalogFactoryBase.
     */
    public CatalogFactory getInstance() {
        
        return instance;    
        
    }
    
    // Documented in CatalogFactory interface
    public Catalog getCatalog() {
        
        return getCatalog(DEFAULT_CATALOG);        

    }

    // Documented in CatalogFactory interface
    public void setCatalog(Catalog catalog) {
        
        addCatalog(DEFAULT_CATALOG, catalog);
        
    }

    // Documented in CatalogFactory interface
    public Catalog getCatalog(String name) {
        
        /**
         * In the event that this class will be used by multiple applications 
         * with the same class loader (as with web applications), there will 
         * be a separate Hashtable of Catalogs for each instance of 
         * ClassLoader.  That way each web application (which will always have 
         * its own) can operate without interfering with one another.
         */
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Hashtable catalogTable = (Hashtable)loaderTable.get(cl);
        
        if (catalogTable != null) {
            return (Catalog)catalogTable.get(name);            
        } else {
            return null;
        }

    }

    // Documented in CatalogFactory interface
    public void addCatalog(String name, Catalog catalog) {

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Hashtable catalogTable = (Hashtable)loaderTable.get(cl);
        
        if (catalogTable == null) {
            catalogTable = new Hashtable();
            loaderTable.put(cl, catalogTable);
        }
        
        catalogTable.put(name, catalog);
    }
    
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to