KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > xml > EjbJar


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

27 package org.objectweb.jonas_ejb.deployment.xml;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.StringTokenizer JavaDoc;
31
32 import org.objectweb.jonas_lib.deployment.xml.AbsDescriptionElement;
33 import org.objectweb.jonas_lib.deployment.xml.DescriptionGroupXml;
34 import org.objectweb.jonas_lib.deployment.xml.TopLevelElement;
35
36 /**
37  * This class defines the implementation of the element ejb-jar
38  *
39  * @author JOnAS team
40  */

41
42 public class EjbJar extends AbsDescriptionElement
43     implements TopLevelElement, DescriptionGroupXml {
44
45
46     /**
47      * Position of Version Number in Public ID Spec
48      */

49     private static final int VERSION_INDEX = 3;
50
51     /**
52      * enterprise-beans
53      */

54     private EnterpriseBeans enterpriseBeans = null;
55
56     /**
57      * relationships
58      */

59     private Relationships relationships = null;
60
61     /**
62      * assembly-descriptor
63      */

64     private AssemblyDescriptor assemblyDescriptor = null;
65
66     /**
67      * ejb-client-jar
68      */

69     private String JavaDoc ejbClientJar = null;
70
71     /**
72      * PublicId of the DTD we are processing
73      */

74     private String JavaDoc publicId = null;
75
76     /**
77      * Version of the EJB specification
78      * is built from the publicId if DOCTYPE
79      * or via the attribute version ins case of schema
80      */

81     private String JavaDoc version = null;
82
83     /**
84      * Constructor
85      */

86     public EjbJar() {
87         super();
88     }
89
90     /**
91      * Get the PublicId of the DTD used
92      * @return the PublicId
93      */

94     public String JavaDoc getPublicId() {
95         return publicId;
96     }
97
98     /**
99      * Set the PublicId of the DTD used
100      * @param pid the publicId
101      */

102     public void setPublicId(String JavaDoc pid) {
103         publicId = pid;
104     }
105
106
107     /**
108      * Get the Version of the EJB specification
109      * @return the Version
110      */

111     public String JavaDoc getVersion() {
112         if (version != null) {
113             return version;
114         }
115         if (publicId == null) {
116             // No DOCTYPE and No version attribute in ejb-jar element
117
version = "2.1";
118         } else {
119             ArrayList JavaDoc al = new ArrayList JavaDoc();
120             // Version must be set via the PublicId of the DOCTYPE
121
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(publicId , "//");
122             while (st.hasMoreTokens()) {
123                 al.add(st.nextToken().trim());
124             }
125             String JavaDoc spec = (String JavaDoc) al.get(2);
126             al.clear();
127             st = new StringTokenizer JavaDoc(spec , " ");
128             while (st.hasMoreTokens()) {
129                 al.add(st.nextToken().trim());
130             }
131             version = (String JavaDoc) al.get(VERSION_INDEX);
132         }
133         return version;
134
135     }
136
137     /**
138      * Set the Version of the EJB specification
139      *
140      * @param ver the version
141      */

142     public void setVersion(String JavaDoc ver) {
143         version = ver;
144     }
145
146     /**
147      * Gets the enterprise-beans
148      * @return the enterprise-beans
149      */

150     public EnterpriseBeans getEnterpriseBeans() {
151         return enterpriseBeans;
152     }
153
154     /**
155      * Set the enterprise-beans
156      * @param enterpriseBeans enterpriseBeans
157      */

158     public void setEnterpriseBeans(EnterpriseBeans enterpriseBeans) {
159         this.enterpriseBeans = enterpriseBeans;
160     }
161
162     /**
163      * Gets the relationships
164      * @return the relationships
165      */

166     public Relationships getRelationships() {
167         return relationships;
168     }
169
170     /**
171      * Set the relationships
172      * @param relationships relationships
173      */

174     public void setRelationships(Relationships relationships) {
175         this.relationships = relationships;
176     }
177
178     /**
179      * Gets the assembly-descriptor
180      * @return the assembly-descriptor
181      */

182     public AssemblyDescriptor getAssemblyDescriptor() {
183         return assemblyDescriptor;
184     }
185
186     /**
187      * Set the assembly-descriptor
188      * @param assemblyDescriptor assemblyDescriptor
189      */

190     public void setAssemblyDescriptor(AssemblyDescriptor assemblyDescriptor) {
191         this.assemblyDescriptor = assemblyDescriptor;
192     }
193
194     /**
195      * Gets the ejb-client-jar
196      * @return the ejb-client-jar
197      */

198     public String JavaDoc getEjbClientJar() {
199         return ejbClientJar;
200     }
201
202     /**
203      * Set the ejb-client-jar
204      * @param ejbClientJar ejbClientJar
205      */

206     public void setEjbClientJar(String JavaDoc ejbClientJar) {
207         this.ejbClientJar = ejbClientJar;
208     }
209
210     /**
211      * Represents this element by it's XML description.
212      * @param indent use this indent for prexifing XML representation.
213      * @return the XML description of this object.
214      */

215     public String JavaDoc toXML(int indent) {
216         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
217         sb.append(indent(indent));
218         sb.append("<ejb-jar>\n");
219
220         indent += 2;
221
222         // description
223
sb.append(xmlElement(getDescription(), "description", indent));
224         // display-name
225
sb.append(xmlElement(getDisplayName(), "display-name", indent));
226         // small-icon
227
sb.append(xmlElement(getIcon().getSmallIcon(), "small-icon", indent));
228         // large-icon
229
sb.append(xmlElement(getIcon().getLargeIcon(), "large-icon", 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 }
251
Popular Tags