/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * Initial developer(s): ____________________________________.
 * Contributor(s): Michel Bruno and Guillaume Riviere
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.resource;

import java.util.Properties;
import java.io.File;
import java.net.URL;

/**
 * MBean class for general Resource Management
 * MBean type: Standard
 * MBean model: delegate
 *
 * @author Michel Bruno and Guillaume Riviere<br>
 * Contributor Michel-Ange Anton (add 'filename', 'inEarCase', 'earURL' properties)
 *
 */
public class JmxResourceAdapter implements JmxResourceAdapterMBean {

    /**
     * Properties associated with the RAR
     */
    private Properties prop = null;
    /**
     * Jndi name
     */
    private String jndiname = null;
    /**
     * Filename of the RAR
     */
    private String filename = null;
    /**
     * Boolean if the RAR is in an EAR file
     */
    private boolean inEarCase = false;
    /**
     * URL of the EAR if used
     */
    private URL earURL = null;

    /**
     * Constructor
     * @param prop Properties of RAR
     * @param jndiname String of RAR
     * @param filename String of RAR filename
     * @param inEarCase boolean if in an EAR file
     * @param earURL URL of EAR file
     */
    public JmxResourceAdapter(Properties prop, String jndiname, String filename,
        boolean inEarCase, URL earURL) {
        this.prop = prop;
        this.jndiname =  jndiname;
        // To avoid trouble between OS (Unix <-> Windows)
        try {
            this.filename = (new File(filename)).toURL().getPath();
        } catch (Exception e) {
            this.filename = filename;
        }
        this.inEarCase = inEarCase;
        this.earURL = earURL;
    }

    /**
     * return the Adaptor Properties
     * @return Properties adaptor properties
     */
    public Properties getProperties() {
        return prop;
    }

    /**
     * return the jndi name
     * @return String jndiname
     */
    public String getJndiName() {
        return jndiname;
    }

    /**
     * Accessor the filename of the resource adapter.
     * @return String the filename
     */
    public String getFilename() {
        return filename;
    }

    /**
     * Accessor the flag indicating if the resource adapter is in Ear.
     * @return boolean Flag if this resource adapter is in Ear
     */
    public boolean isInEarCase() {
        return inEarCase;
    }

    /**
     * Accessor the URL of the Ear if the resource adapter is in Ear.
     * @return URL of the Ear or null
     */
    public URL getEarURL() {
        return earURL;
    }
}
