001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.anttasks.convertors;
016:
017: import java.io.File;
018: import java.util.Properties;
019:
020: import org.apache.tools.ant.BuildException;
021:
022: import com.metaboss.sdlctools.applications.anttasks.AntMetaBossUtils;
023: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
024: import com.metaboss.sdlctools.models.ModelRepository;
025: import com.metaboss.sdlctools.models.metabossmodel.ModelUtils;
026:
027: /** Special Ant task used to convert UML Model to MetaBoss model and save it.
028: * The source UML Model must conform to UML Profile For MetaBoss Design Model.
029: * This task extends abstract {@link com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask MetaBossModelToolTask}
030: * and therefore suports all of its attributes. In addition it supports the following attributes:
031: * <table border="1" cellpadding="2" cellspacing="0">
032: * <tr>
033: * <th>Attribute Name</th>
034: * <th>Attribute Description</th>
035: * </tr>
036: * <tr>
037: * <td valign="top">umlfile</td>
038: * <td valign="top">The mandatory path and name of the uml file where source model should be
039: * obtained from.
040: * </td>
041: * </tr>
042: * <tr>
043: * <td valign="top">rectify</td>
044: * <td valign="top">The optional boolean flag. If this flag is set to true (this is the default) the attempt will be made to
045: * "rectify" the converted model. This process validates the model and attempts to fix all discovered constraint violations.
046: * Obviously not all constraint violations can be fixed, but some of them can.
047: * </td>
048: * </tr>
049: * <tr>
050: * <td valign="top">validate</td>
051: * <td valign="top">The optional boolean flag. If this flag is trus (this is the default) the
052: * invalid model will not be saved. If this flag is false the model will be saved without validation.
053: * </td>
054: * </tr>
055: * </table>
056: */
057: public class UMLToMetaBoss extends MetaBossModelToolTask {
058: private File mUMLFile = null;
059: private boolean mValidate = true;
060: private boolean mRectify = true;
061:
062: /** Default constructor */
063: public UMLToMetaBoss() {
064: // Convertor to MetaBoss uses brand new model
065: super (false);
066: }
067:
068: /** The setter for the "UMLFile" attribute */
069: public void setUMLFile(File pUMLFile) {
070: mUMLFile = pUMLFile;
071: }
072:
073: /** The getter for the "UMLFile" attribute */
074: public File getUMLFile() {
075: if (mUMLFile == null)
076: throw new BuildException(
077: "Missing 'umlfile' attribute, which is mandatory for <"
078: + getTaskName() + "> task.");
079: return mUMLFile;
080: }
081:
082: /** The setter for the "rectify" attribute */
083: public void setRectify(boolean pRectify) {
084: mRectify = pRectify;
085: }
086:
087: /** The setter for the "validate" attribute */
088: public void setValidate(boolean pValidate) {
089: mValidate = pValidate;
090: }
091:
092: /** The getter for the "rectify" attribute */
093: public boolean needToRectify() {
094: return mRectify;
095: }
096:
097: /** The getter for the "validate" attribute */
098: public boolean needToValidate() {
099: return mValidate;
100: }
101:
102: // The method executing the tool
103: public void runTool() throws Exception {
104: String lSourceUMLModelName = getUMLFile().getAbsolutePath();
105: String lTargetEntepriseModelName = "TempEnterprise_"
106: + getModelName() + "_TempEnterprise";
107: try {
108: // Read in UML model
109: AntMetaBossUtils.getModelRepository().openModel(
110: lSourceUMLModelName, getUMLFile(),
111: ModelRepository.METAMODEL_NAME_UML);
112: // Convert model to MetaBoss
113: ModelUtils.convertUMLModelToMetaBossModel(
114: lSourceUMLModelName, lTargetEntepriseModelName);
115: // Rectify resulting model if it is allowed
116: if (needToRectify())
117: AntMetaBossUtils.getModelRepository().rectifyModel(
118: lTargetEntepriseModelName);
119: // Export model into the file
120: // First ensure that the model file is absent
121: File lDestinationFile = new File(getModelName());
122: if (lDestinationFile.exists())
123: lDestinationFile.delete();
124: AntMetaBossUtils.getModelRepository().exportModel(
125: lTargetEntepriseModelName, needToValidate(),
126: lDestinationFile, new Properties());
127: } finally {
128: // Delete temporary loaded models
129: if (AntMetaBossUtils.getModelRepository().containsModel(
130: lSourceUMLModelName))
131: AntMetaBossUtils.getModelRepository().closeModel(
132: lSourceUMLModelName);
133: if (AntMetaBossUtils.getModelRepository().containsModel(
134: lTargetEntepriseModelName))
135: AntMetaBossUtils.getModelRepository().closeModel(
136: lTargetEntepriseModelName);
137: }
138: }
139: }
|