KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > ddmodifier > WebServicesDDModifier


1 /**
2  * JOnAS : Java(TM) OpenSource Application Server
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA
18  *
19  * Initial Developer : Guillaume Sauthier
20  * --------------------------------------------------------------------------
21  * $Id: WebServicesDDModifier.java,v 1.2 2004/04/19 13:49:54 sauthieg Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas_ws.wsgen.ddmodifier;
26
27 import org.w3c.dom.Document JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29 import org.w3c.dom.Node JavaDoc;
30 import org.w3c.dom.NodeList JavaDoc;
31
32 /**
33  * @author Guillaume Sauthier
34  */

35 public class WebServicesDDModifier extends DeploymentDescModifier {
36
37     /**
38      * @param doc webservices.xml Document
39      */

40     public WebServicesDDModifier(Document JavaDoc doc) {
41         super(doc.getDocumentElement(), doc);
42     }
43
44     /**
45      * Update the servlet-link element in webservices.xml to the Generated servlet element.
46      *
47      * @param wsdName WebService Description name
48      * @param link old servlet-link value
49      * @param replace new servlet-link value
50      */

51     public void changeServletLink(String JavaDoc wsdName, String JavaDoc link, String JavaDoc replace) {
52
53         Element JavaDoc wsd = findWebserviceDesc(wsdName);
54
55         // if element found
56
if (wsd != null) {
57             NodeList JavaDoc nl = wsd.getElementsByTagNameNS(J2EE_NS, "port-component");
58
59             for (int i = 0; i < nl.getLength(); i++) {
60                 Element JavaDoc e = (Element JavaDoc) nl.item(i);
61                 NodeList JavaDoc sib = e.getElementsByTagNameNS(J2EE_NS, "service-impl-bean");
62
63                 Node JavaDoc servletLink = ((Element JavaDoc) sib.item(0)).getElementsByTagNameNS(J2EE_NS, "servlet-link").item(0);
64
65                 // test
66
// port-component/sib-link/servlet-link/#text-node.value
67
if (servletLink.getFirstChild().getNodeValue().equals(link)) {
68                     servletLink.getFirstChild().setNodeValue(replace);
69                 }
70             }
71         }
72     }
73
74     /**
75      * Search element for webservices-description named with the given name.
76      *
77      * @param name the searched webservices-description name
78      *
79      * @return the found element or null if element is not found (should'nt
80      * occurs).
81      */

82     private Element JavaDoc findWebserviceDesc(String JavaDoc name) {
83         NodeList JavaDoc nl = getElement().getElementsByTagNameNS(J2EE_NS, "webservice-description");
84         Element JavaDoc wsd = null;
85
86         for (int i = 0; (i < nl.getLength()) && (wsd == null); i++) {
87             Element JavaDoc e = (Element JavaDoc) nl.item(i);
88
89             NodeList JavaDoc names = e.getElementsByTagNameNS(J2EE_NS, "webservice-description-name");
90
91             // test
92
// webservices-description/webservices-description--name/#text-node.value
93
if (names.item(0).getFirstChild().getNodeValue().equals(name)) {
94                 wsd = e;
95             }
96         }
97
98         return wsd;
99     }
100
101 }
Popular Tags