001: package xdoclet.modules.ojb;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.commons.logging.Log;
019: import xdoclet.XDocletException;
020: import xdoclet.XmlSubTask;
021: import xdoclet.util.LogUtil;
022: import xdoclet.util.Translator;
023:
024: /**
025: * Generates the XML schema for torque.
026: *
027: * @author <a href="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
028: * @created April 9, 2003
029: * @ant.element display-name="Torque Schema" name="torqueschema" parent="xdoclet.modules.ojb.OjbDocletTask"
030: */
031: public class TorqueSubTask extends XmlSubTask {
032: private static String TORQUE_TEMPLATE_FILE = "resources/torque_xml.xdt";
033: private static String TORQUE_DEFAULT_FILE_NAME = "project-schema.xml";
034:
035: /** Whether to generate verbose output */
036: private boolean _isVerbose = false;
037: /** The database name */
038: private String _databaseName;
039: /** The torque dtd url */
040: private String _dtdUrl = "http://jakarta.apache.org/turbine/dtd/database.dtd";
041: /** Whether to generate foreignkey tags in the torque schema */
042: private boolean _isGeneratingForeignkeys = true;
043:
044: /**
045: * Creates a new object.
046: */
047: public TorqueSubTask() {
048: setTemplateURL(getClass().getResource(TORQUE_TEMPLATE_FILE));
049: setDestinationFile(TORQUE_DEFAULT_FILE_NAME);
050: setSubTaskName("torqueschema");
051: }
052:
053: /**
054: * Returns whether we generate verbose output.
055: *
056: * @return <code>true</code> if we generate verbose output
057: */
058: public boolean getVerbose() {
059: return _isVerbose;
060: }
061:
062: /**
063: * Specifies whether we generate verbose output.
064: *
065: * @param beVerbose Whether we generate verbose output
066: */
067: public void setVerbose(boolean beVerbose) {
068: _isVerbose = beVerbose;
069: }
070:
071: /**
072: * Sets the dtd used for the torque schema.
073: *
074: * @param url The dtd url
075: */
076: public void setDtdUrl(String url) {
077: _dtdUrl = url;
078: }
079:
080: /**
081: * Returns the dtd url.
082: *
083: * @return The url
084: */
085: public String getDtdUrl() {
086: return _dtdUrl;
087: }
088:
089: /**
090: * Returns the database name.
091: *
092: * @return The database name
093: */
094: public String getDatabaseName() {
095: return _databaseName;
096: }
097:
098: /**
099: * Sets the databaseName used for the torque schema.
100: *
101: * @param databaseName The database name
102: */
103: public void setDatabaseName(String databaseName) {
104: _databaseName = databaseName;
105: }
106:
107: /**
108: * Specifies whether we should generate foreignkey tags.
109: *
110: * @param generateForeignkeys <code>true</code> if we will generate foreignkey tags
111: */
112: public void setGenerateForeignkeys(boolean generateForeignkeys) {
113: _isGeneratingForeignkeys = generateForeignkeys;
114: }
115:
116: /**
117: * Returns whether we generate foreignkey tags.
118: *
119: * @return <code>true</code> if we generate foreignkey tags
120: */
121: public boolean getGenerateForeignkeys() {
122: return _isGeneratingForeignkeys;
123: }
124:
125: /**
126: * Called to validate configuration parameters.
127: *
128: * @exception XDocletException Is not thrown
129: */
130: public void validateOptions() throws XDocletException {
131: if ((_databaseName == null) || (_databaseName.length() == 0)) {
132: throw new XDocletException(Translator.getString(
133: XDocletModulesOjbMessages.class,
134: XDocletModulesOjbMessages.DATABASENAME_IS_REQUIRED));
135: }
136: }
137:
138: /**
139: * Executes the task.
140: *
141: * @exception XDocletException If an error occurs.
142: */
143: public void execute() throws XDocletException {
144: startProcess();
145: }
146:
147: public void startProcess() throws XDocletException {
148: Log log = LogUtil.getLog(TorqueSubTask.class, "startProcess");
149:
150: if (log.isDebugEnabled()) {
151: log.debug("destDir.toString()=" + getDestDir());
152: log.debug("getTemplateURL()=" + getTemplateURL());
153: log.debug("getDestinationfile()=" + getDestinationFile());
154: log.debug("getOfType()=" + getOfType());
155: log.debug("getExtent()=" + getExtent());
156: log.debug("getHavingClassTag()=" + getHavingClassTag());
157: }
158:
159: startProcessForAll();
160: }
161:
162: /**
163: * Describe what the method does
164: *
165: * @exception XDocletException
166: */
167: protected void engineStarted() throws XDocletException {
168: System.out.println("Generating torque schema ("
169: + getDestinationFile() + ")");
170: }
171: }
|