KickJava   Java API By Example, From Geeks To Geeks.

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


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: DeploymentDescModifier.java,v 1.8 2005/07/18 23:53:30 mwringe 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.Text JavaDoc;
30
31 import org.objectweb.jonas.common.Log;
32
33 import org.objectweb.util.monolog.api.Logger;
34
35 /**
36  * Modify an Element from a Deployment Descriptor. Contains XML commons
37  * utilities.
38  *
39  * @author Guillaume Sauthier
40  */

41 public class DeploymentDescModifier {
42
43     /** J2EE Default XML namespace */
44     protected static final String JavaDoc J2EE_NS = "http://java.sun.com/xml/ns/j2ee";
45
46     /** JOnAS Default XML namespace */
47     protected static final String JavaDoc JONAS_NS = "http://www.objectweb.org/jonas/ns";
48
49     /** logger */
50     private static Logger logger = Log.getLogger(Log.JONAS_WSGEN_PREFIX);
51
52     /** base element */
53     private Element JavaDoc element;
54
55     /** parent element */
56     private Element JavaDoc parent;
57
58     /** base document */
59     private Document JavaDoc doc;
60
61     /**
62      * Create a new DeploymentDescModifier to update the given Element.
63      *
64      * @param element XML element to be modified.
65      * @param doc base document for Element creation.
66      */

67     public DeploymentDescModifier(Element JavaDoc element, Document JavaDoc doc) {
68         this(element, doc, null);
69     }
70
71     /**
72      * Create a new DeploymentDescModifier to update the given Element.
73      *
74      * @param element XML element to be modified.
75      * @param doc base document for Element creation.
76      * @param parent parent Element, used if element is null
77      */

78     public DeploymentDescModifier(Element JavaDoc element, Document JavaDoc doc, Element JavaDoc parent) {
79         this.element = element;
80         this.doc = doc;
81         this.parent = parent;
82     }
83
84     /**
85      * Create a new Element with given name in J2EE XML namespace.
86      *
87      * @param name Element name
88      *
89      * @return the created Element
90      */

91     protected Element JavaDoc newJ2EEElement(String JavaDoc name) {
92         return doc.createElementNS(J2EE_NS, name);
93     }
94
95     /**
96      * Create a new Element with given name in J2EE XML namespace with an inner
97      * Text Node.
98      *
99      * @param name Element name
100      * @param text Element content
101      *
102      * @return the created Element
103      */

104     protected Element JavaDoc newJ2EEElement(String JavaDoc name, String JavaDoc text) {
105         Element JavaDoc e = doc.createElementNS(J2EE_NS, name);
106         Text JavaDoc txt = doc.createTextNode(text);
107         e.appendChild(txt);
108
109         return e;
110     }
111
112     /**
113      * Create a new Element with given name in JOnAS XML namespace.
114      *
115      * @param name Element name
116      *
117      * @return the created Element
118      */

119     protected Element JavaDoc newJOnASElement(String JavaDoc name) {
120         return doc.createElementNS(JONAS_NS, name);
121     }
122
123     /**
124      * Create a new Element with given name in JOnAS XML namespace, with an
125      * inner Text Node.
126      *
127      * @param name Element name
128      * @param text node's text
129      *
130      * @return the created Element
131      */

132     protected Element JavaDoc newJOnASElement(String JavaDoc name, String JavaDoc text) {
133         Element JavaDoc e = doc.createElementNS(JONAS_NS, name);
134         Text JavaDoc txt = doc.createTextNode(text);
135         e.appendChild(txt);
136
137         return e;
138     }
139
140
141     /**
142      * Create a new Element with given name
143      *
144      * @param name Element name
145      * @return the created Element
146      */

147     protected Element JavaDoc newElement (String JavaDoc name) {
148          return doc.createElement(name);
149     }
150
151     /**
152      * Create a new Element with an inner Text Node.
153      *
154      * @param name Element name
155      * @param text node's text
156      *
157      * @return the created Element
158      */

159     protected Element JavaDoc newElement (String JavaDoc name, String JavaDoc text) {
160         Element JavaDoc e = doc.createElement(name);
161         Text JavaDoc txt = doc.createTextNode(text);
162         e.appendChild(txt);
163
164         return e;
165     }
166
167     /**
168      * @return Returns the logger.
169      */

170     public static Logger getLogger() {
171         return logger;
172     }
173
174     /**
175      * @return Returns the parent (can be null).
176      */

177     public Element JavaDoc getParent() {
178         return parent;
179     }
180
181     /**
182      * @return Returns the element.
183      */

184     public Element JavaDoc getElement() {
185         return element;
186     }
187
188     /**
189      * @return Returns the document.
190      */

191     public Document JavaDoc getDocument() {
192         return doc;
193     }
194
195     /**
196      * Set the new document to use
197      * @param doc the new document to use
198      */

199     public void setDocument(Document JavaDoc doc) {
200         this.doc = doc;
201         this.parent = doc.getDocumentElement();
202     }
203
204     /**
205      * Set the new base Element to use
206      * @param e the new base Element to use
207      */

208     public void setElement(Element JavaDoc e) {
209         element = e;
210         getParent().appendChild(e);
211     }
212
213 }
Popular Tags