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: DeploymentDescModifier.java 7057 2005-07-18 23:53:31Z mwringe $
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.Text;
028:
029: import org.objectweb.jonas.common.Log;
030:
031: import org.objectweb.util.monolog.api.Logger;
032:
033: /**
034: * Modify an Element from a Deployment Descriptor. Contains XML commons
035: * utilities.
036: *
037: * @author Guillaume Sauthier
038: */
039: public class DeploymentDescModifier {
040:
041: /** J2EE Default XML namespace */
042: protected static final String J2EE_NS = "http://java.sun.com/xml/ns/j2ee";
043:
044: /** JOnAS Default XML namespace */
045: protected static final String JONAS_NS = "http://www.objectweb.org/jonas/ns";
046:
047: /** logger */
048: private static Logger logger = Log
049: .getLogger(Log.JONAS_WSGEN_PREFIX);
050:
051: /** base element */
052: private Element element;
053:
054: /** parent element */
055: private Element parent;
056:
057: /** base document */
058: private Document doc;
059:
060: /**
061: * Create a new DeploymentDescModifier to update the given Element.
062: *
063: * @param element XML element to be modified.
064: * @param doc base document for Element creation.
065: */
066: public DeploymentDescModifier(Element element, Document doc) {
067: this (element, doc, null);
068: }
069:
070: /**
071: * Create a new DeploymentDescModifier to update the given Element.
072: *
073: * @param element XML element to be modified.
074: * @param doc base document for Element creation.
075: * @param parent parent Element, used if element is null
076: */
077: public DeploymentDescModifier(Element element, Document doc,
078: Element parent) {
079: this .element = element;
080: this .doc = doc;
081: this .parent = parent;
082: }
083:
084: /**
085: * Create a new Element with given name in J2EE XML namespace.
086: *
087: * @param name Element name
088: *
089: * @return the created Element
090: */
091: protected Element newJ2EEElement(String name) {
092: return doc.createElementNS(J2EE_NS, name);
093: }
094:
095: /**
096: * Create a new Element with given name in J2EE XML namespace with an inner
097: * Text Node.
098: *
099: * @param name Element name
100: * @param text Element content
101: *
102: * @return the created Element
103: */
104: protected Element newJ2EEElement(String name, String text) {
105: Element e = doc.createElementNS(J2EE_NS, name);
106: Text 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 newJOnASElement(String 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 newJOnASElement(String name, String text) {
133: Element e = doc.createElementNS(JONAS_NS, name);
134: Text txt = doc.createTextNode(text);
135: e.appendChild(txt);
136:
137: return e;
138: }
139:
140: /**
141: * Create a new Element with given name
142: *
143: * @param name Element name
144: * @return the created Element
145: */
146: protected Element newElement(String name) {
147: return doc.createElement(name);
148: }
149:
150: /**
151: * Create a new Element with an inner Text Node.
152: *
153: * @param name Element name
154: * @param text node's text
155: *
156: * @return the created Element
157: */
158: protected Element newElement(String name, String text) {
159: Element e = doc.createElement(name);
160: Text txt = doc.createTextNode(text);
161: e.appendChild(txt);
162:
163: return e;
164: }
165:
166: /**
167: * @return Returns the logger.
168: */
169: public static Logger getLogger() {
170: return logger;
171: }
172:
173: /**
174: * @return Returns the parent (can be null).
175: */
176: public Element getParent() {
177: return parent;
178: }
179:
180: /**
181: * @return Returns the element.
182: */
183: public Element getElement() {
184: return element;
185: }
186:
187: /**
188: * @return Returns the document.
189: */
190: public Document getDocument() {
191: return doc;
192: }
193:
194: /**
195: * Set the new document to use
196: * @param doc the new document to use
197: */
198: public void setDocument(Document doc) {
199: this .doc = doc;
200: this .parent = doc.getDocumentElement();
201: }
202:
203: /**
204: * Set the new base Element to use
205: * @param e the new base Element to use
206: */
207: public void setElement(Element e) {
208: element = e;
209: getParent().appendChild(e);
210: }
211:
212: }
|