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.examples;
016:
017: import java.io.File;
018: import java.util.Properties;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.log4j.PropertyConfigurator;
026:
027: import com.metaboss.enterprise.BaseException;
028: import com.metaboss.sdlctools.models.ModelRepository;
029: import com.metaboss.sdlctools.models.ModelValidationException;
030: import com.metaboss.sdlctools.models.metabossmodel.ModelUtils;
031: import com.metaboss.util.MetaBossSpecificUtils;
032:
033: /**
034: * @author Rost
035: *
036: * To change the template for this generated type comment go to
037: * Window>Preferences>Java>Code Generation>Code and Comments
038: */
039: public class ConvertExistingModelToUMLExample {
040: // Commons Logging instance.
041: private static final Log sLogger;
042: static {
043: // Read metaboss installation specific properties
044: MetaBossSpecificUtils.setupSystemProperties();
045: // Configure logger as early as possible
046: PropertyConfigurator.configure(System.getProperties());
047: sLogger = LogFactory.getLog(WorkingWithDiagramsExample.class);
048: }
049:
050: // Initialise enterprise model properties
051: private static File sEnterpriseModelRootFile = new File(
052: "C:/MetaBoss-1.4/example/EnterpriseModel/HatMaker/Model.xml");
053: private static File sUMLModelFile = new File("c:/HatMakerUML.xmi");
054:
055: public static void main(String[] args) {
056: try {
057: ModelRepository lModelRepository = null;
058: try {
059: Context lContext = new InitialContext();
060: lModelRepository = (ModelRepository) lContext
061: .lookup(ModelRepository.COMPONENT_URL);
062: sLogger.info("Opening HatMaker model...");
063: String lSourceModelName = sEnterpriseModelRootFile
064: .getAbsolutePath();
065: lModelRepository.openModel(lSourceModelName,
066: sEnterpriseModelRootFile, "MetaBossMetaModel");
067: String lTargetModelName = sUMLModelFile
068: .getAbsolutePath();
069: sLogger.info("Converting model to UML...");
070: ModelUtils.convertMetaBossModelToUMLModel(
071: lSourceModelName, lTargetModelName);
072: sLogger.info("Exporting the model...");
073: // Delete target file if necessary
074: if (sUMLModelFile.exists())
075: sUMLModelFile.delete();
076: lModelRepository.exportModel(lTargetModelName, false,
077: sUMLModelFile, new Properties());
078: sLogger.info("Done");
079: } finally {
080: if (lModelRepository != null)
081: lModelRepository.close();
082: }
083: } catch (Throwable t) {
084: handleException(t);
085: }
086: }
087:
088: // This helper must be called from all tools when exception has been caught
089: // it will print the exception in the best possible manner
090: static void handleException(Throwable pThrowable) {
091: System.out.println("Caught exception "
092: + pThrowable.getClass().getName());
093: if (pThrowable instanceof BaseException) {
094: pThrowable.printStackTrace(System.out);
095: Throwable t = pThrowable.getCause();
096: while (t != null) {
097: System.out.println();
098: System.out.println();
099: System.out.println("Cause : " + t.getClass().getName());
100: t.printStackTrace(System.out);
101: // Special case for model validation exception - it has explanation
102: if (t instanceof ModelValidationException) {
103: System.out.println(((ModelValidationException) t)
104: .getFullExplanation());
105: break;
106: } else if (t instanceof BaseException) {
107: t = ((BaseException) t).getCause();
108: } else
109: break;
110: }
111: } else {
112: System.out.println(pThrowable.getMessage());
113: pThrowable.printStackTrace(System.out);
114: }
115: }
116: }
|