/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2005 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
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.container;

import java.net.URL;

import javax.naming.Context;

import org.objectweb.jonas_ejb.container.Container;
import org.objectweb.jonas_lib.JWorkManager;

import org.objectweb.jonas.service.Service;
import org.objectweb.jonas.service.ServiceException;

/**
 * EJB Service interface.
 */
public interface EJBService extends Service {

    /**
     * Create a JOnAS Container for all the beans that are described in a .xml file,
     * or belong to .jar file.
     * @param ctx JNDI context in which is found the container configuration.
     * @return The ObjectName of the MBean associated to the container (i.e. to the deployed module)
     */
    String createContainer(Context ctx) throws Exception;

    String createContainer(String fileName) throws Exception;

    /**
     * Test if the specified file is already deployed (if a container
     * is created for this jar).
     * @param fileName the name of the jar file
     * @return true if the jar was deployed, false otherwise
     */
    Boolean isJarDeployed(String fileName);

    /**
     * Test if the specified jar identified with its work name is already deployed
     * (if a container is created for this jar).
     * @param workFileName the internal name of the jar file (working copy)
     * @return true if the jar was deployed, false otherwise
     */
    boolean isJarDeployedByWorkName(String workFileName);

    /**
     * @return the Container by its file name (.xml or .jar)
     */
    Container getContainer(String fileName);

    /**
     * Remove a  JOnAS Container.
     * @param cont JOnAS container to remove.
     */
    void removeContainer(Container cont);

    void removeContainer(String fileName) throws Exception;

    /**
     * List of all JOnAS Containers
     * @return an array of Container objects
     */
    Container[] listContainers();

    /**
     * Synchronized all entity bean containers
     * @param passivate passivate instances after synchronization.
     */
    void syncAllEntities(boolean passivate);

    /**
     * Deploy the given ejb-jars of an ear file with the specified parent
     * classloader (ear classloader). (This method is only used for
     * the ear applications, not for the ejb-jar applications).
     * @param ctx the context containing the configuration
     * to deploy the ejbjars.<BR>
     * This context contains the following parameters :<BR>
     *    - earRootUrl the root of the ear application.<BR>
     *    - earClassLoader the ear classLoader of the ear application.<BR>
     *    - ejbClassLoader the ejb classLoader for the ejbjars.<BR>
     *    - jarURLs the list of the urls of the ejb-jars to deploy.<BR>
     *    - roleNames the role names of the security-role.<BR>
     * @return ClassLoader the ejbClassLoader created.
     * @throws ServiceException if an error occurs during the deployment.
     */
    void deployJars(Context ctx)throws ServiceException;

    /**
     * Undeploy the given ejb-jars of an ear file with the specified parent
     * classloader (ear classloader). (This method is only used for
     * the ear applications, not for the ejb-jar applications).
     * @param urls the list of the urls of the ejb-jars to deploy.
     */
    void unDeployJars(URL[] urls);

    /**
     * Make a cleanup of the cache of deployment descriptor. This method must
     * be invoked after the ear deployment by the EAR service.
     * the deployment of an ear by .
     * @param earClassLoader the ClassLoader of the ear application to
     * remove from the cache.
     */
    void removeCache(ClassLoader earClassLoader);

    /**
     * Return the Ejbjars directory.
     * @return The Ejbjars directory
     */
    String getEjbjarsDirectory();


    /**
     * Check that GenIC have been applied on the given ejb-jar file
     * If it was not done, it run GenIC against the file.
     * @param fileName given EJB-JAR file.
     * @param urls Array of URLs used as CLASSPATH during EJB compilation
     */
    void checkGenIC(String fileName, URL[] urls);

    /**
     * Get the workManager
     */
    JWorkManager getWorkManager();
}

