KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > sun > sunone > ejb > SunONESubTask


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.sun.sunone.ejb;
6
7 import org.apache.commons.logging.Log;
8
9 import xdoclet.XDocletException;
10 import xdoclet.XDocletMessages;
11 import xdoclet.modules.ejb.dd.AbstractEjbDeploymentDescriptorSubTask;
12 import xdoclet.util.LogUtil;
13 import xdoclet.util.Translator;
14
15 /**
16  * Generates configuration files for EJB jars in iPlanet/SunONE
17  *
18  * @author <a HREF="mailto:stevensa@users.sourceforge.net">Andrew Stevens</a>
19  * @created October 01, 2002
20  * @ant.element display-name="SunONE" name="sunone" parent="xdoclet.modules.ejb.EjbDocletTask"
21  * @xdoclet.merge-file file="ejb-env-entries-{0}.xml" relates-to="ias-ejb-jar.xml" description="Same as for
22  * &lt;deploymentdescriptor&gt; subtask (only used for MDBs)."
23  * @xdoclet.merge-file file="mdb-ejbrefs-{0}.xml" relates-to="ias-ejb-jar.xml" description="Same as for
24  * &lt;deploymentdescriptor&gt; subtask, except root element name is mdb-ejb-ref rather than ejb-ref (only used for
25  * MDBs)."
26  * @xdoclet.merge-file file="mdb-resourcerefs-{0}.xml" relates-to="ias-ejb-jar.xml" description="Same as for
27  * &lt;deploymentdescriptor&gt; subtask, except root element name is mdb-resource-ref rather than resource-ref
28  * (only used for MDBs)."
29  * @xdoclet.merge-file file="ejb-resource-env-refs-{0}.xml" relates-to="ias-ejb-jar.xml" description="Same as for
30  * &lt;deploymentdescriptor&gt; subtask (only used for MDBs)."
31  * @xdoclet.merge-file file="sunone-role-mappings.ent" relates-to="ias-ejb-jar.xml, sun-ejb-jar.xml" description="An
32  * Unparsed XML Entity file that contains the &lt;role-mapping&gt; elements."
33  * @xdoclet.merge-file file="sunone-pm-descriptors.xml" relates-to="sun-ejb-jar.xml" description="An XML Document
34  * containing the &lt;pm-descriptors&gt; element."
35  * @xdoclet.merge-file file="sunone-ior-security-config-{0}.xml" relates-to="sun-ejb-jar.xml" description="An XML
36  * Document containing the &lt;ior-security-config&gt; element for a bean."
37  * @version $Revision: 1.3 $
38  * @todo allow for overriding the CMP templates etc.
39  * @todo secondary-table element is not currently supported in the cmp mappings file
40  */

