/*******************************************************************************
 * Copyright (c), 2001, 2002 N2 Broadband, Inc.  All Rights Reserved.
 *
 * This module contains unpublished, confidential, proprietary
 * material.  The use and dissemination of this material are
 * governed by a license.  The above copyright notice does not
 * evidence any actual or intended publication of this material.
 *
 * Author:  Drake H. Henderson
 * Created:  11-12-01
 *
 ******************************************************************************/

package com.n2bb.plugins;

import java.io.InputStream;
import java.util.Properties;
import javax.servlet.ServletException;


import com.n2bb.util.OrbManager;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

/**
 * Sets properties on OrbManager.
 */
public final class ORBPlugIn implements PlugIn {

    private static Logger n2bbLog = Logger.getLogger(ORBPlugIn.class);

    private String pathname = "/WEB-INF/orb.properties";

    public String getPathname() {
        return (this.pathname);
    }

    public void setPathname(String pathname) {
        this.pathname = pathname;
    }

    /**
     * Sets properties on OrbManager.  Does not actually create orb --
     * orb is created lazily by OrbManager.getInstance(), using properties
     * set here.
     */
    public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

        Properties props = new Properties();
        InputStream is = servlet.getServletContext().getResourceAsStream(pathname);
        if (is == null)
            n2bbLog.error("orb properties not found");
        else {
            try {
                props.load(is);
            }
            catch (Exception e) {
                n2bbLog.error("failed to load orb properties - message... " + e.getMessage(), e);
            }
        }

        OrbManager.setProperties(props);

    }

    public void destroy() {
        OrbManager.destroy();
    }

}

