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: GeneralWSFinder.java 8253 2006-04-18 11:40:19Z sauthieg $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ws.wsgen.finder;
025:
026: import java.util.Iterator;
027:
028: import org.objectweb.jonas_lib.genbase.archive.Application;
029: import org.objectweb.jonas_lib.genbase.archive.Client;
030: import org.objectweb.jonas_lib.genbase.archive.EjbJar;
031: import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
032: import org.objectweb.jonas_lib.genbase.archive.WebApp;
033:
034: /**
035: * <code>GeneralWSFinder</code> is a wrapper for ear and other J2EE module types.
036: *
037: * @author Guillaume Sauthier
038: */
039: public class GeneralWSFinder implements J2EEWebServicesFinder {
040:
041: /**
042: * Explored archive.
043: */
044: private J2EEArchive archive = null;
045:
046: /**
047: * Creates a WSFinder suitable for all types of modules.
048: * @param archive Explored archive.
049: */
050: public GeneralWSFinder(J2EEArchive archive) {
051: super ();
052: this .archive = archive;
053: }
054:
055: /**
056: * @see org.objectweb.jonas_ws.wsgen.finder.J2EEWebServicesFinder#find()
057: */
058: public boolean find() {
059:
060: if (archive instanceof Application) {
061: // explore sub modules
062: Application app = (Application) archive;
063:
064: // If any ejbjar has a webservice, return directly
065: for (Iterator i = app.getEjbJars(); i.hasNext();) {
066: EjbJar ejb = (EjbJar) i.next();
067: if (findWebServicesInEjbJar(ejb)) {
068: return true;
069: }
070: }
071:
072: // If any webapp has a webservice, return directly
073: for (Iterator i = app.getWebApps(); i.hasNext();) {
074: WebApp web = (WebApp) i.next();
075: if (findWebServicesInWebApp(web)) {
076: return true;
077: }
078: }
079:
080: //If any client has a webservice, return directly
081: for (Iterator i = app.getClients(); i.hasNext();) {
082: Client client = (Client) i.next();
083: if (findWebServicesInClient(client)) {
084: return true;
085: }
086: }
087:
088: } else if (archive instanceof EjbJar) {
089: return findWebServicesInEjbJar((EjbJar) archive);
090: } else if (archive instanceof WebApp) {
091: return findWebServicesInWebApp((WebApp) archive);
092: } else if (archive instanceof Client) {
093: return findWebServicesInClient((Client) archive);
094: }
095: return false;
096: }
097:
098: /**
099: * @param archive The archive to explore.
100: * @return Returns <code>true</code> if the Client has WebServices.
101: */
102: private static boolean findWebServicesInClient(Client archive) {
103: J2EEWebServicesFinder finder = new GenericWSFinder(archive,
104: "META-INF/application-client.xml");
105: return finder.find();
106: }
107:
108: /**
109: * @param archive The archive to explore.
110: * @return Returns <code>true</code> if the WebApp has WebServices.
111: */
112: private static boolean findWebServicesInWebApp(WebApp archive) {
113: J2EEWebServicesFinder finder = new GenericWSFinder(archive,
114: "WEB-INF/web.xml");
115: return finder.find();
116: }
117:
118: /**
119: * @param archive The archive to explore.
120: * @return Returns <code>true</code> if the EjbJar has WebServices.
121: */
122: private static boolean findWebServicesInEjbJar(EjbJar archive) {
123: J2EEWebServicesFinder finder = new GenericWSFinder(archive,
124: "META-INF/ejb-jar.xml");
125: return finder.find();
126: }
127:
128: }
|