KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > TorqueSubTask


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

17
18 import org.apache.commons.logging.Log;
19 import xdoclet.XDocletException;
20 import xdoclet.XmlSubTask;
21 import xdoclet.util.LogUtil;
22 import xdoclet.util.Translator;
23
24 /**
25  * Generates the XML schema for torque.
26  *
27  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
28  * @created April 9, 2003
29  * @ant.element display-name="Torque Schema" name="torqueschema" parent="xdoclet.modules.ojb.OjbDocletTask"
30  */

31 public class TorqueSubTask extends XmlSubTask
32 {
33     private static String JavaDoc TORQUE_TEMPLATE_FILE = "resources/torque_xml.xdt";
34     private static String JavaDoc TORQUE_DEFAULT_FILE_NAME = "project-schema.xml";
35
36     /** Whether to generate verbose output */
37     private boolean _isVerbose = false;
38     /** The database name */
39     private String JavaDoc _databaseName;
40     /** The torque dtd url */
41     private String JavaDoc _dtdUrl = "http://jakarta.apache.org/turbine/dtd/database.dtd";
42     /** Whether to generate foreignkey tags in the torque schema */
43     private boolean _isGeneratingForeignkeys = true;
44     
45     
46     /**
47      * Creates a new object.
48      */

49     public TorqueSubTask()
50     {
51         setTemplateURL(getClass().getResource(TORQUE_TEMPLATE_FILE));
52         setDestinationFile(TORQUE_DEFAULT_FILE_NAME);
53         setSubTaskName("torqueschema");
54     }
55
56     /**
57      * Returns whether we generate verbose output.
58      *
59      * @return <code>true</code> if we generate verbose output
60      */

61     public boolean getVerbose()
62     {
63         return _isVerbose;
64     }
65
66     /**
67      * Specifies whether we generate verbose output.
68      *
69      * @param beVerbose Whether we generate verbose output
70      */

71     public void setVerbose(boolean beVerbose)
72     {
73         _isVerbose = beVerbose;
74     }
75
76     /**
77      * Sets the dtd used for the torque schema.
78      *
79      * @param url The dtd url
80      */

81     public void setDtdUrl(String JavaDoc url)
82     {
83         _dtdUrl = url;
84     }
85
86     /**
87      * Returns the dtd url.
88      *
89      * @return The url
90      */

91     public String JavaDoc getDtdUrl()
92     {
93         return _dtdUrl;
94     }
95
96     /**
97      * Returns the database name.
98      *
99      * @return The database name
100      */

101     public String JavaDoc getDatabaseName()
102     {
103         return _databaseName;
104     }
105
106     /**
107      * Sets the databaseName used for the torque schema.
108      *
109      * @param databaseName The database name
110      */

111     public void setDatabaseName(String JavaDoc databaseName)
112     {
113         _databaseName = databaseName;
114     }
115
116     /**
117      * Specifies whether we should generate foreignkey tags.
118      *
119      * @param generateForeignkeys <code>true</code> if we will generate foreignkey tags
120      */

121     public void setGenerateForeignkeys(boolean generateForeignkeys)
122     {
123         _isGeneratingForeignkeys = generateForeignkeys;
124     }
125
126     /**
127      * Returns whether we generate foreignkey tags.
128      *
129      * @return <code>true</code> if we generate foreignkey tags
130      */

131     public boolean getGenerateForeignkeys()
132     {
133         return _isGeneratingForeignkeys;
134     }
135     
136     /**
137      * Called to validate configuration parameters.
138      *
139      * @exception XDocletException Is not thrown
140      */

141     public void validateOptions() throws XDocletException
142     {
143         if ((_databaseName == null) || (_databaseName.length() == 0)) {
144             throw new XDocletException(Translator.getString(XDocletModulesOjbMessages.class,
145                 XDocletModulesOjbMessages.DATABASENAME_IS_REQUIRED));
146         }
147     }
148
149     /**
150      * Executes the task.
151      *
152      * @exception XDocletException If an error occurs.
153      */

154     public void execute() throws XDocletException
155     {
156         startProcess();
157     }
158
159     public void startProcess() throws XDocletException
160     {
161         Log log = LogUtil.getLog(TorqueSubTask.class, "startProcess");
162
163         if (log.isDebugEnabled()) {
164             log.debug("destDir.toString()=" + getDestDir());
165             log.debug("getTemplateURL()=" + getTemplateURL());
166             log.debug("getDestinationfile()=" + getDestinationFile());
167             log.debug("getOfType()=" + getOfType());
168             log.debug("getExtent()=" + getExtent());
169             log.debug("getHavingClassTag()=" + getHavingClassTag());
170         }
171
172         startProcessForAll();
173     }
174
175     /**
176      * Describe what the method does
177      *
178      * @exception XDocletException
179      */

180     protected void engineStarted() throws XDocletException
181     {
182         System.out.println("Generating torque schema ("+getDestinationFile()+")");
183     }
184 }
185
Popular Tags