/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2006 Bull S.A.S.
 * 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_ws.wsgen.finder;

import java.util.Iterator;
import java.util.List;

import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;

/**
 * <code>WebServicesXmlFinder</code> finds out if there is any
 * <code>webservices.xml</code> within the given {@link J2EEArchive}.
 *
 * @author Guillaume Sauthier
 */
public class WebServicesXmlFinder implements J2EEWebServicesFinder {

    /**
     * WebApp's webservices.xml.
     */
    private static final String WEBINF_WEBSERVICES_XML = "WEB-INF/webservices.xml";

    /**
     * EjbJar's webservices.xml.
     */
    private static final String METAINF_WEBSERVICES_XML = "META-INF/webservices.xml";

    /**
     * Archive to browse.
     */
    private J2EEArchive archive = null;

    /**
     * Constructs a <code>WebServicesXmlFinder</code> that will
     * explore the given {@link J2EEArchive}.
     * @param archive archive to explore.
     */
    public WebServicesXmlFinder(J2EEArchive archive) {
        this.archive = archive;
    }

    /**
     * @see org.objectweb.jonas_ws.wsgen.finder.J2EEWebServicesFinder#find()
     */
    public boolean find() {
        List files = archive.getContainedFiles();
        for (Iterator i = files.iterator(); i.hasNext();) {
            String filename = (String) i.next();
            if (WEBINF_WEBSERVICES_XML.equals(filename)
                || METAINF_WEBSERVICES_XML.equals(filename)) {
                return true;
            }
        }
        return false;
    }

}
