001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: GenericWSFinder.java 8401 2006-05-30 11:26:01Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.finder;
025:
026: import java.io.InputStream;
027:
028: import javax.xml.parsers.ParserConfigurationException;
029: import javax.xml.parsers.SAXParser;
030: import javax.xml.parsers.SAXParserFactory;
031:
032: import org.xml.sax.SAXException;
033:
034: import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
035:
036: import org.objectweb.jonas.common.Log;
037:
038: import org.objectweb.util.monolog.api.BasicLevel;
039: import org.objectweb.util.monolog.api.Logger;
040:
041: /**
042: * Multi-module (EjbJar, WebApp, Client) WebServices Finder.
043: *
044: * @author Guillaume Sauthier
045: */
046: public class GenericWSFinder implements J2EEWebServicesFinder {
047:
048: /**
049: * logger.
050: */
051: private static Logger logger = Log
052: .getLogger(Log.JONAS_WSGEN_PREFIX);
053:
054: /**
055: * The archive to be explored.
056: */
057: private J2EEArchive archive = null;
058:
059: /**
060: * Standard XML descriptor name.
061: */
062: private String descriptorName = null;
063:
064: /**
065: * Create a multi-module type WSFinder.
066: * @param archive The archive to be explored.
067: * @param descriptorName Standard XML descriptor name.
068: */
069: public GenericWSFinder(J2EEArchive archive, String descriptorName) {
070: super ();
071: this .archive = archive;
072: this .descriptorName = descriptorName;
073: }
074:
075: /**
076: * @see org.objectweb.jonas_ws.wsgen.finder.J2EEWebServicesFinder#find()
077: */
078: public boolean find() {
079: J2EEWebServicesFinder wsFinder = new WebServicesXmlFinder(
080: archive);
081:
082: ServiceRefFinder srFinder = new ServiceRefFinder();
083: try {
084: InputStream is = archive.getInputStream(descriptorName);
085: SAXParser parser = getSAXParser();
086: parser.parse(is, srFinder);
087: } catch (Exception e) {
088: logger
089: .log(BasicLevel.DEBUG, "Cannot return a SAXParser",
090: e);
091: // by default, the ServiceRefFinder will return false...
092: }
093:
094: // returns true if there is a webservices.xml and/or some service-ref
095: return wsFinder.find() || srFinder.find();
096: }
097:
098: /**
099: * @return Returns a SAXParser
100: * @throws ParserConfigurationException when Parser cannot be created.
101: * @throws SAXException when Parser cannot be created.
102: */
103: protected SAXParser getSAXParser()
104: throws ParserConfigurationException, SAXException {
105: SAXParserFactory factory = SAXParserFactory.newInstance();
106: factory.setNamespaceAware(true);
107: factory
108: .setFeature(
109: "http://apache.org/xml/features/nonvalidating/load-external-dtd",
110: false);
111: SAXParser parser = factory.newSAXParser();
112: return parser;
113: }
114:
115: }
|