KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > ant > taskdefs > Dods


1 /*
2  * Title: DODS Ant task
3  * Description: DODS
4  */

5 package org.enhydra.ant.taskdefs;
6
7 import java.io.File JavaDoc;
8 import org.apache.tools.ant.BuildException;
9 import org.apache.tools.ant.Task;
10 import org.enhydra.dods.generator.DODSGenerator;
11
12 /**
13  *
14  * @author Sinisa Milosevic
15  * Invokes DODS to generate a set of java classes from a doml file.<BR>
16  * The files will only be regenerated/compiled if the date on the doml file is
17  * newer than at least one of the generated files.<BR>
18  * This taskdef extends Ant's <javac> task; refer to that documentation for
19  * parameters that affect compilation.<BR>
20  * Typically made visible to an Ant build file with the following declaration:<PRE>
21  * &lt;taskdef name="dods" classname="org.enhydra.ant.taskdefs.Dods"/&gt;</PRE>
22  *
23  * <B>Parameters</B><PRE>
24  *
25  * domlfile - The doml input file describing data object mapping. Required = Yes.
26  * outputDir - Target for generated classes, expressed as a directory path. Required = Yes.
27  * force - Forces DODS always to regenerate source files.
28  * Possible values: ("true", "false"(default)). Required = No.
29  * action - Name of Ant task from generate.xml.
30  * If only documentation need to be generated then set action="dods:generatorOff"
31  * and set indicators for generating documentation (pdf,xmi,ptl,html).
32  * Required = No.
33  * templateDir - Name of folder for template set for generating java code, expressed as a directory path. Required = No.
34  * templateSet - Template set for generating java code. Required = No.
35  * confDir - Path to custom configuration folder = No.
36  * database - Sets database vendor for generating sql. Required = No.
37  * html - Indicates DODS to generate html documentation from .doml file
38  * Possible values: ("true", "false"(default)). Required = No.
39  * pdf - Indicates DODS to generate pdf documentation from .doml file
40  * Possible values: ("true", "false"(default)). Required = No.
41  * xmi - Indicates DODS to generate xmi documentation from .doml file
42  * Possible values: ("true", "false"(default)). Required = No.
43  * ptl - Indicates DODS to generate ptl (Rational Rose) documentation from .doml file.
44  * Possible values: ("true", "false"(default)). Required = No.
45  * without parameters - to create all sql files and java classes and to compile it.
46  *
47  * action parameters:
48  * dods:build_all - to create all sql files and java classes.
49  * dods:sql - to create only sql files.
50  * dods:java -to create only java files and to compile them.
51  * dods:javaNoCompile -To create only java files and not to compile them.
52  * dods:noCompile -To create SQL files and java files and not to compile them.
53  * dods:build_all_split - to create all sql files and java classes and to compile it. SQL files will be divided into separate files using SQLSplitter
54  * dods:sqlsplit - to create only sql files and separate in different files using SQLSplitter.
55  * dods:noCompileSplit - To create SQL files and separate sql commands using SQLSplitter and java files and not to compile them.
56  *
57  * templateset parameters:
58  * standard - generate standard java code.
59  * <user_defined> - any user defined template set.
60  *</PRE>
61  *<BR>
62  * Examples<PRE>
63  * &lt;dods domlfile="${basedir}/discRack.doml"
64  * outputDir="${basedir}/src"
65  * templateset="standard"/&gt;</PRE>
66  *
67  */

