0001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012: // POSSIBILITY OF SUCH DAMAGE.
0013: //
0014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015: package com.metaboss.sdlctools.models.impl.metabossmodel;
0016:
0017: import java.util.Collection;
0018: import java.util.HashMap;
0019: import java.util.Iterator;
0020:
0021: import javax.naming.Context;
0022: import javax.naming.InitialContext;
0023: import javax.naming.NamingException;
0024:
0025: import org.omg.uml.foundation.datatypes.AggregationKindEnum;
0026: import org.omg.uml.foundation.datatypes.PseudostateKindEnum;
0027:
0028: import com.metaboss.sdlctools.models.ModelAlreadyLoadedException;
0029: import com.metaboss.sdlctools.models.ModelNotLoadedException;
0030: import com.metaboss.sdlctools.models.ModelRepository;
0031: import com.metaboss.sdlctools.models.ModelRepositoryException;
0032: import com.metaboss.sdlctools.models.ModelRepositoryNotFoundException;
0033: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
0034: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
0035: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
0036: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
0037: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
0038: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0039: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
0040: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
0041: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
0042: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0043: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0044: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
0045: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
0046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.AbstractOperation;
0047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
0048: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
0049: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventDataField;
0050: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventMessageField;
0051: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscription;
0052: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
0053: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
0054: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
0055: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0056: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
0057: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
0058: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
0059: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0060: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0061: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationType;
0062: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
0063: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
0064: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0065: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0066: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
0067: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0068: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0069: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
0070: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.PrimaryKeyElement;
0071: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
0072: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputField;
0073: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
0074: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
0075: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
0076: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
0077:
0078: /** This is a utility class which converts MetaBoss models to the UML models
0079: * with special MetaBoss profile */
0080: public final class MetaBossModelToUMLModelConvertor {
0081: // This clas is used to pass down the context of the conversion
0082: private static class ConversionContext {
0083: public ModelRepository mModelRepository = null;
0084: public String mTargetModelName = null;
0085: public MetaBossModelPackage mMetaBossModelExtent = null;
0086: public org.omg.uml.UmlPackage mUMLModelExtent = null;
0087: public org.omg.uml.modelmanagement.Model mEnterpriseModel = null;
0088: // Profile package is always present
0089: public org.omg.uml.modelmanagement.UmlPackage mMetaBossModelProfilePackage = null;
0090: /** Stereotype used to mark the OCL invariants */
0091: public org.omg.uml.foundation.core.Stereotype mOCLInvariantStereotype = null;
0092: /** Stereotype used to mark the OCL preconditions */
0093: public org.omg.uml.foundation.core.Stereotype mOCLPreconditionStereotype = null;
0094:
0095: public UMLStylesheet.UMLMetaBossProfile mMetaBossProfile = null;
0096: // The cache for objects where there is one-to-one mapping between metaboss element and uml element
0097: // Used to improve performance of the conversion
0098: public HashMap mUmlElementsMap = new HashMap(); // MetaBoss element is the key and associated UmlElement is the value
0099:
0100: public org.omg.uml.foundation.core.UmlClass getUmlTypetemplate(
0101: TypeTemplate pMetaBossTypeTemplate)
0102: throws ModelRepositoryException {
0103: org.omg.uml.foundation.core.UmlClass lTypeTemplateUmlClass = null;
0104: if ((lTypeTemplateUmlClass = (org.omg.uml.foundation.core.UmlClass) mUmlElementsMap
0105: .get(pMetaBossTypeTemplate)) == null)
0106: mUmlElementsMap
0107: .put(
0108: pMetaBossTypeTemplate,
0109: lTypeTemplateUmlClass = UMLUtils
0110: .getUmlClass(
0111: mTargetModelName,
0112: pMetaBossTypeTemplate,
0113: UMLStylesheet
0114: .getTypeTemplateXPath(pMetaBossTypeTemplate)));
0115: return lTypeTemplateUmlClass;
0116: }
0117:
0118: public org.omg.uml.foundation.core.DataType getUmlDataType(
0119: DataType pMetaBossDataType)
0120: throws ModelRepositoryException {
0121: org.omg.uml.foundation.core.DataType lDataTypeUmlClass = null;
0122: if ((lDataTypeUmlClass = (org.omg.uml.foundation.core.DataType) mUmlElementsMap
0123: .get(pMetaBossDataType)) == null)
0124: mUmlElementsMap.put(pMetaBossDataType,
0125: lDataTypeUmlClass = UMLUtils.getUmlDataType(
0126: mTargetModelName, pMetaBossDataType));
0127: return lDataTypeUmlClass;
0128: }
0129:
0130: public org.omg.uml.foundation.core.UmlClass getUmlStructure(
0131: Structure pMetaBossStructure)
0132: throws ModelRepositoryException {
0133: org.omg.uml.foundation.core.UmlClass lStructureUmlClass = null;
0134: if ((lStructureUmlClass = (org.omg.uml.foundation.core.UmlClass) mUmlElementsMap
0135: .get(pMetaBossStructure)) == null)
0136: mUmlElementsMap
0137: .put(
0138: pMetaBossStructure,
0139: lStructureUmlClass = UMLUtils
0140: .getUmlClass(
0141: mTargetModelName,
0142: pMetaBossStructure,
0143: UMLStylesheet
0144: .getStructureXPath(pMetaBossStructure)));
0145: return lStructureUmlClass;
0146: }
0147:
0148: public org.omg.uml.modelmanagement.UmlPackage getUmlNamespace(
0149: AbstractNamespace pMetaBossNamespace)
0150: throws ModelRepositoryException {
0151: org.omg.uml.modelmanagement.UmlPackage lUmlNamespace = null;
0152: if ((lUmlNamespace = (org.omg.uml.modelmanagement.UmlPackage) mUmlElementsMap
0153: .get(pMetaBossNamespace)) == null)
0154: mUmlElementsMap
0155: .put(
0156: pMetaBossNamespace,
0157: lUmlNamespace = UMLUtils
0158: .getUmlPackage(
0159: mTargetModelName,
0160: pMetaBossNamespace,
0161: UMLStylesheet
0162: .getNamespaceXPath(pMetaBossNamespace)));
0163: return lUmlNamespace;
0164: }
0165: }
0166:
0167: public static void doConversion(String pSourceMetaBossModelName,
0168: String pTargetUMLModelName) throws ModelRepositoryException {
0169: try {
0170: ConversionContext lConversionContext = new ConversionContext();
0171: Context lContext = new InitialContext();
0172: lConversionContext.mModelRepository = (ModelRepository) lContext
0173: .lookup(ModelRepository.COMPONENT_URL);
0174:
0175: // Obtain source model package
0176: if (!lConversionContext.mModelRepository
0177: .containsModel(pSourceMetaBossModelName))
0178: throw new ModelNotLoadedException(
0179: pSourceMetaBossModelName);
0180: lConversionContext.mMetaBossModelExtent = (MetaBossModelPackage) lConversionContext.mModelRepository
0181: .getModelExtent(pSourceMetaBossModelName);
0182: // Create target model package
0183: if (lConversionContext.mModelRepository
0184: .containsModel(pTargetUMLModelName))
0185: throw new ModelAlreadyLoadedException(
0186: pTargetUMLModelName);
0187: try {
0188: lConversionContext.mModelRepository.createModel(
0189: pTargetUMLModelName, null,
0190: ModelRepository.METAMODEL_NAME_UML, null);
0191: lConversionContext.mTargetModelName = pTargetUMLModelName;
0192: lConversionContext.mModelRepository.beginTransaction();
0193: lConversionContext.mUMLModelExtent = (org.omg.uml.UmlPackage) lConversionContext.mModelRepository
0194: .getModelExtent(lConversionContext.mTargetModelName);
0195: lConversionContext.mEnterpriseModel = lConversionContext.mUMLModelExtent
0196: .getModelManagement().getModel().createModel();
0197: lConversionContext.mEnterpriseModel
0198: .setName(UMLStylesheet.mModelName);
0199: // Create couple of standard UML stereotypes
0200: lConversionContext.mOCLInvariantStereotype = lConversionContext.mUMLModelExtent
0201: .getCore().getStereotype().createStereotype();
0202: lConversionContext.mOCLInvariantStereotype
0203: .setName("invariant");
0204: lConversionContext.mOCLInvariantStereotype
0205: .setNamespace(lConversionContext.mEnterpriseModel);
0206: lConversionContext.mOCLInvariantStereotype
0207: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0208: lConversionContext.mOCLPreconditionStereotype = lConversionContext.mUMLModelExtent
0209: .getCore().getStereotype().createStereotype();
0210: lConversionContext.mOCLPreconditionStereotype
0211: .setName("precondition");
0212: lConversionContext.mOCLPreconditionStereotype
0213: .setNamespace(lConversionContext.mEnterpriseModel);
0214: lConversionContext.mOCLPreconditionStereotype
0215: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0216:
0217: // Create standard MetaBoss profile
0218: lConversionContext.mMetaBossProfile = UMLStylesheet
0219: .createMetaBossProfile(
0220: lConversionContext.mModelRepository,
0221: lConversionContext.mEnterpriseModel);
0222: // See if it is an enterprise model
0223: Enterprise lPossibleEnterprise = (Enterprise) lConversionContext.mMetaBossModelExtent
0224: .getModelElement().findByRef("Enterprise");
0225: DesignLibrary lPossibleDesignLibrary = (DesignLibrary) lConversionContext.mMetaBossModelExtent
0226: .getModelElement().findByRef("DesignLibrary");
0227: if (lPossibleEnterprise != null) {
0228: convertEnterprise(lConversionContext,
0229: lPossibleEnterprise);
0230: } else if (lPossibleDesignLibrary != null) {
0231: convertDesignLibrary(lConversionContext,
0232: lPossibleDesignLibrary);
0233: }
0234:
0235: lConversionContext.mModelRepository.commitTransaction();
0236: } finally {
0237: if (lConversionContext.mModelRepository
0238: .isInTransaction())
0239: lConversionContext.mModelRepository
0240: .rollbackTransaction();
0241: }
0242: } catch (NamingException e) {
0243: throw new ModelRepositoryNotFoundException(e);
0244: }
0245: }
0246:
0247: private static void convertEnterprise(
0248: ConversionContext pConversionContext, Enterprise pEnterprise)
0249: throws ModelRepositoryException {
0250: // Create enterprise package
0251: org.omg.uml.modelmanagement.UmlPackage lEnterprisePackage = pConversionContext.mUMLModelExtent
0252: .getModelManagement().getUmlPackage()
0253: .createUmlPackage();
0254: lEnterprisePackage.setName(pEnterprise.getName());
0255: lEnterprisePackage
0256: .setNamespace(pConversionContext.mEnterpriseModel);
0257: lEnterprisePackage
0258: .getStereotype()
0259: .add(
0260: pConversionContext.mMetaBossProfile.mEnterprisePackageStereotype);
0261: UMLUtils.copyComment(pEnterprise, lEnterprisePackage);
0262:
0263: // Create design library package
0264: DesignLibrary lDesignLibrary = pEnterprise.getDesignLibrary();
0265: if (lDesignLibrary != null)
0266: convertDesignLibrary(pConversionContext, lDesignLibrary);
0267:
0268: // Now convert all systems
0269: convertSystems(pConversionContext, pEnterprise.getSystems());
0270: }
0271:
0272: private static void convertDesignLibrary(
0273: ConversionContext pConversionContext,
0274: DesignLibrary pDesignLibrary)
0275: throws ModelRepositoryException {
0276: org.omg.uml.modelmanagement.UmlPackage lDesignLibraryPackage = pConversionContext.mUMLModelExtent
0277: .getModelManagement().getUmlPackage()
0278: .createUmlPackage();
0279: Enterprise lEnterprise = pDesignLibrary.getEnterprise();
0280: if (lEnterprise != null) {
0281: // This is an enterprise design library
0282: lDesignLibraryPackage.setName("DesignLibrary");
0283: lDesignLibraryPackage.setNamespace(UMLUtils.getUmlPackage(
0284: pConversionContext.mTargetModelName, lEnterprise,
0285: UMLStylesheet.getEnterpriseXPath(lEnterprise)));
0286: } else {
0287: // This is standalone design library
0288: lDesignLibraryPackage.setName(pDesignLibrary.getName());
0289: lDesignLibraryPackage
0290: .setNamespace(pConversionContext.mEnterpriseModel);
0291: }
0292: lDesignLibraryPackage
0293: .getStereotype()
0294: .add(
0295: pConversionContext.mMetaBossProfile.mDesignLibraryPackageStereotype);
0296: UMLUtils.copyComment(pDesignLibrary, lDesignLibraryPackage);
0297:
0298: // Convert all data dictionaries from the enterprise design library
0299:
0300: // First go through convert only namespaces and typetemplates
0301: for (Iterator lDesignLibraryDictionariesIterator = pDesignLibrary
0302: .getDataDictionaries().iterator(); lDesignLibraryDictionariesIterator
0303: .hasNext();) {
0304: DataDictionary lDataDictionary = (DataDictionary) lDesignLibraryDictionariesIterator
0305: .next();
0306: org.omg.uml.modelmanagement.UmlPackage lDataDictionaryPackage = pConversionContext.mUMLModelExtent
0307: .getModelManagement().getUmlPackage()
0308: .createUmlPackage();
0309: lDataDictionaryPackage.setName(lDataDictionary.getName());
0310: lDataDictionaryPackage.setNamespace(lDesignLibraryPackage);
0311: lDataDictionaryPackage
0312: .getStereotype()
0313: .add(
0314: pConversionContext.mMetaBossProfile.mDataDictionaryPackageStereotype);
0315: UMLUtils.copyComment(lDataDictionary,
0316: lDataDictionaryPackage);
0317: // Cache the dictionary
0318: pConversionContext.mUmlElementsMap.put(lDataDictionary,
0319: lDataDictionaryPackage);
0320:
0321: convertSubNamespaces(pConversionContext,
0322: lDataDictionaryPackage, lDataDictionary
0323: .getSubNamespaces());
0324: convertTypetemplates(pConversionContext, lDataDictionary
0325: .getCombinedTypeTemplates());
0326: }
0327: // Second go through convert datatypes and structure types (without fields)
0328: for (Iterator lDesignLibraryDictionariesIterator = pDesignLibrary
0329: .getDataDictionaries().iterator(); lDesignLibraryDictionariesIterator
0330: .hasNext();) {
0331: DataDictionary lDataDictionary = (DataDictionary) lDesignLibraryDictionariesIterator
0332: .next();
0333: convertDatatypes(pConversionContext, lDataDictionary
0334: .getCombinedDataTypes());
0335: convertStructures(pConversionContext, lDataDictionary
0336: .getCombinedStructures());
0337: }
0338:
0339: // After all structures are created structure fields should be added as a separate step
0340: // note that adding fields will not work together with adding structures because
0341: // field can refer to another, as yet undefined, structure
0342: for (Iterator lDesignLibraryDictionariesIterator = pDesignLibrary
0343: .getDataDictionaries().iterator(); lDesignLibraryDictionariesIterator
0344: .hasNext();) {
0345: DataDictionary lDataDictionary = (DataDictionary) lDesignLibraryDictionariesIterator
0346: .next();
0347: for (Iterator lStructuresIterator = lDataDictionary
0348: .getCombinedStructures().iterator(); lStructuresIterator
0349: .hasNext();) {
0350: Structure lStructure = (Structure) lStructuresIterator
0351: .next();
0352: convertStructureFields(pConversionContext, lStructure
0353: .getFields());
0354: }
0355: }
0356: }
0357:
0358: // Helper. Converts given collection of systems from MetaBoss model to UML model
0359: private static void convertSystems(
0360: ConversionContext pConversionContext,
0361: Collection pSourceSystems) throws ModelRepositoryException {
0362: // During the firts run through only create system package, data dictionary, typetemplates
0363: org.omg.uml.modelmanagement.UmlPackage lCurrentUmlEnterprise = null;
0364: Enterprise lCurrentEnterprise = null;
0365: for (Iterator lSystemsIterator = pSourceSystems.iterator(); lSystemsIterator
0366: .hasNext();) {
0367: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lSystemsIterator
0368: .next();
0369: Enterprise lEnterprise = lSystem.getEnterprise();
0370: if (lCurrentEnterprise == null
0371: || lCurrentEnterprise.equals(lEnterprise) == false) {
0372: // Now set the new currents
0373: lCurrentEnterprise = lEnterprise;
0374: lCurrentUmlEnterprise = UMLUtils.getUmlPackage(
0375: pConversionContext.mTargetModelName,
0376: lEnterprise, UMLStylesheet
0377: .getEnterpriseXPath(lEnterprise));
0378: }
0379: // Now add system, its public interfaces and implementation packages
0380: org.omg.uml.modelmanagement.UmlPackage lUmlSystem = pConversionContext.mUMLModelExtent
0381: .getModelManagement().getUmlPackage()
0382: .createUmlPackage();
0383: lUmlSystem.setName(lSystem.getName());
0384: lUmlSystem.setNamespace(lCurrentUmlEnterprise);
0385: lUmlSystem
0386: .getStereotype()
0387: .add(
0388: pConversionContext.mMetaBossProfile.mSystemPackageStereotype);
0389: UMLUtils.copyComment(lSystem, lUmlSystem);
0390:
0391: org.omg.uml.modelmanagement.UmlPackage lUmlSystemPublicInterfaces = pConversionContext.mUMLModelExtent
0392: .getModelManagement().getUmlPackage()
0393: .createUmlPackage();
0394: lUmlSystemPublicInterfaces
0395: .setName(UMLStylesheet.mSystemPublicInterfacesPackageName);
0396: lUmlSystemPublicInterfaces.setNamespace(lUmlSystem);
0397:
0398: org.omg.uml.modelmanagement.UmlPackage lUmlSystemDataDictionary = pConversionContext.mUMLModelExtent
0399: .getModelManagement().getUmlPackage()
0400: .createUmlPackage();
0401: lUmlSystemDataDictionary
0402: .setName(UMLStylesheet.mSystemDataDictionaryPackageName);
0403: lUmlSystemDataDictionary
0404: .setNamespace(lUmlSystemPublicInterfaces);
0405: lUmlSystemDataDictionary
0406: .getStereotype()
0407: .add(
0408: pConversionContext.mMetaBossProfile.mDataDictionaryPackageStereotype);
0409:
0410: org.omg.uml.modelmanagement.UmlPackage lUmlSystemServicemodules = pConversionContext.mUMLModelExtent
0411: .getModelManagement().getUmlPackage()
0412: .createUmlPackage();
0413: lUmlSystemServicemodules
0414: .setName(UMLStylesheet.mSystemServicemodulesPackageName);
0415: lUmlSystemServicemodules
0416: .setNamespace(lUmlSystemPublicInterfaces);
0417:
0418: org.omg.uml.modelmanagement.UmlPackage lUmlSystemImplementationComponents = pConversionContext.mUMLModelExtent
0419: .getModelManagement().getUmlPackage()
0420: .createUmlPackage();
0421: lUmlSystemImplementationComponents
0422: .setName(UMLStylesheet.mSystemImplementationComponentsPackageName);
0423: lUmlSystemImplementationComponents.setNamespace(lUmlSystem);
0424:
0425: // First go only add data dictionary with namespace and typetemplates
0426: DataDictionary lDataDictionary = lSystem
0427: .getDataDictionary();
0428: if (lDataDictionary != null) {
0429: convertSubNamespaces(pConversionContext,
0430: lUmlSystemDataDictionary, lDataDictionary
0431: .getSubNamespaces());
0432: convertTypetemplates(pConversionContext,
0433: lDataDictionary.getCombinedTypeTemplates());
0434: }
0435: }
0436: // Now add datatypes and structures in a separate step - only after all templates are added
0437: for (Iterator lSystemsIterator = pSourceSystems.iterator(); lSystemsIterator
0438: .hasNext();) {
0439: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lSystemsIterator
0440: .next();
0441: DataDictionary lDataDictionary = lSystem
0442: .getDataDictionary();
0443: if (lDataDictionary != null) {
0444: convertDatatypes(pConversionContext, lDataDictionary
0445: .getCombinedDataTypes());
0446: convertStructures(pConversionContext, lDataDictionary
0447: .getCombinedStructures());
0448: }
0449: }
0450: // Now add structure fiedsin a separate step - only after all datatypes and structures are added
0451: for (Iterator lSystemsIterator = pSourceSystems.iterator(); lSystemsIterator
0452: .hasNext();) {
0453: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lSystemsIterator
0454: .next();
0455: DataDictionary lDataDictionary = lSystem
0456: .getDataDictionary();
0457: if (lDataDictionary != null) {
0458: for (Iterator lStructuresIterator = lDataDictionary
0459: .getCombinedStructures().iterator(); lStructuresIterator
0460: .hasNext();) {
0461: Structure lStructure = (Structure) lStructuresIterator
0462: .next();
0463: convertStructureFields(pConversionContext,
0464: lStructure.getFields());
0465: }
0466: }
0467: }
0468:
0469: // Now add servicemodules
0470: convertServicemodules(pConversionContext);
0471:
0472: // Domains
0473: convertDomains(pConversionContext);
0474: // Entities
0475: convertEntities(pConversionContext);
0476: // Associations
0477: convertEntityAssociations(pConversionContext);
0478: convertEntitySelectors(pConversionContext);
0479: convertEntityPrimaryKeys(pConversionContext);
0480: // State machines
0481: convertEntityStateMachines(pConversionContext);
0482: convertEntityStates(pConversionContext);
0483: convertEntityStateTransitions(pConversionContext);
0484: }
0485:
0486: // Helper. Puts all source SubNamespaces into the target package
0487: private static void convertSubNamespaces(
0488: ConversionContext pConversionContext,
0489: org.omg.uml.modelmanagement.UmlPackage pTargetPackage,
0490: Collection pSourceSubNamespaces)
0491: throws ModelRepositoryException {
0492: for (Iterator lSubNamespacesIterator = pSourceSubNamespaces
0493: .iterator(); lSubNamespacesIterator.hasNext();) {
0494: Namespace lNamespace = (Namespace) lSubNamespacesIterator
0495: .next();
0496: org.omg.uml.modelmanagement.UmlPackage lNamespacePackage = pConversionContext.mUMLModelExtent
0497: .getModelManagement().getUmlPackage()
0498: .createUmlPackage();
0499: lNamespacePackage.setName(lNamespace.getName());
0500: lNamespacePackage.setNamespace(pTargetPackage);
0501: UMLUtils.copyComment(lNamespace, lNamespacePackage);
0502: // Cache the namespace
0503: pConversionContext.mUmlElementsMap.put(lNamespace,
0504: lNamespacePackage);
0505: // Convert child namespaces
0506: convertSubNamespaces(pConversionContext, lNamespacePackage,
0507: lNamespace.getSubNamespaces());
0508: }
0509: }
0510:
0511: // Helper. Puts all typetemplates in the target model
0512: private static void convertTypetemplates(
0513: ConversionContext pConversionContext,
0514: Collection pSourceTypetemplates)
0515: throws ModelRepositoryException {
0516: org.omg.uml.modelmanagement.UmlPackage lCurrentNamespacePackage = null;
0517: AbstractNamespace lCurrentNamespace = null;
0518: for (Iterator lTypetemplatesIterator = pSourceTypetemplates
0519: .iterator(); lTypetemplatesIterator.hasNext();) {
0520: TypeTemplate lTypetemplate = (TypeTemplate) lTypetemplatesIterator
0521: .next();
0522: AbstractNamespace lTypetemplateNamespace = lTypetemplate
0523: .getNamespace();
0524: if (lCurrentNamespace == null
0525: || lCurrentNamespace.equals(lTypetemplateNamespace) == false) {
0526: // Now set the new currents
0527: lCurrentNamespace = lTypetemplateNamespace;
0528: lCurrentNamespacePackage = pConversionContext
0529: .getUmlNamespace(lTypetemplateNamespace);
0530: }
0531: // Now add template to the package
0532: org.omg.uml.foundation.core.UmlClass lUmlTypetemplate = pConversionContext.mUMLModelExtent
0533: .getCore().getUmlClass().createUmlClass();
0534: lUmlTypetemplate.setName(lTypetemplate.getName());
0535: lUmlTypetemplate.setAbstract(true);
0536: lUmlTypetemplate.setNamespace(lCurrentNamespacePackage);
0537: lUmlTypetemplate
0538: .getStereotype()
0539: .add(
0540: pConversionContext.mMetaBossProfile.mTypetemplateStereotype);
0541: UMLUtils.copyComment(lTypetemplate, lUmlTypetemplate);
0542: // Now add template descriptors in the loop
0543: addTypetemplatePropertyDescriptors(pConversionContext,
0544: lUmlTypetemplate, lTypetemplate);
0545:
0546: // Cache newly created typetemplate
0547: pConversionContext.mUmlElementsMap.put(lTypetemplate,
0548: lUmlTypetemplate);
0549:
0550: }
0551: }
0552:
0553: // Helper. Adds TypetemplatePropertyDescriptors to the model element
0554: private static void addTypetemplatePropertyDescriptors(
0555: ConversionContext pConversionContext,
0556: org.omg.uml.foundation.core.UmlClass pTargetTypetemplate,
0557: TypeTemplate pSourceTypetemplate)
0558: throws ModelRepositoryException {
0559: for (Iterator lPropertyDescriptorsIter = pSourceTypetemplate
0560: .getPropertyDescriptors().iterator(); lPropertyDescriptorsIter
0561: .hasNext();) {
0562: PropertyDescriptor lPropertyDescriptor = (PropertyDescriptor) lPropertyDescriptorsIter
0563: .next();
0564:
0565: // Create new Template parameter
0566: org.omg.uml.foundation.core.TemplateParameter lUmlTemplateParameter = pConversionContext.mUMLModelExtent
0567: .getCore().getTemplateParameter()
0568: .createTemplateParameter();
0569: lUmlTemplateParameter.setTemplate(pTargetTypetemplate);
0570:
0571: // Create Generic Uml parameter and package it in the TemplateParameter
0572: org.omg.uml.foundation.core.Parameter lUmlParameter = pConversionContext.mUMLModelExtent
0573: .getCore().getParameter().createParameter();
0574: lUmlTemplateParameter.setParameter(lUmlParameter);
0575: lUmlParameter.setName(lPropertyDescriptor.getName());
0576: lUmlParameter
0577: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0578: lUmlParameter
0579: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
0580: lUmlParameter
0581: .getStereotype()
0582: .add(
0583: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
0584: UMLUtils.copyComment(lPropertyDescriptor, lUmlParameter);
0585: UMLUtils
0586: .attachSingleTagToElement(
0587: lUmlParameter,
0588: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
0589: Boolean.toString(lPropertyDescriptor
0590: .isArray()));
0591: // Call recursive method to add child property decriptors if it is necessary
0592: if (lPropertyDescriptor.isContainer()) {
0593: addTypetemplatePropertyDescriptors(pConversionContext,
0594: lUmlParameter, lPropertyDescriptor);
0595: }
0596: }
0597: }
0598:
0599: // Helper. Adds TypetemplatePropertyDescriptors recursively to the model element
0600: private static void addTypetemplatePropertyDescriptors(
0601: ConversionContext pConversionContext,
0602: org.omg.uml.foundation.core.Parameter pTargetParameter,
0603: PropertyDescriptor pSourceDescriptor)
0604: throws ModelRepositoryException {
0605: for (Iterator lPropertyDescriptorsIter = pSourceDescriptor
0606: .getSubPropertyDescriptors().iterator(); lPropertyDescriptorsIter
0607: .hasNext();) {
0608: // Create Uml parameter and package it in the TemplateParameter
0609: PropertyDescriptor lPropertyDescriptor = (PropertyDescriptor) lPropertyDescriptorsIter
0610: .next();
0611:
0612: // Create new Template parameter
0613: org.omg.uml.foundation.core.TemplateParameter lUmlTemplateParameter = pConversionContext.mUMLModelExtent
0614: .getCore().getTemplateParameter()
0615: .createTemplateParameter();
0616: lUmlTemplateParameter.setTemplate(pTargetParameter);
0617:
0618: // Create Generic Uml parameter and package it in the TemplateParameter
0619: org.omg.uml.foundation.core.Parameter lUmlParameter = pConversionContext.mUMLModelExtent
0620: .getCore().getParameter().createParameter();
0621: lUmlTemplateParameter.setParameter(lUmlParameter);
0622: lUmlParameter.setName(lPropertyDescriptor.getName());
0623: lUmlParameter
0624: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0625: lUmlParameter
0626: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
0627: lUmlParameter
0628: .getStereotype()
0629: .add(
0630: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
0631: UMLUtils.copyComment(lPropertyDescriptor, lUmlParameter);
0632: UMLUtils
0633: .attachSingleTagToElement(
0634: lUmlParameter,
0635: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
0636: Boolean.toString(lPropertyDescriptor
0637: .isArray()));
0638:
0639: // Call recursive method to add child property decriptors if it is necessary
0640: if (lPropertyDescriptor.isContainer()) {
0641: addTypetemplatePropertyDescriptors(pConversionContext,
0642: lUmlParameter, lPropertyDescriptor);
0643: }
0644: }
0645: }
0646:
0647: // Helper. Puts all domains in the target model
0648: private static void convertDomains(
0649: ConversionContext pConversionContext)
0650: throws ModelRepositoryException {
0651: Collection lDomains = pConversionContext.mMetaBossModelExtent
0652: .getEnterpriseModel().getSystemImplementationModel()
0653: .getDomain().refAllOfClass();
0654: org.omg.uml.modelmanagement.UmlPackage lCurrentSystemImplementationPackage = null;
0655: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lCurrentSystem = null;
0656: for (Iterator lDomainsIterator = lDomains.iterator(); lDomainsIterator
0657: .hasNext();) {
0658: Domain lDomain = (Domain) lDomainsIterator.next();
0659: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0660: .getSystem();
0661: if (lCurrentSystem == null
0662: || lCurrentSystem.equals(lSystem) == false) {
0663: // Now set the new currents
0664: lCurrentSystem = lSystem;
0665: lCurrentSystemImplementationPackage = UMLUtils
0666: .getUmlPackage(
0667: pConversionContext.mTargetModelName,
0668: lSystem,
0669: UMLStylesheet
0670: .getSystemImplementationComponentsXPath(lSystem));
0671: }
0672: // Now add domain package
0673: org.omg.uml.modelmanagement.UmlPackage lDomainPackage = pConversionContext.mUMLModelExtent
0674: .getModelManagement().getUmlPackage()
0675: .createUmlPackage();
0676: lDomainPackage.setName(lDomain.getName());
0677: lDomainPackage
0678: .setNamespace(lCurrentSystemImplementationPackage);
0679: lDomainPackage
0680: .getStereotype()
0681: .add(
0682: pConversionContext.mMetaBossProfile.mDomainPackageStereotype);
0683: UMLUtils.copyComment(lDomain, lDomainPackage);
0684: }
0685: }
0686:
0687: // Helper. Puts all entities in the target model
0688: private static void convertEntities(
0689: ConversionContext pConversionContext)
0690: throws ModelRepositoryException {
0691: Collection lEntities = pConversionContext.mMetaBossModelExtent
0692: .getEnterpriseModel().getSystemImplementationModel()
0693: .getEntity().refAllOfClass();
0694: // Do not set inheritance on the first run because supertype may not be defined yet
0695: org.omg.uml.modelmanagement.UmlPackage lCurrentDomainPackage = null;
0696: Domain lCurrentDomain = null;
0697: for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
0698: .hasNext();) {
0699: Entity lEntity = (Entity) lEntitiesIterator.next();
0700: Domain lDomain = lEntity.getDomain();
0701: if (lCurrentDomain == null
0702: || lCurrentDomain.equals(lDomain) == false) {
0703: // Now set the new currents
0704: lCurrentDomain = lDomain;
0705: lCurrentDomainPackage = UMLUtils.getUmlPackage(
0706: pConversionContext.mTargetModelName, lDomain,
0707: UMLStylesheet.getDomainXPath(lDomain));
0708: }
0709: // Now add entity class
0710: org.omg.uml.foundation.core.UmlClass lEntityClass = pConversionContext.mUMLModelExtent
0711: .getCore().getUmlClass().createUmlClass();
0712: lEntityClass.setName(lEntity.getName());
0713: lEntityClass.setNamespace(lCurrentDomainPackage);
0714: lEntityClass
0715: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0716: lEntityClass
0717: .getStereotype()
0718: .add(
0719: pConversionContext.mMetaBossProfile.mEntityClassStereotype);
0720: lEntityClass.setAbstract(lEntity.isAbstract());
0721: lEntityClass.setLeaf(lEntity.isFinal());
0722: UMLUtils
0723: .attachSingleTagToElement(
0724: lEntityClass,
0725: pConversionContext.mMetaBossProfile.mEntityClassTagDefinition_Type,
0726: lEntity.getStereotype().toString());
0727: UMLUtils
0728: .attachSingleTagToElement(
0729: lEntityClass,
0730: pConversionContext.mMetaBossProfile.mEntityClassTagDefinition_PluralName,
0731: lEntity.getPluralName());
0732: UMLUtils.copyComment(lEntity, lEntityClass);
0733:
0734: Collection lEntityClassFeatures = lEntityClass.getFeature();
0735: // Add implicit attributes
0736: // - InstanceId
0737: {
0738: org.omg.uml.foundation.core.Attribute lEntityAttribute = pConversionContext.mUMLModelExtent
0739: .getCore().getAttribute().createAttribute();
0740: lEntityClassFeatures.add(lEntityAttribute);
0741: lEntityAttribute.setName("InstanceId");
0742: lEntityAttribute
0743: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0744: lEntityAttribute
0745: .setType(pConversionContext
0746: .getUmlDataType(lEntity
0747: .getInstanceIdDataType()));
0748: lEntityAttribute
0749: .getStereotype()
0750: .add(
0751: pConversionContext.mMetaBossProfile.mEntityAttributeStereotype);
0752: UMLUtils
0753: .attachSingleTagToElement(
0754: lEntityAttribute,
0755: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Derived,
0756: Boolean.toString(true));
0757: UMLUtils
0758: .attachSingleTagToElement(
0759: lEntityAttribute,
0760: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Type,
0761: AttributeStereotypeEnum.MANDATORY
0762: .toString());
0763: UMLUtils
0764: .attachSingleTagToElement(
0765: lEntityAttribute,
0766: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_IsUsedForOrdering,
0767: Boolean.toString(false));
0768: UMLUtils
0769: .copyComment(
0770: "This autogenerated attribute contains unique id of the instance. It helps to provide fast direct access to all entities.",
0771: lEntityAttribute);
0772: }
0773: // - Version Id only for updateable ones
0774: if (!lEntity.getStereotype().equals(
0775: EntityStereotypeEnum.LOG_FILE)) {
0776: org.omg.uml.foundation.core.Attribute lEntityAttribute = pConversionContext.mUMLModelExtent
0777: .getCore().getAttribute().createAttribute();
0778: lEntityClassFeatures.add(lEntityAttribute);
0779: lEntityAttribute.setName("VersionId");
0780: lEntityAttribute
0781: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0782: lEntityAttribute
0783: .setType(pConversionContext
0784: .getUmlDataType(lEntity
0785: .getVersionIdDataType()));
0786: lEntityAttribute
0787: .getStereotype()
0788: .add(
0789: pConversionContext.mMetaBossProfile.mEntityAttributeStereotype);
0790: UMLUtils
0791: .attachSingleTagToElement(
0792: lEntityAttribute,
0793: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Derived,
0794: Boolean.toString(true));
0795: UMLUtils
0796: .attachSingleTagToElement(
0797: lEntityAttribute,
0798: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Type,
0799: AttributeStereotypeEnum.MANDATORY
0800: .toString());
0801: UMLUtils
0802: .attachSingleTagToElement(
0803: lEntityAttribute,
0804: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_IsUsedForOrdering,
0805: Boolean.toString(false));
0806: UMLUtils
0807: .copyComment(
0808: "This autogenerated attribute contains version id of the instance. It helps to keep track of updates and protect data integrity.",
0809: lEntityAttribute);
0810: }
0811: // - State only for the ones which have state
0812: if (lEntity.getStateMachine() != null) {
0813: org.omg.uml.foundation.core.Attribute lEntityAttribute = pConversionContext.mUMLModelExtent
0814: .getCore().getAttribute().createAttribute();
0815: lEntityClassFeatures.add(lEntityAttribute);
0816: lEntityAttribute.setName("State");
0817: lEntityAttribute
0818: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0819: lEntityAttribute.setType(pConversionContext
0820: .getUmlDataType(lEntity.getStateDataType()));
0821: lEntityAttribute
0822: .getStereotype()
0823: .add(
0824: pConversionContext.mMetaBossProfile.mEntityAttributeStereotype);
0825: UMLUtils
0826: .attachSingleTagToElement(
0827: lEntityAttribute,
0828: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Derived,
0829: Boolean.toString(true));
0830: UMLUtils
0831: .attachSingleTagToElement(
0832: lEntityAttribute,
0833: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Type,
0834: AttributeStereotypeEnum.MANDATORY
0835: .toString());
0836: UMLUtils
0837: .attachSingleTagToElement(
0838: lEntityAttribute,
0839: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_IsUsedForOrdering,
0840: Boolean.toString(false));
0841: UMLUtils
0842: .copyComment(
0843: "This autogenerated attribute contains state of the entity. It is automatically included in the entities with the state machine.",
0844: lEntityAttribute);
0845: }
0846:
0847: for (Iterator lAttributesIterator = lEntity.getAttributes()
0848: .iterator(); lAttributesIterator.hasNext();) {
0849: Attribute lAttribute = (Attribute) lAttributesIterator
0850: .next();
0851: org.omg.uml.foundation.core.Attribute lEntityAttribute = pConversionContext.mUMLModelExtent
0852: .getCore().getAttribute().createAttribute();
0853: lEntityClassFeatures.add(lEntityAttribute);
0854: lEntityAttribute.setName(lAttribute.getName());
0855: lEntityAttribute
0856: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0857: lEntityAttribute.setType(pConversionContext
0858: .getUmlDataType(lAttribute.getDataType()));
0859:
0860: lEntityAttribute
0861: .getStereotype()
0862: .add(
0863: pConversionContext.mMetaBossProfile.mEntityAttributeStereotype);
0864: UMLUtils
0865: .attachSingleTagToElement(
0866: lEntityAttribute,
0867: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Derived,
0868: Boolean.toString(false));
0869: UMLUtils
0870: .attachSingleTagToElement(
0871: lEntityAttribute,
0872: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_Type,
0873: lAttribute.getStereotype().toString());
0874: UMLUtils
0875: .attachSingleTagToElement(
0876: lEntityAttribute,
0877: pConversionContext.mMetaBossProfile.mEntityAttributeTagDefinition_IsUsedForOrdering,
0878: Boolean.toString(lAttribute
0879: .isUsedForOrdering()));
0880: UMLUtils.copyComment(lAttribute, lEntityAttribute);
0881: }
0882: // Convert constraints if necessary
0883: Collection lConstraints = lEntity.getConstraints();
0884: if (!lConstraints.isEmpty()) {
0885: String lEntityName = lEntity.getName();
0886: String lContextName = lEntityName.substring(0, 1)
0887: .toUpperCase()
0888: + lEntityName.substring(1);
0889: String lConstraintStringStart = "context "
0890: + lContextName + " inv : ";
0891: convertConstraints(pConversionContext, lConstraints,
0892: lEntityClass, lConstraintStringStart);
0893: }
0894: }
0895: // Now that all entities are created we could go and set up inheritance
0896: org.omg.uml.foundation.core.GeneralizationClass lGeneralisationClass = pConversionContext.mUMLModelExtent
0897: .getCore().getGeneralization();
0898: for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
0899: .hasNext();) {
0900: Entity lEntity = (Entity) lEntitiesIterator.next();
0901: Entity lSupertypeEntity = lEntity.getSupertype();
0902: if (lSupertypeEntity != null) {
0903: // We have got a supertype - add generalisation in
0904: Domain lDomain = lEntity.getDomain();
0905: if (lCurrentDomain == null
0906: || lCurrentDomain.equals(lDomain) == false) {
0907: // Now set the new currents
0908: lCurrentDomain = lDomain;
0909: lCurrentDomainPackage = UMLUtils.getUmlPackage(
0910: pConversionContext.mTargetModelName,
0911: lDomain, UMLStylesheet
0912: .getDomainXPath(lDomain));
0913: }
0914: org.omg.uml.foundation.core.UmlClass lEntityClass = UMLUtils
0915: .getUmlClass(
0916: pConversionContext.mTargetModelName,
0917: lEntity, UMLStylesheet
0918: .getEntityXPath(lEntity));
0919: org.omg.uml.foundation.core.UmlClass lSupertypeEntityClass = UMLUtils
0920: .getUmlClass(
0921: pConversionContext.mTargetModelName,
0922: lSupertypeEntity,
0923: UMLStylesheet
0924: .getEntityXPath(lSupertypeEntity));
0925: org.omg.uml.foundation.core.Generalization lGeneralization = lGeneralisationClass
0926: .createGeneralization();
0927: lGeneralization.setNamespace(lCurrentDomainPackage);
0928: lGeneralization.setParent(lSupertypeEntityClass);
0929: lGeneralization.setChild(lEntityClass);
0930: }
0931: }
0932: }
0933:
0934: // Helper. Puts all entities in the target model
0935: private static void convertEntityStateMachines(
0936: ConversionContext pConversionContext)
0937: throws ModelRepositoryException {
0938: Collection lStateMachines = pConversionContext.mMetaBossModelExtent
0939: .getStateMachineModel().getStateMachine()
0940: .refAllOfClass();
0941: org.omg.uml.modelmanagement.UmlPackage lCurrentDomainPackage = null;
0942: Domain lCurrentDomain = null;
0943: for (Iterator lStateMachinesIterator = lStateMachines
0944: .iterator(); lStateMachinesIterator.hasNext();) {
0945: StateMachine lStateMachine = (StateMachine) lStateMachinesIterator
0946: .next();
0947: Entity lOwnerEntity = lStateMachine.getEntity();
0948: Domain lDomain = lOwnerEntity.getDomain();
0949: if (lCurrentDomain == null
0950: || lCurrentDomain.equals(lDomain) == false) {
0951: // Now set the new currents
0952: lCurrentDomain = lDomain;
0953: lCurrentDomainPackage = UMLUtils.getUmlPackage(
0954: pConversionContext.mTargetModelName, lDomain,
0955: UMLStylesheet.getDomainXPath(lDomain));
0956: }
0957: org.omg.uml.foundation.core.UmlClass lEntityClass = UMLUtils
0958: .getUmlClass(pConversionContext.mTargetModelName,
0959: lOwnerEntity, UMLStylesheet
0960: .getEntityXPath(lOwnerEntity));
0961: org.omg.uml.behavioralelements.statemachines.StateMachine lUMLStateMachine = pConversionContext.mUMLModelExtent
0962: .getStateMachines().getStateMachine()
0963: .createStateMachine();
0964: lUMLStateMachine.setNamespace(lEntityClass);
0965: lUMLStateMachine.setContext(lEntityClass);
0966: lUMLStateMachine
0967: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
0968: UMLUtils.copyComment(lStateMachine, lUMLStateMachine);
0969: org.omg.uml.behavioralelements.statemachines.CompositeState lBaseState = pConversionContext.mUMLModelExtent
0970: .getStateMachines().getCompositeState()
0971: .createCompositeState();
0972: lUMLStateMachine.setTop(lBaseState);
0973: }
0974: }
0975:
0976: // Helper. Puts all entity states in the target model
0977: private static void convertEntityStates(
0978: ConversionContext pConversionContext)
0979: throws ModelRepositoryException {
0980: Collection lStates = pConversionContext.mMetaBossModelExtent
0981: .getStateMachineModel().getState().refAllOfClass();
0982: // Do not set inheritance on the first run because supertype may not be defined yet
0983: org.omg.uml.behavioralelements.statemachines.StateMachine lCurrentUMLStateMachine = null;
0984: StateMachine lCurrentStateMachine = null;
0985: for (Iterator lStatesIterator = lStates.iterator(); lStatesIterator
0986: .hasNext();) {
0987: State lState = (State) lStatesIterator.next();
0988: StateMachine lStateMachine = lState.getStateMachine();
0989: if (lCurrentStateMachine == null
0990: || lCurrentStateMachine.equals(lStateMachine) == false) {
0991: // Now set the new currents
0992: lCurrentStateMachine = lStateMachine;
0993: lCurrentUMLStateMachine = UMLUtils.getUmlStateMachine(
0994: pConversionContext.mTargetModelName,
0995: lStateMachine);
0996: }
0997: org.omg.uml.behavioralelements.statemachines.CompositeState lBaseState = (org.omg.uml.behavioralelements.statemachines.CompositeState) lCurrentUMLStateMachine
0998: .getTop();
0999: if (lState.getType().equals(StateTypeEnum.INITIAL)) {
1000: // Initial state
1001: org.omg.uml.behavioralelements.statemachines.Pseudostate lUMLInitialState = pConversionContext.mUMLModelExtent
1002: .getStateMachines().getPseudostate()
1003: .createPseudostate();
1004: lUMLInitialState.setName(lState.getName());
1005: lUMLInitialState.setContainer(lBaseState);
1006: lUMLInitialState
1007: .setKind(PseudostateKindEnum.PK_INITIAL);
1008: lUMLInitialState
1009: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1010: UMLUtils.copyComment(lState, lUMLInitialState);
1011: } else if (lState.getType().equals(StateTypeEnum.FINAL)) {
1012: // Final state
1013: org.omg.uml.behavioralelements.statemachines.FinalState lUMLFinalState = pConversionContext.mUMLModelExtent
1014: .getStateMachines().getFinalState()
1015: .createFinalState();
1016: lUMLFinalState.setName(lState.getName());
1017: lUMLFinalState.setContainer(lBaseState);
1018: lUMLFinalState
1019: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1020: UMLUtils.copyComment(lState, lUMLFinalState);
1021: } else {
1022: // Normal state
1023: org.omg.uml.behavioralelements.statemachines.SimpleState lUMLSimpleState = pConversionContext.mUMLModelExtent
1024: .getStateMachines().getSimpleState()
1025: .createSimpleState();
1026: lUMLSimpleState.setName(lState.getName());
1027: lUMLSimpleState.setContainer(lBaseState);
1028: lUMLSimpleState
1029: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1030: UMLUtils.copyComment(lState, lUMLSimpleState);
1031: }
1032: }
1033: }
1034:
1035: // Helper. Puts all entity state transitions
1036: private static void convertEntityStateTransitions(
1037: ConversionContext pConversionContext)
1038: throws ModelRepositoryException {
1039: Collection lStateTransitions = pConversionContext.mMetaBossModelExtent
1040: .getStateMachineModel().getTransition().refAllOfClass();
1041: // Do not set inheritance on the first run because supertype may not be defined yet
1042: org.omg.uml.behavioralelements.statemachines.StateMachine lCurrentUMLStateMachine = null;
1043: StateMachine lCurrentStateMachine = null;
1044: for (Iterator lStateTransitionsIterator = lStateTransitions
1045: .iterator(); lStateTransitionsIterator.hasNext();) {
1046: Transition lTransition = (Transition) lStateTransitionsIterator
1047: .next();
1048: StateMachine lStateMachine = lTransition.getStateMachine();
1049: if (lCurrentStateMachine == null
1050: || lCurrentStateMachine.equals(lStateMachine) == false) {
1051: // Now set the new currents
1052: lCurrentStateMachine = lStateMachine;
1053: lCurrentUMLStateMachine = UMLUtils.getUmlStateMachine(
1054: pConversionContext.mTargetModelName,
1055: lStateMachine);
1056: }
1057:
1058: org.omg.uml.behavioralelements.statemachines.Transition lUmlTransition = pConversionContext.mUMLModelExtent
1059: .getStateMachines().getTransition()
1060: .createTransition();
1061: lUmlTransition.setName(lTransition.getName());
1062: lUmlTransition.setStateMachine(lCurrentUMLStateMachine);
1063: lUmlTransition
1064: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1065: UMLUtils.copyComment(lTransition, lUmlTransition);
1066: lUmlTransition.setSource(UMLUtils.getUmlState(
1067: pConversionContext.mTargetModelName, lTransition
1068: .getStartState()));
1069: lUmlTransition.setTarget(UMLUtils.getUmlState(
1070: pConversionContext.mTargetModelName, lTransition
1071: .getEndState()));
1072: }
1073: }
1074:
1075: // Helper. Puts all associations in the target model
1076: private static void convertEntityAssociations(
1077: ConversionContext pConversionContext)
1078: throws ModelRepositoryException {
1079: Collection lAssociations = pConversionContext.mMetaBossModelExtent
1080: .getEnterpriseModel().getSystemImplementationModel()
1081: .getAssociation().refAllOfClass();
1082: // Do not set inheritance on the first run because supertype may not be defined yet
1083: org.omg.uml.modelmanagement.UmlPackage lCurrentDomainPackage = null;
1084: Domain lCurrentDomain = null;
1085: for (Iterator lAssociationsIterator = lAssociations.iterator(); lAssociationsIterator
1086: .hasNext();) {
1087: Association lAssociation = (Association) lAssociationsIterator
1088: .next();
1089: Domain lDomain = lAssociation.getDomain();
1090: if (lCurrentDomain == null
1091: || lCurrentDomain.equals(lDomain) == false) {
1092: // Now set the new currents
1093: lCurrentDomain = lDomain;
1094: lCurrentDomainPackage = UMLUtils.getUmlPackage(
1095: pConversionContext.mTargetModelName, lDomain,
1096: UMLStylesheet.getDomainXPath(lDomain));
1097: }
1098: // Now add association and two ends
1099: org.omg.uml.foundation.core.UmlAssociation lUmlAssociation = pConversionContext.mUMLModelExtent
1100: .getCore().getUmlAssociation()
1101: .createUmlAssociation();
1102: lUmlAssociation.setName(lAssociation.getName());
1103: lUmlAssociation.setNamespace(lCurrentDomainPackage);
1104: lUmlAssociation
1105: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1106: UMLUtils.copyComment(lAssociation, lUmlAssociation);
1107:
1108: // Thre are only two ends
1109: for (Iterator lAssociationRolesIterator = lAssociation
1110: .getRoles().iterator(); lAssociationRolesIterator
1111: .hasNext();) {
1112: AssociationRole lAssociationRole = (AssociationRole) lAssociationRolesIterator
1113: .next();
1114: org.omg.uml.foundation.core.AssociationEnd lUmlAssociationEnd = pConversionContext.mUMLModelExtent
1115: .getCore().getAssociationEnd()
1116: .createAssociationEnd();
1117: lUmlAssociationEnd.setName(lAssociationRole.getName());
1118: lUmlAssociationEnd.setAssociation(lUmlAssociation);
1119: lUmlAssociationEnd
1120: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1121: lUmlAssociationEnd
1122: .getStereotype()
1123: .add(
1124: pConversionContext.mMetaBossProfile.mAssociationRoleStereotype);
1125: UMLUtils.copyComment(lAssociationRole,
1126: lUmlAssociationEnd);
1127: UMLUtils
1128: .attachSingleTagToElement(
1129: lUmlAssociationEnd,
1130: pConversionContext.mMetaBossProfile.mAssociationRoleTagDefinition_PluralName,
1131: lAssociationRole.getPluralName());
1132: AggregationType lAggregationType = lAssociationRole
1133: .getAggregationType();
1134: if (lAggregationType
1135: .equals(AggregationTypeEnum.COMPOSITION))
1136: lUmlAssociationEnd
1137: .setAggregation(AggregationKindEnum.AK_COMPOSITE);
1138: else if (lAggregationType
1139: .equals(AggregationTypeEnum.AGGREGATION))
1140: lUmlAssociationEnd
1141: .setAggregation(AggregationKindEnum.AK_AGGREGATE);
1142: else
1143: lUmlAssociationEnd
1144: .setAggregation(AggregationKindEnum.AK_NONE);
1145: lUmlAssociationEnd.setNavigable(true);
1146: lUmlAssociationEnd.setMultiplicity(UMLUtils
1147: .createMultiplicityInstance(
1148: pConversionContext.mUMLModelExtent,
1149: lAssociationRole.isOptional() ? 0 : 1,
1150: lAssociationRole.isPlural() ? -1 : 1));
1151: Entity lEntityInRole = lAssociationRole.getEntity();
1152: org.omg.uml.foundation.core.UmlClass lEntityClass = UMLUtils
1153: .getUmlClass(
1154: pConversionContext.mTargetModelName,
1155: lEntityInRole, UMLStylesheet
1156: .getEntityXPath(lEntityInRole));
1157: lUmlAssociationEnd.setParticipant(lEntityClass);
1158: }
1159: }
1160: }
1161:
1162: // Helper. Puts all associations in the target model
1163: private static void convertEntityPrimaryKeys(
1164: ConversionContext pConversionContext)
1165: throws ModelRepositoryException {
1166: Collection lEntities = pConversionContext.mMetaBossModelExtent
1167: .getEnterpriseModel().getSystemImplementationModel()
1168: .getEntity().refAllOfClass();
1169: for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
1170: .hasNext();) {
1171: Entity lEntity = (Entity) lEntitiesIterator.next();
1172: Collection lPrimaryKeyElements = lEntity
1173: .getPrimaryKeyElements();
1174: if (!lPrimaryKeyElements.isEmpty()) {
1175: org.omg.uml.foundation.core.UmlClass lEntityClass = UMLUtils
1176: .getUmlClass(
1177: pConversionContext.mTargetModelName,
1178: lEntity, UMLStylesheet
1179: .getEntityXPath(lEntity));
1180: for (Iterator lElementsIterator = lPrimaryKeyElements
1181: .iterator(); lElementsIterator.hasNext();) {
1182: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lElementsIterator
1183: .next();
1184: UMLUtils
1185: .attachSingleTagToElement(
1186: lEntityClass,
1187: pConversionContext.mMetaBossProfile.mEntityClassTagDefinition_PrimaryKeyElement,
1188: lPrimaryKeyElement.getName());
1189: }
1190: }
1191: }
1192: }
1193:
1194: // Helper. Puts all associations in the target model
1195: private static void convertEntitySelectors(
1196: ConversionContext pConversionContext)
1197: throws ModelRepositoryException {
1198: Collection lSelectors = pConversionContext.mMetaBossModelExtent
1199: .getEnterpriseModel().getSystemImplementationModel()
1200: .getSelector().refAllOfClass();
1201: // Do not set inheritance on the first run because supertype may not be defined yet
1202: org.omg.uml.foundation.core.UmlClass lCurrentUmlEntity = null;
1203: Entity lCurrentEntity = null;
1204: for (Iterator lSelectorsIterator = lSelectors.iterator(); lSelectorsIterator
1205: .hasNext();) {
1206: Selector lSelector = (Selector) lSelectorsIterator.next();
1207: Entity lEntity = lSelector.getEntity();
1208: if (lCurrentEntity == null
1209: || lCurrentEntity.equals(lEntity) == false) {
1210: // Now set the new currents
1211: lCurrentEntity = lEntity;
1212: lCurrentUmlEntity = UMLUtils.getUmlClass(
1213: pConversionContext.mTargetModelName, lEntity,
1214: UMLStylesheet.getEntityXPath(lEntity));
1215: }
1216: org.omg.uml.foundation.core.Operation lUmlSelector = pConversionContext.mUMLModelExtent
1217: .getCore().getOperation().createOperation();
1218: lUmlSelector.setName(lSelector.getName());
1219: lUmlSelector.setOwner(lCurrentUmlEntity);
1220: lUmlSelector.setQuery(true);
1221: lUmlSelector
1222: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1223: UMLUtils.copyComment(lSelector, lUmlSelector);
1224: lUmlSelector
1225: .getStereotype()
1226: .add(
1227: pConversionContext.mMetaBossProfile.mSelectorStereotype);
1228: UMLUtils
1229: .attachSingleTagToElement(
1230: lUmlSelector,
1231: pConversionContext.mMetaBossProfile.mSelectorTagDefinition_Cardinality,
1232: lSelector.getCardinality().toString());
1233: UMLUtils
1234: .attachSingleTagToElement(
1235: lUmlSelector,
1236: pConversionContext.mMetaBossProfile.mSelectorTagDefinition_DefaultSQLQuery,
1237: lSelector.getTextOfSqlSelect() != null ? lSelector
1238: .getTextOfSqlSelect()
1239: : "");
1240: UMLUtils
1241: .attachSingleTagToElement(
1242: lUmlSelector,
1243: pConversionContext.mMetaBossProfile.mSelectorTagDefinition_Derived,
1244: lSelector.isImplicit() ? "true" : "false");
1245: // Add input parameters
1246: Collection lUmlSelectorParameters = lUmlSelector
1247: .getParameter();
1248: // Convert input fields
1249: for (Iterator lInputFieldsIterator = lSelector
1250: .getInputFields().iterator(); lInputFieldsIterator
1251: .hasNext();) {
1252: SelectorInputField lInputField = (SelectorInputField) lInputFieldsIterator
1253: .next();
1254: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
1255: .getCore().getParameter().createParameter();
1256: lUmlSelectorParameters.add(lParameter);
1257: lParameter.setName(lInputField.getName());
1258: lParameter
1259: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1260: lParameter
1261: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
1262: UMLUtils.copyComment(lInputField, lParameter);
1263: UMLUtils
1264: .attachSingleTagToElement(
1265: lParameter,
1266: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
1267: Boolean.toString(lInputField.isArray()));
1268: DataType lDataType = lInputField.getDataType();
1269: if (lDataType != null)
1270: lParameter.setType(pConversionContext
1271: .getUmlDataType(lDataType));
1272: }
1273: }
1274: }
1275:
1276: // Helper. Puts all datatypes in the target model
1277: private static void convertDatatypes(
1278: ConversionContext pConversionContext,
1279: Collection pSourceDatatypes)
1280: throws ModelRepositoryException {
1281: org.omg.uml.modelmanagement.UmlPackage lCurrentNamespacePackage = null;
1282: AbstractNamespace lCurrentNamespace = null;
1283: for (Iterator lDataTypesIterator = pSourceDatatypes.iterator(); lDataTypesIterator
1284: .hasNext();) {
1285: DataType lDataType = (DataType) lDataTypesIterator.next();
1286: AbstractNamespace lDataTypeNamespace = lDataType
1287: .getNamespace();
1288: if (lCurrentNamespace == null
1289: || lCurrentNamespace.equals(lDataTypeNamespace) == false) {
1290: // Now set the new currents
1291: lCurrentNamespace = lDataTypeNamespace;
1292: lCurrentNamespacePackage = pConversionContext
1293: .getUmlNamespace(lDataTypeNamespace);
1294: }
1295: // Now add template to the package
1296: org.omg.uml.foundation.core.DataType lUmlDataType = pConversionContext.mUMLModelExtent
1297: .getCore().getDataType().createDataType();
1298: lUmlDataType.setName(lDataType.getName());
1299: UMLUtils.copyComment(lDataType, lUmlDataType);
1300: lUmlDataType.setNamespace(lCurrentNamespacePackage);
1301: // Work on binding of the data type to the type template if it is a templated data type
1302: TypeTemplate lTypetemplate = lDataType.getTypetemplate();
1303: if (lTypetemplate != null) {
1304: org.omg.uml.foundation.core.UmlClass lUmlTypetemplate = pConversionContext
1305: .getUmlTypetemplate(lTypetemplate);
1306: org.omg.uml.foundation.core.Binding lUmlBinding = pConversionContext.mUMLModelExtent
1307: .getCore().getBinding().createBinding();
1308: lUmlBinding.getSupplier().add(lUmlTypetemplate);
1309: lUmlBinding.getClient().add(lUmlDataType);
1310: lUmlBinding.setNamespace(lUmlDataType);
1311: // Now add template properties in the loop
1312: addTypetemplateProperties(pConversionContext,
1313: lUmlDataType, lUmlBinding, lDataType);
1314: }
1315: // Cache newly created datatype
1316: pConversionContext.mUmlElementsMap.put(lDataType,
1317: lUmlDataType);
1318: }
1319: }
1320:
1321: // Helper. Adds TypetemplatePropertyDescriptors to the model element
1322: private static void addTypetemplateProperties(
1323: ConversionContext pConversionContext,
1324: org.omg.uml.foundation.core.DataType pTargetDataType,
1325: org.omg.uml.foundation.core.Binding pTargetBinding,
1326: DataType pSourceDataType) throws ModelRepositoryException {
1327: org.omg.uml.foundation.core.TemplateArgumentClass lTemplateArgumentClass = pConversionContext.mUMLModelExtent
1328: .getCore().getTemplateArgument();
1329: org.omg.uml.foundation.core.ParameterClass lParameterClass = pConversionContext.mUMLModelExtent
1330: .getCore().getParameter();
1331: org.omg.uml.behavioralelements.commonbehavior.DataValueClass lDataValueClass = pConversionContext.mUMLModelExtent
1332: .getCommonBehavior().getDataValue();
1333: for (Iterator lPropertiesIter = pSourceDataType
1334: .getCombinedTypetemplateProperties().iterator(); lPropertiesIter
1335: .hasNext();) {
1336: Property lProperty = (Property) lPropertiesIter.next();
1337:
1338: // Create new Template parameter
1339: org.omg.uml.foundation.core.TemplateArgument lUmlTemplateArgument = lTemplateArgumentClass
1340: .createTemplateArgument();
1341: lUmlTemplateArgument.setBinding(pTargetBinding);
1342:
1343: // Create Uml DataValue and package it in the TemplateParameter
1344: org.omg.uml.behavioralelements.commonbehavior.DataValue lUmlDataValue = lDataValueClass
1345: .createDataValue();
1346: lUmlDataValue.setNamespace(pTargetDataType);
1347: lUmlTemplateArgument.setModelElement(lUmlDataValue);
1348: lUmlDataValue.setName(lProperty.getKey());
1349: lUmlDataValue
1350: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1351: lUmlDataValue
1352: .getStereotype()
1353: .add(
1354: pConversionContext.mMetaBossProfile.mGenericArgumentStereotype);
1355: if (lProperty.getValue() != null)
1356: UMLUtils
1357: .attachSingleTagToElement(
1358: lUmlDataValue,
1359: pConversionContext.mMetaBossProfile.mGenericArgumentTagDefinition_Value,
1360: lProperty.getValue());
1361: UMLUtils.copyComment(lProperty, lUmlDataValue);
1362: }
1363: }
1364:
1365: // Helper. Converts all servicemodules from MetaBoss model to UML model
1366: private static void convertServicemodules(
1367: ConversionContext pConversionContext)
1368: throws ModelRepositoryException {
1369: Collection lAllServicemodules = pConversionContext.mMetaBossModelExtent
1370: .getEnterpriseModel().getServicemodule()
1371: .refAllOfClass();
1372: // At the first run put all packages
1373: org.omg.uml.modelmanagement.UmlPackage lCurrentSystemServicemodulesPackage = null;
1374: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lCurrentSystem = null;
1375: for (Iterator lServicemodulesIterator = lAllServicemodules
1376: .iterator(); lServicemodulesIterator.hasNext();) {
1377: Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
1378: .next();
1379: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lServicemodule
1380: .getSystem();
1381: if (lCurrentSystem == null
1382: || lCurrentSystem.equals(lSystem) == false) {
1383: // Now set the new currents
1384: lCurrentSystem = lSystem;
1385: lCurrentSystemServicemodulesPackage = UMLUtils
1386: .getUmlPackage(
1387: pConversionContext.mTargetModelName,
1388: lSystem,
1389: UMLStylesheet
1390: .getSystemServicemodulesXPath(lSystem));
1391: }
1392: org.omg.uml.modelmanagement.UmlPackage lServicemoduleUmlPackage = pConversionContext.mUMLModelExtent
1393: .getModelManagement().getUmlPackage()
1394: .createUmlPackage();
1395: lServicemoduleUmlPackage.setName(lServicemodule.getName());
1396: lServicemoduleUmlPackage
1397: .setNamespace(lCurrentSystemServicemodulesPackage);
1398: lServicemoduleUmlPackage
1399: .getStereotype()
1400: .add(
1401: pConversionContext.mMetaBossProfile.mServicemodulePackageStereotype);
1402: UMLUtils.copyComment(lServicemodule,
1403: lServicemoduleUmlPackage);
1404:
1405: org.omg.uml.modelmanagement.UmlPackage lServicemoduleMessagesPackage = pConversionContext.mUMLModelExtent
1406: .getModelManagement().getUmlPackage()
1407: .createUmlPackage();
1408: lServicemoduleMessagesPackage
1409: .setName(UMLStylesheet.mServicemoduleMessagesPackageName);
1410: lServicemoduleMessagesPackage
1411: .setNamespace(lServicemoduleUmlPackage);
1412:
1413: org.omg.uml.modelmanagement.UmlPackage lServicemoduleStructuresPackage = pConversionContext.mUMLModelExtent
1414: .getModelManagement().getUmlPackage()
1415: .createUmlPackage();
1416: lServicemoduleStructuresPackage
1417: .setName(UMLStylesheet.mServicemoduleStructuresPackageName);
1418: lServicemoduleStructuresPackage
1419: .setNamespace(lServicemoduleUmlPackage);
1420:
1421: org.omg.uml.modelmanagement.UmlPackage lServicemoduleServicesPackage = pConversionContext.mUMLModelExtent
1422: .getModelManagement().getUmlPackage()
1423: .createUmlPackage();
1424: lServicemoduleServicesPackage
1425: .setName(UMLStylesheet.mServicemoduleServicesPackageName);
1426: lServicemoduleServicesPackage
1427: .setNamespace(lServicemoduleUmlPackage);
1428:
1429: org.omg.uml.modelmanagement.UmlPackage lServicemoduleEventSubscriptionsPackage = pConversionContext.mUMLModelExtent
1430: .getModelManagement().getUmlPackage()
1431: .createUmlPackage();
1432: lServicemoduleEventSubscriptionsPackage
1433: .setName(UMLStylesheet.mServicemoduleEventSubscriptionsPackageName);
1434: lServicemoduleEventSubscriptionsPackage
1435: .setNamespace(lServicemoduleUmlPackage);
1436:
1437: // And structures
1438: convertStructures(pConversionContext, lServicemodule
1439: .getStructures());
1440: }
1441: // After all shells for servicemodules have been created - time to convert messages
1442: convertMessages(pConversionContext);
1443:
1444: // After all structures are created structure fields should be added as a separate step
1445: // note that adding fields will not work together with adding structures because
1446: // field can refer to another, as yet undefined, structure
1447: for (Iterator lServicemodulesIterator = lAllServicemodules
1448: .iterator(); lServicemodulesIterator.hasNext();) {
1449: Servicemodule lServicemodule = (Servicemodule) lServicemodulesIterator
1450: .next();
1451: for (Iterator lStructuresIterator = lServicemodule
1452: .getStructures().iterator(); lStructuresIterator
1453: .hasNext();) {
1454: Structure lStructure = (Structure) lStructuresIterator
1455: .next();
1456: convertStructureFields(pConversionContext, lStructure
1457: .getFields());
1458: }
1459: }
1460: // And now services and event subscriptions
1461: convertServices(pConversionContext);
1462: convertEventSubscriptions(pConversionContext);
1463: }
1464:
1465: // Helper. Converts all messages from MetaBoss model to UML model
1466: private static void convertMessages(
1467: ConversionContext pConversionContext)
1468: throws ModelRepositoryException {
1469: Collection lAllMessages = pConversionContext.mMetaBossModelExtent
1470: .getEnterpriseModel().getMessage().refAllOfClass();
1471: // At the first run put all packages
1472: org.omg.uml.modelmanagement.UmlPackage lUmlMessagesPackage = null;
1473: ModelElement lCurrentContainerElement = null;
1474: for (Iterator lMessagesIterator = lAllMessages.iterator(); lMessagesIterator
1475: .hasNext();) {
1476: Message lMessage = (Message) lMessagesIterator.next();
1477: Servicemodule lServicemodule = lMessage.getServicemodule();
1478: AbstractNamespace lNamespace = lMessage.getNamespace();
1479: if (lServicemodule != null) {
1480: if (lCurrentContainerElement == null
1481: || lCurrentContainerElement
1482: .equals(lServicemodule) == false) {
1483: // Now set the new current servicemodule
1484: lCurrentContainerElement = lServicemodule;
1485: lUmlMessagesPackage = UMLUtils
1486: .getUmlPackage(
1487: pConversionContext.mTargetModelName,
1488: lServicemodule,
1489: UMLStylesheet
1490: .getServicemoduleMessagesXPath(lServicemodule));
1491: }
1492: } else if (lNamespace != null) {
1493: if (lCurrentContainerElement == null
1494: || lCurrentContainerElement.equals(lNamespace) == false) {
1495: // Now set the new current servicemodule
1496: lCurrentContainerElement = lNamespace;
1497: lUmlMessagesPackage = pConversionContext
1498: .getUmlNamespace(lNamespace);
1499: }
1500: } else
1501: throw new ModelRepositoryException(
1502: "Message must be contained inside Servicemodule or Namespace. MessageRef: "
1503: + lMessage.getRef());
1504: org.omg.uml.foundation.core.UmlClass lMessageUmlClass = pConversionContext.mUMLModelExtent
1505: .getCore().getUmlClass().createUmlClass();
1506: lMessageUmlClass.setName(lMessage.getName());
1507: lMessageUmlClass.setNamespace(lUmlMessagesPackage);
1508: lMessageUmlClass
1509: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1510: lMessageUmlClass
1511: .getStereotype()
1512: .add(
1513: pConversionContext.mMetaBossProfile.mServicemoduleMessageStereotype);
1514: // Set derived flag if this message is owned by any of the assistants
1515: if (lMessage.isDerived())
1516: UMLUtils
1517: .attachSingleTagToElement(
1518: lMessageUmlClass,
1519: pConversionContext.mMetaBossProfile.mServicemoduleMessageTagDefinition_Derived,
1520: Boolean.toString(true));
1521:
1522: // Work on default text tag definition
1523: {
1524: org.omg.uml.foundation.core.TaggedValue lTaggedValue = pConversionContext.mUMLModelExtent
1525: .getCore().getTaggedValue().createTaggedValue();
1526: lTaggedValue
1527: .setType(pConversionContext.mMetaBossProfile.mServicemoduleMessageTagDefinition_DefaultText);
1528: lTaggedValue
1529: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1530: lTaggedValue.setModelElement(lMessageUmlClass);
1531: lTaggedValue.getDataValue().add(
1532: lMessage.getDefaultText());
1533: }
1534: // Work on type tag definition
1535: {
1536: org.omg.uml.foundation.core.TaggedValue lTaggedValue = pConversionContext.mUMLModelExtent
1537: .getCore().getTaggedValue().createTaggedValue();
1538: lTaggedValue
1539: .setType(pConversionContext.mMetaBossProfile.mServicemoduleMessageTagDefinition_Type);
1540: lTaggedValue
1541: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1542: lTaggedValue.setModelElement(lMessageUmlClass);
1543: lTaggedValue.getDataValue().add(
1544: lMessage.getType().toString());
1545: }
1546:
1547: UMLUtils.copyComment(lMessage, lMessageUmlClass);
1548:
1549: Collection lMessageClassFeatures = lMessageUmlClass
1550: .getFeature();
1551: for (Iterator lMessageFieldsIterator = lMessage.getFields()
1552: .iterator(); lMessageFieldsIterator.hasNext();) {
1553: MessageField lMessageField = (MessageField) lMessageFieldsIterator
1554: .next();
1555: org.omg.uml.foundation.core.Attribute lFieldAttribute = pConversionContext.mUMLModelExtent
1556: .getCore().getAttribute().createAttribute();
1557: lMessageClassFeatures.add(lFieldAttribute);
1558: lFieldAttribute.setName(lMessageField.getName());
1559: lFieldAttribute
1560: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1561: lFieldAttribute.setType(pConversionContext
1562: .getUmlDataType(lMessageField.getDataType()));
1563: UMLUtils.copyComment(lMessageField, lFieldAttribute);
1564: }
1565: }
1566: }
1567:
1568: // Helper. Converts all structures from MetaBoss model to UML model
1569: private static void convertStructures(
1570: ConversionContext pConversionContext, Collection pStructures)
1571: throws ModelRepositoryException {
1572: // At the first run put all packages
1573: org.omg.uml.modelmanagement.UmlPackage lUmlStructuresPackage = null;
1574: ModelElement lCurrentContainerElement = null;
1575: for (Iterator lStructuresIterator = pStructures.iterator(); lStructuresIterator
1576: .hasNext();) {
1577: Structure lStructure = (Structure) lStructuresIterator
1578: .next();
1579: Servicemodule lServicemodule = lStructure
1580: .getServicemodule();
1581: AbstractNamespace lNamespace = lStructure.getNamespace();
1582: if (lServicemodule != null) {
1583: if (lCurrentContainerElement == null
1584: || lCurrentContainerElement
1585: .equals(lServicemodule) == false) {
1586: // Now set the new current servicemodule
1587: lCurrentContainerElement = lServicemodule;
1588: lUmlStructuresPackage = UMLUtils
1589: .getUmlPackage(
1590: pConversionContext.mTargetModelName,
1591: lServicemodule,
1592: UMLStylesheet
1593: .getServicemoduleStructuresXPath(lServicemodule));
1594: }
1595: } else if (lNamespace != null) {
1596: if (lCurrentContainerElement == null
1597: || lCurrentContainerElement.equals(lNamespace) == false) {
1598: // Now set the new current servicemodule
1599: lCurrentContainerElement = lNamespace;
1600: lUmlStructuresPackage = pConversionContext
1601: .getUmlNamespace(lNamespace);
1602: }
1603: } else
1604: throw new ModelRepositoryException(
1605: "Structure must be contained inside Servicemodule or Namespace. StructureRef: "
1606: + lStructure.getRef());
1607: org.omg.uml.foundation.core.UmlClass lStructureClass = pConversionContext.mUMLModelExtent
1608: .getCore().getUmlClass().createUmlClass();
1609: lStructureClass.setName(lStructure.getName());
1610: lStructureClass.setNamespace(lUmlStructuresPackage);
1611: lStructureClass
1612: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1613: lStructureClass
1614: .getStereotype()
1615: .add(
1616: pConversionContext.mMetaBossProfile.mServicemoduleStructureStereotype);
1617: UMLUtils.copyComment(lStructure, lStructureClass);
1618: Collection lConstraints = lStructure.getConstraints();
1619: if (!lConstraints.isEmpty()) {
1620: String lStructureName = lStructure.getName();
1621: String lContextName = lStructureName.substring(0, 1)
1622: .toUpperCase()
1623: + lStructureName.substring(1);
1624: String lConstraintStringStart = "context "
1625: + lContextName + " inv : ";
1626: convertConstraints(pConversionContext, lConstraints,
1627: lStructureClass, lConstraintStringStart);
1628: }
1629: // Cache newly created structure
1630: pConversionContext.mUmlElementsMap.put(lStructure,
1631: lStructureClass);
1632: }
1633: }
1634:
1635: // Helper. Converts supplied collection of the MetaBoss constraints into UML model
1636: private static void convertConstraints(
1637: ConversionContext pConversionContext,
1638: Collection pMetaBossConstraints,
1639: org.omg.uml.foundation.core.ModelElement pTargetContextElement,
1640: String pConstraintStringStart)
1641: throws ModelRepositoryException {
1642: Collection lTargetUMLConstraints = pTargetContextElement
1643: .getConstraint();
1644: // Establish which stereotype shoud we use
1645: org.omg.uml.foundation.core.Stereotype lUMLConstraintStereotype = null;
1646: if (pConstraintStringStart.trim().endsWith("pre :"))
1647: lUMLConstraintStereotype = pConversionContext.mOCLPreconditionStereotype;
1648: else if (pConstraintStringStart.trim().endsWith("inv :"))
1649: lUMLConstraintStereotype = pConversionContext.mOCLInvariantStereotype;
1650:
1651: for (Iterator lConstraintsIterator = pMetaBossConstraints
1652: .iterator(); lConstraintsIterator.hasNext();) {
1653: ModelElementConstraint lConstraint = (ModelElementConstraint) lConstraintsIterator
1654: .next();
1655: org.omg.uml.foundation.core.Constraint lUMLConstraint = pConversionContext.mUMLModelExtent
1656: .getCore().getConstraint().createConstraint();
1657: lUMLConstraint.setName(lConstraint.getName());
1658: lUMLConstraint.setNamespace(pTargetContextElement
1659: .getNamespace());
1660: lUMLConstraint
1661: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1662: UMLUtils.copyComment(lConstraint, lUMLConstraint);
1663: org.omg.uml.foundation.datatypes.BooleanExpression lConstraintExpression = pConversionContext.mUMLModelExtent
1664: .getDataTypes().getBooleanExpression()
1665: .createBooleanExpression();
1666: lConstraintExpression.setLanguage("OCL");
1667: lConstraintExpression.setBody(pConstraintStringStart
1668: + lConstraint.getOclExpression());
1669: lUMLConstraint.setBody(lConstraintExpression);
1670: UMLUtils
1671: .attachSingleTagToElement(
1672: lUMLConstraint,
1673: pConversionContext.mMetaBossProfile.mConstraintTagDefinition_DefaultErrorText,
1674: lConstraint.getDefaultErrorText());
1675: Collection lConstraintStereotypes = lUMLConstraint
1676: .getStereotype();
1677: lConstraintStereotypes
1678: .add(pConversionContext.mMetaBossProfile.mConstraintStereotype);
1679: if (lUMLConstraintStereotype != null)
1680: lUMLConstraint.getStereotype().add(
1681: lUMLConstraintStereotype);
1682: lTargetUMLConstraints.add(lUMLConstraint);
1683: }
1684: }
1685:
1686: // Helper. Converts all structure fields from MetaBoss model to UML model
1687: private static void convertStructureFields(
1688: ConversionContext pConversionContext,
1689: Collection pStructureFields)
1690: throws ModelRepositoryException {
1691: // At the first run put all packages
1692: org.omg.uml.foundation.core.UmlClass lCurrentStructureClass = null;
1693: Structure lCurrentStructure = null;
1694: Collection lCurrentStructureClassFeatures = null;
1695: for (Iterator lStructureFieldsIterator = pStructureFields
1696: .iterator(); lStructureFieldsIterator.hasNext();) {
1697: StructureField lStructureField = (StructureField) lStructureFieldsIterator
1698: .next();
1699: Structure lStructure = lStructureField.getOwnerStructure();
1700: if (lCurrentStructure == null
1701: || lCurrentStructure.equals(lStructure) == false) {
1702: // Now set the new currents
1703: lCurrentStructure = lStructure;
1704: lCurrentStructureClass = pConversionContext
1705: .getUmlStructure(lStructure);
1706: lCurrentStructureClassFeatures = lCurrentStructureClass
1707: .getFeature();
1708: }
1709: org.omg.uml.foundation.core.Attribute lStructureAttribute = pConversionContext.mUMLModelExtent
1710: .getCore().getAttribute().createAttribute();
1711: lCurrentStructureClassFeatures.add(lStructureAttribute);
1712: lStructureAttribute.setName(lStructureField.getName());
1713: lStructureAttribute
1714: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1715: lStructureAttribute.setMultiplicity(UMLUtils
1716: .createMultiplicityInstance(
1717: pConversionContext.mUMLModelExtent, 0,
1718: lStructureField.isArray() ? -1 : 1));
1719: Structure lStructureType = lStructureField
1720: .getStructureType();
1721: DataType lDataType = lStructureField.getDataType();
1722: if (lStructureType != null)
1723: lStructureAttribute.setType(pConversionContext
1724: .getUmlStructure(lStructureType));
1725: else if (lDataType != null)
1726: lStructureAttribute.setType(pConversionContext
1727: .getUmlDataType(lDataType));
1728: UMLUtils.copyComment(lStructureField, lStructureAttribute);
1729: }
1730: }
1731:
1732: // Helper. Converts all Services from MetaBoss model to UML model
1733: private static void convertServices(
1734: ConversionContext pConversionContext)
1735: throws ModelRepositoryException {
1736: Collection lAllServices = pConversionContext.mMetaBossModelExtent
1737: .getEnterpriseModel().getService().refAllOfClass();
1738: // At the first run put all packages
1739: org.omg.uml.modelmanagement.UmlPackage lCurrentServicemoduleServicesPackage = null;
1740: Servicemodule lCurrentServicemodule = null;
1741: for (Iterator lServicesIterator = lAllServices.iterator(); lServicesIterator
1742: .hasNext();) {
1743: Service lService = (Service) lServicesIterator.next();
1744: Servicemodule lServicemodule = lService.getServicemodule();
1745: if (lCurrentServicemodule == null
1746: || lCurrentServicemodule.equals(lServicemodule) == false) {
1747: // Now set the new currents
1748: lCurrentServicemodule = lServicemodule;
1749: lCurrentServicemoduleServicesPackage = UMLUtils
1750: .getUmlPackage(
1751: pConversionContext.mTargetModelName,
1752: lServicemodule,
1753: UMLStylesheet
1754: .getServicemoduleServicesXPath(lServicemodule));
1755: }
1756: org.omg.uml.foundation.core.UmlClass lServiceUmlElement = pConversionContext.mUMLModelExtent
1757: .getCore().getUmlClass().createUmlClass();
1758: lServiceUmlElement.setName(lService.getName());
1759: lServiceUmlElement
1760: .setNamespace(lCurrentServicemoduleServicesPackage);
1761: lServiceUmlElement
1762: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1763: lServiceUmlElement
1764: .getStereotype()
1765: .add(
1766: pConversionContext.mMetaBossProfile.mServicemoduleServiceStereotype);
1767: UMLUtils.copyComment(lService, lServiceUmlElement);
1768: for (Iterator lOperationsIterator = lService
1769: .getOperations().iterator(); lOperationsIterator
1770: .hasNext();) {
1771: Operation lOperation = (Operation) lOperationsIterator
1772: .next();
1773: org.omg.uml.foundation.core.Operation lUMLOperation = pConversionContext.mUMLModelExtent
1774: .getCore().getOperation().createOperation();
1775: lUMLOperation.setName(lOperation.getName());
1776: lUMLOperation.setQuery(lOperation.isQuery());
1777: lUMLOperation
1778: .setOwnerScope(org.omg.uml.foundation.datatypes.ScopeKindEnum.SK_INSTANCE);
1779: lUMLOperation
1780: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1781: lUMLOperation.setOwner(lServiceUmlElement);
1782: lUMLOperation
1783: .getStereotype()
1784: .add(
1785: pConversionContext.mMetaBossProfile.mServiceOperationStereotype);
1786: UMLUtils.copyComment(lOperation, lUMLOperation);
1787: // Work on transaction policy definition
1788: {
1789: org.omg.uml.foundation.core.TaggedValue lTaggedValue = pConversionContext.mUMLModelExtent
1790: .getCore().getTaggedValue()
1791: .createTaggedValue();
1792: lTaggedValue
1793: .setType(pConversionContext.mMetaBossProfile.mServiceOperationTagDefinition_TransactionPolicy);
1794: lTaggedValue
1795: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1796: lTaggedValue.setModelElement(lUMLOperation);
1797: lTaggedValue.getDataValue().add(
1798: lOperation.getTransactionPolicy()
1799: .toString());
1800: }
1801: // Copy all operation contents
1802: copyAbstractOperationContents(lService.getName(),
1803: lUMLOperation, lOperation, pConversionContext);
1804: }
1805: }
1806: }
1807:
1808: // Helper. Converts all Services from MetaBoss model to UML model
1809: private static void convertEventSubscriptions(
1810: ConversionContext pConversionContext)
1811: throws ModelRepositoryException {
1812: Collection lAllEventSubscriptions = pConversionContext.mMetaBossModelExtent
1813: .getEnterpriseModel().getEventSubscription()
1814: .refAllOfClass();
1815: // At the first run put all packages
1816: org.omg.uml.modelmanagement.UmlPackage lCurrentServicemoduleEventSubscriptionsPackage = null;
1817: Servicemodule lCurrentServicemodule = null;
1818: for (Iterator lEventSubscriptionsIterator = lAllEventSubscriptions
1819: .iterator(); lEventSubscriptionsIterator.hasNext();) {
1820: EventSubscription lEventSubscription = (EventSubscription) lEventSubscriptionsIterator
1821: .next();
1822: Servicemodule lServicemodule = lEventSubscription
1823: .getServicemodule();
1824: if (lCurrentServicemodule == null
1825: || lCurrentServicemodule.equals(lServicemodule) == false) {
1826: // Now set the new currents
1827: lCurrentServicemodule = lServicemodule;
1828: lCurrentServicemoduleEventSubscriptionsPackage = UMLUtils
1829: .getUmlPackage(
1830: pConversionContext.mTargetModelName,
1831: lServicemodule,
1832: UMLStylesheet
1833: .getServicemoduleEventSubscriptionsXPath(lServicemodule));
1834: }
1835: org.omg.uml.foundation.core.UmlClass lEventSubscriptionUmlElement = pConversionContext.mUMLModelExtent
1836: .getCore().getUmlClass().createUmlClass();
1837: lEventSubscriptionUmlElement.setName(lEventSubscription
1838: .getName());
1839: lEventSubscriptionUmlElement
1840: .setNamespace(lCurrentServicemoduleEventSubscriptionsPackage);
1841: lEventSubscriptionUmlElement
1842: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1843: lEventSubscriptionUmlElement
1844: .getStereotype()
1845: .add(
1846: pConversionContext.mMetaBossProfile.mServicemoduleEventSubscriptionStereotype);
1847: UMLUtils.copyComment(lEventSubscription,
1848: lEventSubscriptionUmlElement);
1849: // Work on synchronisation event
1850: Event lSynchronisationEvent = lEventSubscription
1851: .getSynchronisationEvent();
1852: if (lSynchronisationEvent != null)
1853: UMLUtils
1854: .attachSingleTagToElement(
1855: lEventSubscriptionUmlElement,
1856: pConversionContext.mMetaBossProfile.mEventSubscriptionStereotypeTagDefinition_SynchronisationEventName,
1857: lSynchronisationEvent.getName());
1858: // Work on the subscription operation
1859: EventSubscriptionOperation lEventSubscriptionOperation = lEventSubscription
1860: .getSubscriptionOperation();
1861: org.omg.uml.foundation.core.Operation lUMLOperation = pConversionContext.mUMLModelExtent
1862: .getCore().getOperation().createOperation();
1863: lUMLOperation.setName("Subscribe");
1864: lUMLOperation.setQuery(false);
1865: lUMLOperation
1866: .setOwnerScope(org.omg.uml.foundation.datatypes.ScopeKindEnum.SK_INSTANCE);
1867: lUMLOperation
1868: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1869: lUMLOperation.setOwner(lEventSubscriptionUmlElement);
1870: lUMLOperation
1871: .getStereotype()
1872: .add(
1873: pConversionContext.mMetaBossProfile.mEventSubscriptionOperationStereotype);
1874: UMLUtils.copyComment(lEventSubscriptionOperation,
1875: lUMLOperation);
1876: // Copy all operation contents
1877: copyAbstractOperationContents(lEventSubscription.getName(),
1878: lUMLOperation, lEventSubscriptionOperation,
1879: pConversionContext);
1880: // Now add all operations which represent events
1881: for (Iterator lEventsIterator = lEventSubscription
1882: .getEvents().iterator(); lEventsIterator.hasNext();) {
1883: Event lEvent = (Event) lEventsIterator.next();
1884: org.omg.uml.foundation.core.Operation lUMLEvent = pConversionContext.mUMLModelExtent
1885: .getCore().getOperation().createOperation();
1886: lUMLEvent.setName(lEvent.getName());
1887: lUMLEvent.setQuery(false);
1888: lUMLEvent
1889: .setOwnerScope(org.omg.uml.foundation.datatypes.ScopeKindEnum.SK_INSTANCE);
1890: lUMLEvent
1891: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1892: lUMLEvent.setOwner(lEventSubscriptionUmlElement);
1893: lUMLEvent
1894: .getStereotype()
1895: .add(
1896: pConversionContext.mMetaBossProfile.mEventSubscriptionEventStereotype);
1897: UMLUtils.copyComment(lEvent, lUMLEvent);
1898: // Work on event data and message fields
1899: Collection lUMLOperationParameters = lUMLEvent
1900: .getParameter();
1901: // Convert data fields
1902: for (Iterator lDataFieldsIterator = lEvent
1903: .getDataFields().iterator(); lDataFieldsIterator
1904: .hasNext();) {
1905: EventDataField lDataField = (EventDataField) lDataFieldsIterator
1906: .next();
1907: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
1908: .getCore().getParameter().createParameter();
1909: lUMLOperationParameters.add(lParameter);
1910: lParameter.setName(lDataField.getName());
1911: lParameter
1912: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1913: lParameter
1914: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
1915: lParameter
1916: .getStereotype()
1917: .add(
1918: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
1919: UMLUtils.copyComment(lDataField, lParameter);
1920: UMLUtils
1921: .attachSingleTagToElement(
1922: lParameter,
1923: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
1924: Boolean.toString(lDataField
1925: .isArray()));
1926: Structure lStructureType = lDataField
1927: .getStructureType();
1928: DataType lDataType = lDataField.getDataType();
1929: if (lStructureType != null)
1930: lParameter.setType(pConversionContext
1931: .getUmlStructure(lStructureType));
1932: else if (lDataType != null)
1933: lParameter.setType(pConversionContext
1934: .getUmlDataType(lDataType));
1935: }
1936: // Convert message fields
1937: for (Iterator lMessageFieldsIterator = lEvent
1938: .getMessageFields().iterator(); lMessageFieldsIterator
1939: .hasNext();) {
1940: EventMessageField lMessageField = (EventMessageField) lMessageFieldsIterator
1941: .next();
1942: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
1943: .getCore().getParameter().createParameter();
1944: lUMLOperationParameters.add(lParameter);
1945: lParameter.setName(lMessageField.getName());
1946: lParameter
1947: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
1948: lParameter
1949: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
1950: lParameter
1951: .getStereotype()
1952: .add(
1953: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
1954: UMLUtils.copyComment(lMessageField, lParameter);
1955: UMLUtils
1956: .attachSingleTagToElement(
1957: lParameter,
1958: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
1959: Boolean.toString(lMessageField
1960: .isArray()));
1961: Message lMessageType = lMessageField
1962: .getMessageType();
1963: if (lMessageType != null)
1964: lParameter
1965: .setType(UMLUtils
1966: .getUmlClass(
1967: pConversionContext.mTargetModelName,
1968: lMessageType,
1969: UMLStylesheet
1970: .getMessageXPath(lMessageType)));
1971: if (lMessageField.isDerived())
1972: UMLUtils
1973: .attachSingleTagToElement(
1974: lParameter,
1975: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_Derived,
1976: Boolean.toString(true));
1977: }
1978: }
1979: }
1980: }
1981:
1982: // Converts contents of the abstract operation
1983: private static void copyAbstractOperationContents(
1984: String pParentName,
1985: org.omg.uml.foundation.core.Operation pUMLOperation,
1986: AbstractOperation pOperation,
1987: ConversionContext pConversionContext)
1988: throws ModelRepositoryException {
1989: Collection lUMLOperationParameters = pUMLOperation
1990: .getParameter();
1991: // Convert input fields
1992: for (Iterator lInputFieldsIterator = pOperation
1993: .getInputFields().iterator(); lInputFieldsIterator
1994: .hasNext();) {
1995: OperationInputField lInputField = (OperationInputField) lInputFieldsIterator
1996: .next();
1997: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
1998: .getCore().getParameter().createParameter();
1999: lUMLOperationParameters.add(lParameter);
2000: lParameter.setName(lInputField.getName());
2001: lParameter
2002: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
2003: lParameter
2004: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_IN);
2005: lParameter
2006: .getStereotype()
2007: .add(
2008: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
2009: UMLUtils.copyComment(lInputField, lParameter);
2010: UMLUtils
2011: .attachSingleTagToElement(
2012: lParameter,
2013: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
2014: Boolean.toString(lInputField.isArray()));
2015: Structure lStructureType = lInputField.getStructureType();
2016: DataType lDataType = lInputField.getDataType();
2017: if (lStructureType != null)
2018: lParameter.setType(pConversionContext
2019: .getUmlStructure(lStructureType));
2020: else if (lDataType != null)
2021: lParameter.setType(pConversionContext
2022: .getUmlDataType(lDataType));
2023: }
2024: // Convert output fields
2025: for (Iterator lOutputFieldsIterator = pOperation
2026: .getOutputFields().iterator(); lOutputFieldsIterator
2027: .hasNext();) {
2028: OperationOutputField lOutputField = (OperationOutputField) lOutputFieldsIterator
2029: .next();
2030: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
2031: .getCore().getParameter().createParameter();
2032: lUMLOperationParameters.add(lParameter);
2033: lParameter.setName(lOutputField.getName());
2034: lParameter
2035: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
2036: lParameter
2037: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_RETURN);
2038: lParameter
2039: .getStereotype()
2040: .add(
2041: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
2042: UMLUtils.copyComment(lOutputField, lParameter);
2043: UMLUtils
2044: .attachSingleTagToElement(
2045: lParameter,
2046: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
2047: Boolean.toString(lOutputField.isArray()));
2048: Structure lStructureType = lOutputField.getStructureType();
2049: DataType lDataType = lOutputField.getDataType();
2050: if (lStructureType != null)
2051: lParameter.setType(pConversionContext
2052: .getUmlStructure(lStructureType));
2053: else if (lDataType != null)
2054: lParameter.setType(pConversionContext
2055: .getUmlDataType(lDataType));
2056: }
2057: // Convert output messages
2058: for (Iterator lOutputMessagesIterator = pOperation
2059: .getOutputMessages().iterator(); lOutputMessagesIterator
2060: .hasNext();) {
2061: OperationOutputMessage lOutputMessage = (OperationOutputMessage) lOutputMessagesIterator
2062: .next();
2063: org.omg.uml.foundation.core.Parameter lParameter = pConversionContext.mUMLModelExtent
2064: .getCore().getParameter().createParameter();
2065: lUMLOperationParameters.add(lParameter);
2066: lParameter.setName(lOutputMessage.getName());
2067: lParameter
2068: .setVisibility(org.omg.uml.foundation.datatypes.VisibilityKindEnum.VK_PUBLIC);
2069: lParameter
2070: .setKind(org.omg.uml.foundation.datatypes.ParameterDirectionKindEnum.PDK_RETURN);
2071: lParameter
2072: .getStereotype()
2073: .add(
2074: pConversionContext.mMetaBossProfile.mGenericParameterStereotype);
2075: UMLUtils.copyComment(lOutputMessage, lParameter);
2076: UMLUtils
2077: .attachSingleTagToElement(
2078: lParameter,
2079: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_IsArray,
2080: Boolean.toString(lOutputMessage.isArray()));
2081: Message lMessageType = lOutputMessage.getMessageType();
2082: if (lMessageType != null)
2083: lParameter.setType(UMLUtils.getUmlClass(
2084: pConversionContext.mTargetModelName,
2085: lMessageType, UMLStylesheet
2086: .getMessageXPath(lMessageType)));
2087: if (lOutputMessage.isDerived())
2088: UMLUtils
2089: .attachSingleTagToElement(
2090: lParameter,
2091: pConversionContext.mMetaBossProfile.mGenericParameterTagDefinition_Derived,
2092: Boolean.toString(true));
2093: }
2094: // Convert input constraints
2095: Collection lConstraints = pOperation.getInputConstraints();
2096: if (!lConstraints.isEmpty()) {
2097: // Build context string
2098: String lParentContextName = pParentName.substring(0, 1)
2099: .toUpperCase()
2100: + pParentName.substring(1);
2101: String lOperationName = pUMLOperation.getName();
2102: String lOperationContextName = lOperationName.substring(0,
2103: 1).toLowerCase()
2104: + lOperationName.substring(1);
2105: StringBuffer lParametersStringBuffer = new StringBuffer();
2106: for (Iterator lInputFieldsIterator = pOperation
2107: .getInputFields().iterator(); lInputFieldsIterator
2108: .hasNext();) {
2109: OperationInputField lInputField = (OperationInputField) lInputFieldsIterator
2110: .next();
2111: String lParameterName = lInputField.getName();
2112: String lParameterContextName = lParameterName
2113: .substring(0, 1).toLowerCase()
2114: + lParameterName.substring(1);
2115: lParametersStringBuffer.append(lParameterContextName);
2116: if (lInputFieldsIterator.hasNext())
2117: lParametersStringBuffer.append(", ");
2118: }
2119: String lConstraintStringStart = "context " + pParentName
2120: + ":" + lOperationName + "("
2121: + lParametersStringBuffer.toString() + ") pre : ";
2122: convertConstraints(pConversionContext, lConstraints,
2123: pUMLOperation, lConstraintStringStart);
2124: }
2125: }
2126: }
|