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: *
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or 1any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020: * USA
021: *
022: * Initial developer: JOnAS team
023: * --------------------------------------------------------------------------
024: * $Id: EjbJar.java 4716 2004-05-10 11:45:44Z sauthieg $
025: * --------------------------------------------------------------------------
026: */package org.objectweb.jonas_ejb.deployment.xml;
027:
028: import java.util.ArrayList;
029: import java.util.StringTokenizer;
030:
031: import org.objectweb.jonas_lib.deployment.xml.AbsDescriptionElement;
032: import org.objectweb.jonas_lib.deployment.xml.DescriptionGroupXml;
033: import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;
034:
035: /**
036: * This class defines the implementation of the element ejb-jar
037: *
038: * @author JOnAS team
039: */
040:
041: public class EjbJar extends AbsDescriptionElement implements
042: TopLevelElement, DescriptionGroupXml {
043:
044: /**
045: * Position of Version Number in Public ID Spec
046: */
047: private static final int VERSION_INDEX = 3;
048:
049: /**
050: * enterprise-beans
051: */
052: private EnterpriseBeans enterpriseBeans = null;
053:
054: /**
055: * relationships
056: */
057: private Relationships relationships = null;
058:
059: /**
060: * assembly-descriptor
061: */
062: private AssemblyDescriptor assemblyDescriptor = null;
063:
064: /**
065: * ejb-client-jar
066: */
067: private String ejbClientJar = null;
068:
069: /**
070: * PublicId of the DTD we are processing
071: */
072: private String publicId = null;
073:
074: /**
075: * Version of the EJB specification
076: * is built from the publicId if DOCTYPE
077: * or via the attribute version ins case of schema
078: */
079: private String version = null;
080:
081: /**
082: * Constructor
083: */
084: public EjbJar() {
085: super ();
086: }
087:
088: /**
089: * Get the PublicId of the DTD used
090: * @return the PublicId
091: */
092: public String getPublicId() {
093: return publicId;
094: }
095:
096: /**
097: * Set the PublicId of the DTD used
098: * @param pid the publicId
099: */
100: public void setPublicId(String pid) {
101: publicId = pid;
102: }
103:
104: /**
105: * Get the Version of the EJB specification
106: * @return the Version
107: */
108: public String getVersion() {
109: if (version != null) {
110: return version;
111: }
112: if (publicId == null) {
113: // No DOCTYPE and No version attribute in ejb-jar element
114: version = "2.1";
115: } else {
116: ArrayList al = new ArrayList();
117: // Version must be set via the PublicId of the DOCTYPE
118: StringTokenizer st = new StringTokenizer(publicId, "//");
119: while (st.hasMoreTokens()) {
120: al.add(st.nextToken().trim());
121: }
122: String spec = (String) al.get(2);
123: al.clear();
124: st = new StringTokenizer(spec, " ");
125: while (st.hasMoreTokens()) {
126: al.add(st.nextToken().trim());
127: }
128: version = (String) al.get(VERSION_INDEX);
129: }
130: return version;
131:
132: }
133:
134: /**
135: * Set the Version of the EJB specification
136: *
137: * @param ver the version
138: */
139: public void setVersion(String ver) {
140: version = ver;
141: }
142:
143: /**
144: * Gets the enterprise-beans
145: * @return the enterprise-beans
146: */
147: public EnterpriseBeans getEnterpriseBeans() {
148: return enterpriseBeans;
149: }
150:
151: /**
152: * Set the enterprise-beans
153: * @param enterpriseBeans enterpriseBeans
154: */
155: public void setEnterpriseBeans(EnterpriseBeans enterpriseBeans) {
156: this .enterpriseBeans = enterpriseBeans;
157: }
158:
159: /**
160: * Gets the relationships
161: * @return the relationships
162: */
163: public Relationships getRelationships() {
164: return relationships;
165: }
166:
167: /**
168: * Set the relationships
169: * @param relationships relationships
170: */
171: public void setRelationships(Relationships relationships) {
172: this .relationships = relationships;
173: }
174:
175: /**
176: * Gets the assembly-descriptor
177: * @return the assembly-descriptor
178: */
179: public AssemblyDescriptor getAssemblyDescriptor() {
180: return assemblyDescriptor;
181: }
182:
183: /**
184: * Set the assembly-descriptor
185: * @param assemblyDescriptor assemblyDescriptor
186: */
187: public void setAssemblyDescriptor(
188: AssemblyDescriptor assemblyDescriptor) {
189: this .assemblyDescriptor = assemblyDescriptor;
190: }
191:
192: /**
193: * Gets the ejb-client-jar
194: * @return the ejb-client-jar
195: */
196: public String getEjbClientJar() {
197: return ejbClientJar;
198: }
199:
200: /**
201: * Set the ejb-client-jar
202: * @param ejbClientJar ejbClientJar
203: */
204: public void setEjbClientJar(String ejbClientJar) {
205: this .ejbClientJar = ejbClientJar;
206: }
207:
208: /**
209: * Represents this element by it's XML description.
210: * @param indent use this indent for prexifing XML representation.
211: * @return the XML description of this object.
212: */
213: public String toXML(int indent) {
214: StringBuffer sb = new StringBuffer();
215: sb.append(indent(indent));
216: sb.append("<ejb-jar>\n");
217:
218: indent += 2;
219:
220: // description
221: sb.append(xmlElement(getDescription(), "description", indent));
222: // display-name
223: sb.append(xmlElement(getDisplayName(), "display-name", indent));
224: // small-icon
225: sb.append(xmlElement(getIcon().getSmallIcon(), "small-icon",
226: indent));
227: // large-icon
228: sb.append(xmlElement(getIcon().getLargeIcon(), "large-icon",
229: indent));
230: // enterprise-beans
231: if (enterpriseBeans != null) {
232: sb.append(enterpriseBeans.toXML(indent));
233: }
234: // relationships
235: if (relationships != null) {
236: sb.append(relationships.toXML(indent));
237: }
238: // assembly-descriptor
239: if (assemblyDescriptor != null) {
240: sb.append(assemblyDescriptor.toXML(indent));
241: }
242: // ejb-client-jar
243: sb.append(xmlElement(ejbClientJar, "ejb-client-jar", indent));
244: indent -= 2;
245: sb.append(indent(indent));
246: sb.append("</ejb-jar>\n");
247:
248: return sb.toString();
249: }
250: }
|