001: /**
002: * JOnAS : Java(TM) OpenSource Application Server
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017: * USA
018: *
019: * Initial Developer : Guillaume Sauthier
020: * --------------------------------------------------------------------------
021: * $Id: WebServicesDDModifier.java 4622 2004-04-19 13:49:54Z sauthieg $
022: * --------------------------------------------------------------------------
023: */package org.objectweb.jonas_ws.wsgen.ddmodifier;
024:
025: import org.w3c.dom.Document;
026: import org.w3c.dom.Element;
027: import org.w3c.dom.Node;
028: import org.w3c.dom.NodeList;
029:
030: /**
031: * @author Guillaume Sauthier
032: */
033: public class WebServicesDDModifier extends DeploymentDescModifier {
034:
035: /**
036: * @param doc webservices.xml Document
037: */
038: public WebServicesDDModifier(Document doc) {
039: super (doc.getDocumentElement(), doc);
040: }
041:
042: /**
043: * Update the servlet-link element in webservices.xml to the Generated servlet element.
044: *
045: * @param wsdName WebService Description name
046: * @param link old servlet-link value
047: * @param replace new servlet-link value
048: */
049: public void changeServletLink(String wsdName, String link,
050: String replace) {
051:
052: Element wsd = findWebserviceDesc(wsdName);
053:
054: // if element found
055: if (wsd != null) {
056: NodeList nl = wsd.getElementsByTagNameNS(J2EE_NS,
057: "port-component");
058:
059: for (int i = 0; i < nl.getLength(); i++) {
060: Element e = (Element) nl.item(i);
061: NodeList sib = e.getElementsByTagNameNS(J2EE_NS,
062: "service-impl-bean");
063:
064: Node servletLink = ((Element) sib.item(0))
065: .getElementsByTagNameNS(J2EE_NS, "servlet-link")
066: .item(0);
067:
068: // test
069: // port-component/sib-link/servlet-link/#text-node.value
070: if (servletLink.getFirstChild().getNodeValue().equals(
071: link)) {
072: servletLink.getFirstChild().setNodeValue(replace);
073: }
074: }
075: }
076: }
077:
078: /**
079: * Search element for webservices-description named with the given name.
080: *
081: * @param name the searched webservices-description name
082: *
083: * @return the found element or null if element is not found (should'nt
084: * occurs).
085: */
086: private Element findWebserviceDesc(String name) {
087: NodeList nl = getElement().getElementsByTagNameNS(J2EE_NS,
088: "webservice-description");
089: Element wsd = null;
090:
091: for (int i = 0; (i < nl.getLength()) && (wsd == null); i++) {
092: Element e = (Element) nl.item(i);
093:
094: NodeList names = e.getElementsByTagNameNS(J2EE_NS,
095: "webservice-description-name");
096:
097: // test
098: // webservices-description/webservices-description--name/#text-node.value
099: if (names.item(0).getFirstChild().getNodeValue().equals(
100: name)) {
101: wsd = e;
102: }
103: }
104:
105: return wsd;
106: }
107:
108: }
|