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