KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > task > TorqueSQLTransformTask


1 package org.apache.torque.task;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.BufferedWriter JavaDoc;
20 import java.io.FileWriter JavaDoc;
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.Task;
25
26 import org.apache.torque.engine.database.model.Database;
27 import org.apache.torque.engine.database.transform.SQLToAppData;
28
29 /**
30  * An ant task for creating an xml schema from an sql schema
31  *
32  * @author <a HREF="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
33  * @author <a HREF="jvanzyl@zenplex.com">Jason van Zyl</a>
34  * @version $Id: TorqueSQLTransformTask.java,v 1.5 2004/02/22 06:27:41 jmcnally Exp $
35  */

36 public class TorqueSQLTransformTask extends Task
37 {
38     /** SQL input file. */
39     private String JavaDoc inputFile;
40
41     /** XML descriptor output file. */
42     private String JavaDoc outputFile;
43
44     /**
45      * Get the current input file
46      *
47      * @return the input file
48      */

49     public String JavaDoc getInputFile()
50     {
51         return inputFile;
52     }
53
54     /**
55      * Set the sql input file. This file must exist
56      *
57      * @param v the input file
58      */

59     public void setInputFile(String JavaDoc v)
60     {
61         inputFile = v;
62     }
63
64     /**
65      * Get the current output file.
66      *
67      * @return the output file
68      */

69     public String JavaDoc getOutputFile()
70     {
71         return outputFile;
72     }
73
74     /**
75      * Set the current output file. If the file does not
76      * exist it will be created. If the file exists all
77      * it's contents will be replaced.
78      *
79      * @param v the output file
80      */

81     public void setOutputFile (String JavaDoc v)
82     {
83         outputFile = v;
84     }
85
86     /**
87      * Execute the task.
88      *
89      * @throws BuildException Any exceptions caught during procssing will be
90      * rethrown wrapped into a BuildException
91      */

92     public void execute() throws BuildException
93     {
94         try
95         {
96             log("Parsing SQL Schema", Project.MSG_INFO);
97
98             SQLToAppData sqlParser = new SQLToAppData(inputFile);
99             Database app = sqlParser.execute();
100
101             log("Preparing to write xml schema", Project.MSG_INFO);
102             FileWriter JavaDoc fr = new FileWriter JavaDoc(outputFile);
103             BufferedWriter JavaDoc br = new BufferedWriter JavaDoc (fr);
104
105             br.write(app.toString());
106
107             log("Writing xml schema", Project.MSG_INFO);
108
109             br.flush();
110             br.close();
111         }
112         catch (Exception JavaDoc e)
113         {
114             throw new BuildException(e);
115         }
116     }
117 }
118
Popular Tags