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.sdlctools.models.ModelRepository;
028: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
029:
030: /*
031: * Created on 23/10/2003
032: *
033: * To change the template for this generated file go to
034: * Window>Preferences>Java>Code Generation>Code and Comments
035: */
036:
037: /**
038: * @author Rost
039: *
040: * To change the template for this generated type comment go to
041: * Window>Preferences>Java>Code Generation>Code and Comments
042: */
043: public class OpeningExistingModelExample {
044: // Commons Logging instance.
045: private static final Log sLogger;
046: static {
047: // Configure logger as early as possible
048: PropertyConfigurator.configure(System.getProperties());
049: sLogger = LogFactory.getLog(WorkingWithDiagramsExample.class);
050: }
051:
052: // Initialise enterprise model properties
053: private static File sEnterpriseModelRootFile = new File(
054: ModelProperties.sEnterpriseModelsRootDirectory
055: .getAbsolutePath()
056: + File.separator + "HatMaker\\Model.xml");
057: private static File sExportedModelRootFile = new File(
058: ModelProperties.sEnterpriseModelsRootDirectory
059: .getAbsolutePath()
060: + File.separator + "HatMakerExported\\HatMaker.xml");
061:
062: public static void main(String[] args) {
063: try {
064: ModelRepository lModelRepository = null;
065: try {
066: Context lContext = new InitialContext();
067: lModelRepository = (ModelRepository) lContext
068: .lookup(ModelRepository.COMPONENT_URL);
069: // sLogger.info("Loading MetaBossMetaModel...");
070: // lModelRepository.loadMetaModel("MetaBossMetaModel",ModelProperties.sMetaModelFile,"MetaBossModel",ModelProperties.sDefaultPartitioningProperties);
071: System.out.println("Opening HatMaker model...");
072: lModelRepository.openModel("Enterprises.HatMaker",
073: sEnterpriseModelRootFile, "MetaBossMetaModel");
074: System.out.println("Testing if we can do stuff...");
075: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
076: .getModelExtent("Enterprises.HatMaker");
077: System.out.println("Total model elements count = "
078: + lMetaBossModelPackage.getModelElement()
079: .refAllOfType().size());
080: System.out
081: .println("Enterprise count = "
082: + lMetaBossModelPackage
083: .getEnterpriseModel()
084: .getEnterprise()
085: .refAllOfClass().size());
086: System.out.println("System count = "
087: + lMetaBossModelPackage.getEnterpriseModel()
088: .getSystem().refAllOfClass().size());
089: System.out.println("Entity count = "
090: + lMetaBossModelPackage.getEnterpriseModel()
091: .getSystemImplementationModel()
092: .getEntity().refAllOfClass().size());
093: // ModelElement lElement = lMetaBossModelPackage.getModelElement().getByRef("Enterprise[HatMaker]/designLibrary/dataDictionary");
094: // System.out.println("Dumping all contents...");
095: // // Get contents and sort the references
096: // Collection lElements = lMetaBossModelPackage.getModelElement().refAllOfType();
097: // Set lSet = new TreeSet();
098: // for (Iterator lElementsIterator = lElements.iterator(); lElementsIterator.hasNext();)
099: // lSet.add(((ModelElement)lElementsIterator.next()).getRef());
100: // for (Iterator lRefIterator = lSet.iterator(); lRefIterator.hasNext();)
101: // System.out.println("Model Element Ref: " + ((String)lRefIterator.next()));
102: System.out.println("Exporting the model.....");
103: lModelRepository.exportModel("Enterprises.HatMaker",
104: true, sExportedModelRootFile, new Properties());
105: } finally {
106: if (lModelRepository != null)
107: lModelRepository.close();
108: }
109: } catch (Throwable t) {
110: t.printStackTrace();
111: }
112: }
113: }
|