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.Iterator;
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: import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachment;
030: import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachmentUtils;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
033: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DiagramModelElement;
034: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.DomainEntitiesDiagram;
035: import com.metaboss.sdlctools.models.metabossmodel.visualmodel.Point;
036:
037: /*
038: * Created on 23/10/2003
039: *
040: * To change the template for this generated file go to
041: * Window>Preferences>Java>Code Generation>Code and Comments
042: */
043:
044: /**
045: * @author Rost
046: *
047: * To change the template for this generated type comment go to
048: * Window>Preferences>Java>Code Generation>Code and Comments
049: */
050: public class WorkingWithDiagramsExample {
051: // Commons Logging instance.
052: private static final Log sLogger;
053: static {
054: // Configure logger as early as possible
055: PropertyConfigurator.configure(System.getProperties());
056: sLogger = LogFactory.getLog(WorkingWithDiagramsExample.class);
057: }
058:
059: // Initialise enterprise model properties
060: private static File sEnterpriseModelRootFile = new File(
061: ModelProperties.sEnterpriseModelsRootDirectory
062: .getAbsolutePath()
063: + File.separator + "HatMaker\\Model.xml");
064:
065: public static void main(String[] args) {
066: try {
067: ModelRepository lModelRepository = null;
068: try {
069: Context lContext = new InitialContext();
070: lModelRepository = (ModelRepository) lContext
071: .lookup(ModelRepository.COMPONENT_URL);
072: // sLogger.info("Loading MetaBossMetaModel...");
073: // lModelRepository.loadMetaModel("MetaBossMetaModel",ModelProperties.sMetaModelFile,"MetaBossModel",ModelProperties.sDefaultPartitioningProperties);
074: sLogger.info("Opening HatMaker model...");
075: lModelRepository.openModel("Enterprises.HatMaker",
076: sEnterpriseModelRootFile, "MetaBossMetaModel");
077: sLogger.info("Testing if we can do stuff...");
078: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
079: .getModelExtent("Enterprises.HatMaker");
080: // Create entity relationship diagram
081: Domain lDomain = (Domain) lMetaBossModelPackage
082: .getModelElement()
083: .getByRef(
084: "Enterprise[HatMaker]/System[Crm]/Domain[Main]");
085: lModelRepository.beginTransaction();
086: try {
087: // Create Domain entities diagram itself
088: DomainEntitiesDiagram lDomainEntitesDiagram = lMetaBossModelPackage
089: .getVisualModel()
090: .getDomainEntitiesDiagram()
091: .createDomainEntitiesDiagram();
092: lDomainEntitesDiagram.setName("AllEntitiesDiagram");
093: // For each entity object, create diagram element and set it's coordinates
094: Iterator lDomainEntities = lDomain.getEntities()
095: .iterator();
096: while (lDomainEntities.hasNext()) {
097: Entity lEntity = (Entity) lDomainEntities
098: .next();
099: DiagramModelElement lEntityDiagramElement = lMetaBossModelPackage
100: .getVisualModel()
101: .getDiagramModelElement()
102: .createDiagramModelElement();
103: lEntityDiagramElement.setModelElement(lEntity);
104: lEntityDiagramElement.setName(lEntity.getName()
105: + "Class");
106: Point lEntityPosition = lMetaBossModelPackage
107: .getVisualModel().getPoint()
108: .createPoint();
109: lEntityPosition.setName("Anchor");
110: lEntityPosition.setX(20);
111: lEntityPosition.setY(20);
112: lEntityDiagramElement.getGraphicFeatures().add(
113: lEntityPosition);
114:
115: // Add element to the diagram
116: lDomainEntitesDiagram.getElements().add(
117: lEntityDiagramElement);
118: }
119: // Attach a gif image
120: ModelElementAttachment lGifImageAttachment = lMetaBossModelPackage
121: .getModelElementAttachment()
122: .createModelElementAttachment();
123: lGifImageAttachment.setName("image.gif");
124: byte[] lImage = new byte[] { 0x00, 0x01, 0x02,
125: 0x03, 0x04, 0x05, 0x06 };
126: ModelElementAttachmentUtils.setAttachmentData(
127: lGifImageAttachment, lImage);
128: lDomainEntitesDiagram.getAttachments().add(
129: lGifImageAttachment);
130:
131: // Add diagram to domain
132: lDomain.getEntityClassDiagrams().add(
133: lDomainEntitesDiagram);
134:
135: lModelRepository.commitTransaction();
136: lModelRepository.saveModel("Enterprises.HatMaker",
137: true);
138: sLogger.info("Done creating diagram");
139: } finally {
140: if (lModelRepository.isInTransaction())
141: lModelRepository.rollbackTransaction();
142: }
143: } finally {
144: if (lModelRepository != null)
145: lModelRepository.close();
146: }
147: } catch (Throwable t) {
148: t.printStackTrace();
149: }
150: }
151: }
|