001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
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 1any 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: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: JonasWebApp.java 7467 2005-10-04 12:53:14Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_web.deployment.xml;
026:
027: import org.objectweb.jonas_lib.deployment.xml.AbsJonasEnvironmentElement;
028: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
029: import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestination;
030: import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;
031:
032: import org.objectweb.jonas_web.deployment.api.JonasWebAppSchemas;
033:
034: /**
035: * This class defines the implementation of the element jonas-web-app.
036: * @author Florent Benoit
037: */
038: public class JonasWebApp extends AbsJonasEnvironmentElement implements
039: TopLevelElement {
040:
041: /**
042: * Header (with right XSD version) for XML
043: */
044: private String header = null;
045:
046: /**
047: * Host element
048: */
049: private String host = null;
050:
051: /**
052: * Context-root element
053: */
054: private String contextRoot = null;
055:
056: /**
057: * Port to use (used by web services)
058: */
059: private String port = null;
060:
061: /**
062: * Follow the java 2 delegation model or not
063: */
064: private String java2DelegationModel = null;
065:
066: /**
067: * jonas-message-destination
068: */
069: private JLinkedList jonasMessageDestinationList = null;
070:
071: /**
072: * jonas-web-app element XML header
073: */
074: public static final String JONAS_WEBAPP_ELEMENT = "<?xml version=\"1.0\"?>\n"
075: + "<jonas-web-app xmlns=\"http://www.objectweb.org/jonas/ns\"\n"
076: + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
077: + " xsi:schemaLocation=\"http://www.objectweb.org/jonas/ns\n"
078: + " http://www.objectweb.org/jonas/ns/"
079: + JonasWebAppSchemas.getLastSchema() + "\">\n";
080:
081: /**
082: * Constructor : build a new WebApp object
083: */
084: public JonasWebApp() {
085: super ();
086: jonasMessageDestinationList = new JLinkedList(
087: "jonas-message-destination");
088:
089: header = JONAS_WEBAPP_ELEMENT;
090: }
091:
092: // Setters
093:
094: /**
095: * Set the host element of this object
096: * @param host host element of this object
097: */
098: public void setHost(String host) {
099: this .host = host;
100: }
101:
102: /**
103: * Set the context-root element of this object
104: * @param contextRoot context-root element of this object
105: */
106: public void setContextRoot(String contextRoot) {
107: this .contextRoot = contextRoot;
108: }
109:
110: /**
111: * Set the port element of this object
112: * @param port port element of this object
113: */
114: public void setPort(String port) {
115: this .port = port;
116: }
117:
118: /**
119: * Set the java 2 delegation model element of this object
120: * @param java2DelegationModel java2-delegation-model element of this object
121: */
122: public void setJava2DelegationModel(String java2DelegationModel) {
123: this .java2DelegationModel = java2DelegationModel;
124: }
125:
126: /**
127: * Set the jonas-message-destination
128: * @param jonasMessageDestinationList jonasMessageDestination
129: */
130: public void setJonasMessageDestinationList(
131: JLinkedList jonasMessageDestinationList) {
132: this .jonasMessageDestinationList = jonasMessageDestinationList;
133: }
134:
135: /**
136: * Add a new jonas-message-destination element to this object
137: * @param jonasMessageDestination the jonas-message-destination object
138: */
139: public void addJonasMessageDestination(
140: JonasMessageDestination jonasMessageDestination) {
141: jonasMessageDestinationList.add(jonasMessageDestination);
142: }
143:
144: // Getters
145:
146: /**
147: * @return the host element
148: */
149: public String getHost() {
150: return host;
151: }
152:
153: /**
154: * @return the context-root element
155: */
156: public String getContextRoot() {
157: return contextRoot;
158: }
159:
160: /**
161: * @return the port element
162: */
163: public String getPort() {
164: return port;
165: }
166:
167: /**
168: * @return the java2-delegation-model element
169: */
170: public String getJava2DelegationModel() {
171: return java2DelegationModel;
172: }
173:
174: /**
175: * @return the list of all jonas-message-destination elements
176: */
177: public JLinkedList getJonasMessageDestinationList() {
178: return jonasMessageDestinationList;
179: }
180:
181: /**
182: * Represents this element by it's XML description.
183: * @param indent use this indent for prexifing XML representation.
184: * @return the XML description of this object.
185: */
186: public String toXML(int indent) {
187: StringBuffer sb = new StringBuffer();
188: sb.append(indent(indent));
189: if (header != null) {
190: sb.append(header);
191: } else {
192: sb.append("<jonas-web-app>\n");
193: }
194:
195: indent += 2;
196:
197: // jonas-resource-env
198: sb.append(getJonasResourceEnvList().toXML(indent));
199:
200: // jonas-resource
201: sb.append(getJonasResourceList().toXML(indent));
202:
203: // jonas-ejb-ref
204: sb.append(getJonasEjbRefList().toXML(indent));
205:
206: // jonas-message-destination-ref
207: sb.append(getJonasMessageDestinationRefList().toXML(indent));
208:
209: // jonas-message-destination
210: sb.append(getJonasMessageDestinationList().toXML(indent));
211:
212: // jonas-service-ref
213: sb.append(getJonasServiceRefList().toXML(indent));
214:
215: // host
216: if (host != null) {
217: sb.append(xmlElement(host, "host", indent));
218: }
219:
220: // context-root
221: if (contextRoot != null) {
222: sb.append(xmlElement(contextRoot, "context-root", indent));
223: }
224:
225: // port
226: if (port != null) {
227: sb.append(xmlElement(port, "port", indent));
228: }
229:
230: // java2-delegation-model
231: if (java2DelegationModel != null) {
232: sb.append(xmlElement(java2DelegationModel,
233: "java2-delegation-model", indent));
234: }
235:
236: indent -= 2;
237: sb.append(indent(indent));
238: sb.append("</jonas-web-app>");
239:
240: return sb.toString();
241: }
242:
243: /**
244: * @return the header.
245: */
246: public String getHeader() {
247: return header;
248: }
249:
250: /**
251: * @param header The header to set.
252: */
253: public void setHeader(String header) {
254: this.header = header;
255: }
256:
257: }
|