68 public class Dods extends Task {
69     protected String JavaDoc domlfile = null;
70     protected String JavaDoc outputDir = null;
71     protected String JavaDoc action = "dods:build_all"; // action
72
protected String JavaDoc templateDir = null;
73     protected String JavaDoc confDir = null;
74     protected String JavaDoc templateSet = "standard";
75     protected String JavaDoc force = "false";
76     protected String JavaDoc database = DODSGenerator.DATABASE_NOT_SET;
77     protected boolean html = false;
78     protected boolean pdf = false;
79     protected boolean xmi = false;
80     protected boolean ptl = false;
81     public Dods() {}
82
83     /**
84      * Simply invokes DODS Generator, and then compiles the generated files.
85      *
86      * @exception org.apache.tools.ant.BuildException
87      */

88     public void execute() throws org.apache.tools.ant.BuildException {
89         if (domlfile == null) {
90             throw new BuildException("doml attribute must be set!");
91         }
92         if (outputDir == null) {
93             throw new BuildException("output directory attribute must be set!");
94         }
95         if (!(new File JavaDoc(outputDir)).isDirectory()) {
96             throw new BuildException("output directory must be a valid directory!");
97         }
98         if (confDir != null) {
99             if (!(new File JavaDoc(confDir)).isDirectory()) {
100                 throw new BuildException("configuration directory must be a valid directory!");
101             }
102         }
103         try {
104             if (System.getProperty("DODS_HOME") == null) {
105                 if (System.getProperty("ENHYDRA_DIR") != null) {
106                     System.setProperty("DODS_HOME",
107                             System.getProperty("ENHYDRA_DIR") + File.separator
108                             + "dods");
109                 } else {
110                     throw new BuildException("DODS_HOME not set");
111                 }
112             }
113             System.setProperty("JAVA_HOME", System.getProperty("JAVA_HOME"));
114             System.setProperty("TEMPLATESET", templateSet);
115             int exit = DODSGenerator.generateAll(outputDir, domlfile, action,
116                     confDir, templateDir, templateSet, force, database, html,
117                     pdf, xmi, ptl);
118         } catch (Exception JavaDoc e) {
119             throw new BuildException(e);
120         }
121     }
122
123     /**
124      * Sets the doml file.
125      *
126      * @param domlfile the doml input file describing data object mapping.
127      */

128     public void setDomlfile(String JavaDoc domlfile) {
129         this.domlfile = domlfile;
130     }
131
132     /**
133      * Sets the templateDir.
134      *
135      * @param tempDir Path to folder with templates.
136      */

137     public void setTemplateDir(String JavaDoc tempDir) {
138         this.templateDir = tempDir;
139         if (tempDir != null) {
140             try {
141                 File JavaDoc tempFile = new File JavaDoc(tempDir);
142
143                 if (!tempFile.isDirectory()) {
144                     this.templateDir = null;
145                 }
146             } catch (NullPointerException JavaDoc e) {
147                 this.templateDir = null;
148             }
149         }
150          
151     }
152
153     /**
154      * The destination directory in which the generated sources are written to.
155      *
156      * @param outdir target for generated classes, expressed as a directory path.
157      */

158     public void setOutputDir(String JavaDoc outdir) {
159         outputDir = outdir;
160     }
161
162     /**
163      * Sets action parameter.
164      *
165      * @param action value of action parameter.
166      */

167     public void setAction(String JavaDoc action) {
168         this.action = action;
169     }
170
171     /**
172      * Sets template set parameter.
173      *
174      * @param template value of template set.
175      */

176     public void setTemplateSet(String JavaDoc template) {
177         this.templateSet = template;
178     }
179
180     /**
181      * Set the database vendor for creating sql
182      *
183      * @param database database vendor for creating sql
184      */

185     public void setDatabase(String JavaDoc database) {
186         this.database = database;
187     }
188
189     /**
190      * Forces DODS always to regenerate source files.
191      *
192      * @param force "true" if source files shoult be regenerated, otherwise "false".
193      */

194     public void setForce(String JavaDoc force) {
195         this.force = "false";
196         if (force.equals("true")) {
197             this.force = "true";
198         }
199     }
200
201     /**
202      * Indicates DODS to generate html documentation from .doml file.
203      * @param html "true" if html documentation shoult be generated, otherwise "false".
204      */

205     public void setHtml(String JavaDoc html) {
206         this.html = false;
207         if (html.equals("true")) {
208             this.html = true;
209         }
210     }
211
212     /**
213      * Indicates DODS to generate pdf documentation from .doml file.
214      * @param pdf "true" if pdf documentation shoult be generated, otherwise "false".
215      */

216     public void setPdf(String JavaDoc pdf) {
217         this.pdf = false;
218         if (pdf.equals("true")) {
219             this.pdf = true;
220         }
221     }
222
223     /**
224      * Indicates DODS to generate xmi documentation from .doml file.
225      * @param xmi "true" if xmi documentation shoult be generated, otherwise "false".
226      */

227     public void setXmi(String JavaDoc xmi) {
228         this.xmi = false;
229         if (xmi.equals("true")) {
230             this.xmi = true;
231         }
232     }
233
234     /**
235      * Indicates DODS to generate ptl (Rational Rose) documentation from .doml file.
236      * @param ptl "true" if ptl documentation shoult be generated, otherwise "false".
237      */

238     public void setPtl(String JavaDoc ptl) {
239         this.ptl = false;
240         if (ptl.equals("true")) {
241             this.ptl = true;
242         }
243     }
244
245     /**
246      * Indicates DODS to search for configuration files in confDir.
247      * @param string configuration dir
248      */

249     public void setConfDir(String JavaDoc string) {
250         confDir = string;
251     }
252 }
253
Popular Tags