/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2003-2004 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_lib.genbase.modifier;

import java.io.File;
import java.util.jar.JarFile;


/**
 * Used to create the right ArchiveModifier from a given filename (ear, jar,
 * war, ...)
 *
 * @author Guillaume Sauthier
 * @author Florent Benoit (make common class for client stubs and WsGen)
 */
public abstract class AbsModifierFactory {

     /**
     * Application Archive mode
     */
    public static final int APPLICATION = 0;

    /**
     * EjbJar Archive mode
     */
    public static final int EJBJAR = 1;

    /**
     * WebApp Archive mode
     */
    public static final int WEBAPP = 2;

    /**
     * ApplicationClient Archive mode
     */
    public static final int CLIENT = 3;

    /**
     * Utility class (no default public constructor)
     */
    protected AbsModifierFactory() {

    }

    /**
     * returns true if the file is an Application archive.
     *
     * @param jf JarFile to explore.
     *
     * @return true if the file is an Application archive.
     */
    protected static boolean isApplication(JarFile jf) {
        return jf.getEntry("META-INF/application.xml") != null;
    }

    /**
     * returns true if the file is an EjbJar archive.
     *
     * @param jf JarFile to explore.
     *
     * @return true if the file is an EjbJar archive.
     */
    protected static boolean isEjbJar(JarFile jf) {
        return jf.getEntry("META-INF/ejb-jar.xml") != null;
    }

    /**
     * returns true if the file is a WebApp archive.
     *
     * @param jf JarFile to explore.
     *
     * @return true if the file is a WebApp archive.
     */
    protected static boolean isWebApp(JarFile jf) {
        return jf.getEntry("WEB-INF/web.xml") != null;
    }

    /**
     * returns true if the file is a Client archive.
     *
     * @param jf JarFile to explore.
     *
     * @return true if the file is a Client archive.
     */
    protected static boolean isClient(JarFile jf) {
        return jf.getEntry("META-INF/application-client.xml") != null;
    }

    /**
     * returns true if the file is an Application archive.
     *
     * @param f Directory to explore.
     *
     * @return true if the file is an Application archive.
     */
    protected static boolean isApplication(File f) {
        return new File(f, "META-INF" + File.separator + "application.xml").exists();
    }

    /**
     * returns true if the file is an EjbJar archive.
     *
     * @param f Directory to explore.
     *
     * @return true if the file is an EjbJar archive.
     */
    protected static boolean isEjbJar(File f) {
        return new File(f, "META-INF" + File.separator + "ejb-jar.xml").exists();
    }

    /**
     * returns true if the file is a WebApp archive.
     *
     * @param f Directory to explore.
     *
     * @return true if the file is a WebApp archive.
     */
    protected static boolean isWebApp(File f) {
        return new File(f, "WEB-INF" + File.separator + "web.xml").exists();
    }

    /**
     * returns true if the file is a Client archive.
     *
     * @param f Directory to explore.
     *
     * @return true if the file is a Client archive.
     */
    protected static boolean isClient(File f) {
        return new File(f, "META-INF" + File.separator + "application-client.xml").exists();
    }
}