41 public class SunONESubTask extends AbstractEjbDeploymentDescriptorSubTask
42 {
43     /**
44      * The default template file - either ias-ejb-jar_xml.xdt or sun-ejb-jar_xml.xdt, depending on version.
45      */

46     private final static String JavaDoc DEFAULT_TEMPLATE_FILE_70 = "resources/sun-ejb-jar_xml.xdt";
47     private final static String JavaDoc DEFAULT_TEMPLATE_FILE_60 = "resources/ias-ejb-jar_xml.xdt";
48
49     /**
50      * The default generated file name - either ias-ejb-jar.xml or sun-ejb-jar.xml, depending on version.
51      */

52     private final static String JavaDoc GENERATED_FILE_NAME_70 = "sun-ejb-jar.xml";
53     private final static String JavaDoc GENERATED_FILE_NAME_60 = "ias-ejb-jar.xml";
54
55     /**
56      * Public ID of the iPlanet/SunONE-specific DD's DTD.
57      */

58     private final static String JavaDoc SUNONE_DD_PUBLICID_70 = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN";
59     private final static String JavaDoc SUNONE_DD_PUBLICID_60 = "-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN";
60     private final static String JavaDoc SUNONE_DD_PUBLICID_61 = "-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.1//EN";
61
62     /**
63      * System ID of the iPlanet/SunONE-specific DD's DTD.
64      */

65     private final static String JavaDoc SUNONE_DD_SYSTEMID_70 = "http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_0-0.dtd";
66     private final static String JavaDoc SUNONE_DD_SYSTEMID_60 = "http://developer.iplanet.com/appserver/dtds/IASEjb_jar_1_0.dtd";
67     private final static String JavaDoc SUNONE_DD_SYSTEMID_61 = "http://developer.iplanet.com/appserver/dtds/IASEjb_jar_1_1.dtd";
68
69     /**
70      * Path to the local copy of the iPlanet/SunONE-specific DD's DTD.
71      */

72     private final static String JavaDoc SUNONE_DD_DTD_FILE_NAME_70 = "resources/sun-ejb-jar_2_0-0.dtd";
73     private final static String JavaDoc SUNONE_DD_DTD_FILE_NAME_60 = "resources/IASEjb_jar_1_0.dtd";
74     private final static String JavaDoc SUNONE_DD_DTD_FILE_NAME_61 = "resources/IASEjb_jar_1_1.dtd";
75
76     /**
77      * The default CMP mappings template file - sun-cmp-mappings_xml.xdt
78      */

79     private final static String JavaDoc DEFAULT_CMP_TEMPLATE_FILE_70 = "resources/sun-cmp-mappings_xml.xdt";
80
81     /**
82      * The default generated CMP mappings file name.
83      */

84     private final static String JavaDoc GENERATED_CMP_FILE_NAME_70 = "sun-cmp-mappings.xml";
85     private final static String JavaDoc GENERATED_CMP_FILE_NAME_60 = "???";
86     // 6.0 CMP mappings are tricky; the filenames of the mapping files are specified
87
// per-bean in <properties-file-location> elements in the ias-ejb-jar.xml
88
// For now, you'll have to create them by hand.
89

90     /**
91      * Public ID of the iPlanet/SunONE-specific CMP mappings DTD.
92      */

93     private final static String JavaDoc SUNONE_CMP_PUBLICID_70 = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 OR Mapping //EN";
94
95     /**
96      * System ID of the iPlanet/SunONE-specific CMP mappings DTD.
97      */

98     private final static String JavaDoc SUNONE_CMP_SYSTEMID_70 = "http://www.sun.com/software/sunone/appserver/dtds/sun-cmp-mapping_1_0.dtd";
99     private final static String JavaDoc SUNONE_CMP_SYSTEMID_60 = "http://developer.iplanet.com/appserver/dtds/IASPersistence_manager_1_0.dtd";
100
101     /**
102      * Path to the local copy of the iPlanet/SunONE-specific CMP mappings DTD.
103      */

104     private final static String JavaDoc SUNONE_CMP_FILE_NAME_70 = "resources/sun-cmp-mapping_1_0.dtd";
105     private final static String JavaDoc SUNONE_CMP_FILE_NAME_60 = "resources/IASPersistence_manager_1_0.dtd";
106
107     /**
108      * The iPlanet/SunONE version.
109      */

110     private String JavaDoc version = SunONEVersionTypes.VERSION_7_0;
111
112     /**
113      * Optional transaction manager type.
114      */

115     private String JavaDoc transactionManagerType = null;
116
117     /**
118      * Optional CMP Resource JNDI name.
119      */

120     private String JavaDoc cmpResourceJndiName = null;
121
122     /**
123      * Optional CMP Resource Principal name.
124      */

125     private String JavaDoc cmpResourcePrincipalName = null;
126
127     /**
128      * Optional CMP Resource Principal password.
129      */

130     private String JavaDoc cmpResourcePrincipalPassword = null;
131
132     /**
133      * CMP Schema filename (without .dbschema extension), produced by Sun's utilities
134      */

135     private String JavaDoc cmpSchema = null;
136
137     private String JavaDoc cmpTemplateFile = null;
138
139     private String JavaDoc cmpDestinationFile = null;
140
141     public SunONESubTask()
142     {
143         setValidateXML(true);
144     }
145
146     /**
147      * Return the iPlanet/SunONE version.
148      *
149      * @return The iPlanet/SunONE version
150      */

151     public String JavaDoc getVersion()
152     {
153         return version;
154     }
155
156     /**
157      * Return the default transaction manager type.
158      *
159      * @return The transaction manager type
160      */

161     public String JavaDoc getTransactionManagerType()
162     {
163         return transactionManagerType;
164     }
165
166     /**
167      * Return the CMP Resource JNDI name.
168      *
169      * @return The CMP Resource JNDI name
170      */

171     public String JavaDoc getCmpResourceJndiName()
172     {
173         return cmpResourceJndiName;
174     }
175
176     /**
177      * Return the CMP Resource Principal name.
178      *
179      * @return The CMP Resource Principal name
180      */

181     public String JavaDoc getCmpResourcePrincipalName()
182     {
183         return cmpResourcePrincipalName;
184     }
185
186     /**
187      * Return the CMP Resource Principal password.
188      *
189      * @return The CMP Resource Principal password
190      */

191     public String JavaDoc getCmpResourcePrincipalPassword()
192     {
193         return cmpResourcePrincipalPassword;
194     }
195
196     /**
197      * Return the database schema filename (minus .dbschema extension), as captured using Sun's utilities.
198      *
199      * @return The schema filename
200      */

201     public String JavaDoc getCmpSchema()
202     {
203         return cmpSchema;
204     }
205
206     /**
207      * Gets the name of the sun-cmp-mappings.xml template file.
208      *
209      * @return the custom template file
210      */

211     public String JavaDoc getCmpTemplateFile()
212     {
213         return cmpTemplateFile;
214     }
215
216     /**
217      * Gets the destination filename of the CMP mappings file.
218      *
219      * @return the destination filename
220      */

221     public String JavaDoc getCmpDestinationFile()
222     {
223         return cmpDestinationFile;
224     }
225
226     /**
227      * The SunONE/iPlanet version. Supported versions are 6.0, 6.5 and 7.0.
228      *
229      * @param version The new Version value
230      * @ant.not-required No, default is "7.0".
231      */

232     public void setVersion(SunONEVersionTypes version)
233     {
234         this.version = version.getValue();
235     }
236
237     /**
238      * Optional default transaction manager type for all components. Allowed values are 'local' and 'global'.
239      *
240      * @param transactionManagerType "local" or "global"
241      * @ant.not-required Only used for version = 6.5, and optional even then.
242      */

243     public void setTransactionManagerType(String JavaDoc transactionManagerType)
244     {
245         this.transactionManagerType = transactionManagerType;
246     }
247
248     /**
249      * Specifies the absolute jndi-name of the database to be used for storing CMP beans in the EJB JAR file.
250      *
251      * @param cmpResourceJndiName String containing the JNDI name
252      * @ant.not-required Only used for version = 7.0, and optional even then.
253      */

254     public void setCmpResourceJndiName(String JavaDoc cmpResourceJndiName)
255     {
256         this.cmpResourceJndiName = cmpResourceJndiName;
257     }
258
259     /**
260      * Specifies the default sign-on name to the resource manager.
261      *
262      * @param cmpResourcePrincipalName String containing the name
263      * @ant.not-required Only used if cmpResourceJndiName parameter is specified, and optional even then.
264      */

265     public void setCmpResourcePrincipalName(String JavaDoc cmpResourcePrincipalName)
266     {
267         this.cmpResourcePrincipalName = cmpResourcePrincipalName;
268     }
269
270     /**
271      * Specifies the default password to the resource manager.
272      *
273      * @param cmpResourcePrincipalPassword String containing the password
274      * @ant.not-required Only used if the cmpResourcePrincipalName parameter is specified.
275      */

276     public void setCmpResourcePrincipalPassword(String JavaDoc cmpResourcePrincipalPassword)
277     {
278         this.cmpResourcePrincipalPassword = cmpResourcePrincipalPassword;
279     }
280
281     /**
282      * Specifies the database schema filename (minus .dbschema extension), as captured using Sun's utilities.
283      *
284      * @param cmpSchema String containing the schema name
285      * @ant.not-required Only used with CMP entity beans.
286      */

287     public void setCmpSchema(String JavaDoc cmpSchema)
288     {
289         this.cmpSchema = cmpSchema;
290     }
291
292     /**
293      * Sets the name of the sun-cmp-mappings.xml template file.
294      *
295      * @param cmpTemplateFile the name of the custom template file
296      * @ant.not-required
297      */

298     public void setCmpTemplateFile(String JavaDoc cmpTemplateFile)
299     {
300         this.cmpTemplateFile = cmpTemplateFile;
301     }
302
303     /**
304      * Sets the destination filename of the CMP mappings file.
305      *
306      * @param cmpDestinationFile the destination filename
307      * @ant.not-required
308      */

309     public void setCmpDestinationFile(String JavaDoc cmpDestinationFile)
310     {
311         this.cmpDestinationFile = cmpDestinationFile;
312     }
313
314     /**
315      * Called to validate configuration parameters.
316      *
317      * @exception XDocletException Description of Exception
318      */

319     public void validateOptions() throws XDocletException
320     {
321         // we don't call super.validateOptions() here, as the template file and
322
// destination file may not have been set yet
323

324         if (getVersion().equals(SunONEVersionTypes.VERSION_6_5)
325             && getTransactionManagerType() != null) {
326             if (!getTransactionManagerType().equals("local")
327                 && !getTransactionManagerType().equals("global")) {
328                 throw new XDocletException(Translator.getString(XDocletModulesSunONEEjbMessages.class,
329                     XDocletModulesSunONEEjbMessages.INVALID_TRANSACTION_MANAGER_TYPE));
330             }
331         }
332     }
333
334     public void execute() throws XDocletException
335     {
336         if (getVersion().equals(SunONEVersionTypes.VERSION_6_0)) {
337             if (getTemplateURL() == null)
338                 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_60));
339             if (getDestinationFile() == null)
340                 setDestinationFile(GENERATED_FILE_NAME_60);
341             if (getPublicId() == null)
342                 setPublicId(SUNONE_DD_PUBLICID_60);
343             if (getSystemId() == null)
344                 setSystemId(SUNONE_DD_SYSTEMID_60);
345             if (getDtdURL() == null)
346                 setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_60));
347         }
348         else if (getVersion().equals(SunONEVersionTypes.VERSION_6_5)) {
349             if (getTemplateURL() == null)
350                 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_60));
351             if (getDestinationFile() == null)
352                 setDestinationFile(GENERATED_FILE_NAME_60);
353             if (getPublicId() == null)
354                 setPublicId(SUNONE_DD_PUBLICID_61);
355             if (getSystemId() == null)
356                 setSystemId(SUNONE_DD_SYSTEMID_61);
357             if (getDtdURL() == null)
358                 setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_61));
359         }
360         else if (getVersion().equals(SunONEVersionTypes.VERSION_7_0)) {
361             if (getTemplateURL() == null)
362                 setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE_70));
363             if (getDestinationFile() == null)
364                 setDestinationFile(GENERATED_FILE_NAME_70);
365             if (getPublicId() == null)
366                 setPublicId(SUNONE_DD_PUBLICID_70);
367             if (getSystemId() == null)
368                 setSystemId(SUNONE_DD_SYSTEMID_70);
369             if (getDtdURL() == null)
370                 setDtdURL(getClass().getResource(SUNONE_DD_DTD_FILE_NAME_70));
371         }
372         startProcess();
373
374         if (atLeastOneCmpEntityBeanExists()) {
375             if (getVersion().equals(SunONEVersionTypes.VERSION_7_0)) {
376                 if (getCmpTemplateFile() != null) {
377                     setTemplateURL(getClass().getResource(getCmpTemplateFile()));
378                 }
379                 else {
380                     setTemplateURL(getClass().getResource(DEFAULT_CMP_TEMPLATE_FILE_70));
381                 }
382                 if (getCmpDestinationFile() != null) {
383                     setDestinationFile(getCmpDestinationFile());
384                 }
385                 else {
386                     setDestinationFile(GENERATED_CMP_FILE_NAME_70);
387                 }
388                 setPublicId(SUNONE_CMP_PUBLICID_70);
389                 setSystemId(SUNONE_CMP_SYSTEMID_70);
390                 setDtdURL(getClass().getResource(SUNONE_CMP_FILE_NAME_70));
391
392                 startProcess();
393             }
394         }
395     }
396
397     /**
398      * @created 22 January 2003
399      */

400     public static class SunONEVersionTypes extends org.apache.tools.ant.types.EnumeratedAttribute
401     {
402         public final static String JavaDoc VERSION_6_0 = "6.0";
403         public final static String JavaDoc VERSION_6_5 = "6.5";
404         public final static String JavaDoc VERSION_7_0 = "7.0";
405
406         /**
407          * Gets the Values attribute of the SunONEVersionTypes object
408          *
409          * @return The Values value
410          */

411         public String JavaDoc[] getValues()
412         {
413             return (new String JavaDoc[]{VERSION_6_0, VERSION_6_5, VERSION_7_0});
414         }
415     }
416
417 }
418
Popular Tags