01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.applications.anttasks.convertors;
16:
17: import java.io.File;
18: import java.util.Properties;
19:
20: import org.apache.tools.ant.BuildException;
21:
22: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
23: import com.metaboss.sdlctools.applications.anttasks.AntMetaBossUtils;
24: import com.metaboss.sdlctools.models.metabossmodel.ModelUtils;
25:
26: /** Special Ant task used to convert MetaBoss model to the UML model and save it in the XMI format.
27: * This task extends abstract {@link com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask MetaBossModelToolTask}
28: * and therefore suports all of its attributes. In addition it supports the following attributes:
29: * <table border="1" cellpadding="2" cellspacing="0">
30: * <tr>
31: * <th>Attribute Name</th>
32: * <th>Attribute Description</th>
33: * </tr>
34: * <tr>
35: * <td valign="top">umlfile</td>
36: * <td valign="top">The mandatory path and name of the uml file where model should be saved to.
37: * If this file exists it will be overwritten.
38: * </td>
39: * </tr>
40: * </table>
41: */
42: public class MetaBossToUML extends MetaBossModelToolTask {
43: private File mUMLFile = null;
44:
45: /** Default constructor */
46: public MetaBossToUML() {
47: // Convertor from MetaBoss uses existing model
48: super (true);
49: }
50:
51: /** The setter for the "UMLFile" attribute */
52: public void setUMLFile(File pUMLFile) {
53: mUMLFile = pUMLFile;
54: }
55:
56: // The getter for the "UMLFile" attribute. Passed to the destination application as an argument
57: protected File getUMLFile() {
58: if (mUMLFile == null)
59: throw new BuildException(
60: "Missing 'umlfile' attribute, which is mandatory for <"
61: + getTaskName() + "> task.");
62: return mUMLFile;
63: }
64:
65: // The method executing the tool
66: public void runTool() throws Exception {
67: // Ensure that the target file is absent
68: File lDestinationUMLFile = getUMLFile();
69: if (lDestinationUMLFile.exists())
70: lDestinationUMLFile.delete();
71: // Do not have to use default model for this
72: String lTempUMLModelName = "TempUML_" + getModelName()
73: + "_TempUML";
74: // Convert model to UML
75: ModelUtils.convertMetaBossModelToUMLModel(getModelName(),
76: lTempUMLModelName);
77: // Export model into the file
78: AntMetaBossUtils.getModelRepository().exportModel(
79: lTempUMLModelName, false, getUMLFile(),
80: new Properties());
81: // Delete temporary model
82: AntMetaBossUtils.getModelRepository().closeModel(
83: lTempUMLModelName);
84: }
85: }
|