예제 #1
0
        private void ConstructBasicRelation(QVTRelations.IRelationalTransformation transformation, EnAr.Element relationElement)
        {
            // First we check if an empty relation doesn't already exist
            QVTRelations.IRelation relation = FindRelation(transformation, relationElement.Name);

            // If not, we create it
            if (relation == null)
            {
                relation = new QVTRelations.Relation()
                {
                    Name = relationElement.Name
                };
                transformation.Rule.Add(relation);

                // We find the unique child EA elements with the stereotype "qvtTransformationNode"
                List <EnAr.Element> transformationNodeElements = explorer.GetChildrenElementsWithTypeAndStereotype(relationElement, "class", "qvtTransformationNode");
                EnAr.Element        transformationNodeElement  = transformationNodeElements.Single();

                bool isTopRelation = explorer.GetTaggedValue(relationElement, "isTopRelation").ToLower() == "true";

                relation.IsTopLevel     = isTopRelation;
                relation.Transformation = transformation;
                relation.Overrides      = null; // TODO

                // We browse the EA Connectors with the stereotype "qvtTransformationLink", from the qvtTransformationNode
                // We use the concrete syntax extension to order the domains
                foreach (EnAr.Connector qvtTransformationLinkConnector in explorer.GetConnectorsWithSourceWithStereotype(transformationNodeElement, "qvtTransformationLink").OrderBy(c => c.Name))
                {
                    ConstructRelationDomain(transformation, relation, qvtTransformationLinkConnector);
                }
            }
        }
예제 #2
0
        public QVTRelations.IRelationalTransformation ConstructRelationalTransformation(string transformatioName)
        {
            IList <EnAr.Element> transformationsElements = explorer.FindElementsWithTypeAndStereotype("component", "qvtTransformation");

            EnAr.Element transfo = transformationsElements.Single(e => e.Name == transformatioName);
            QVTRelations.IRelationalTransformation transformation = ConstructRelationalTransformation(transfo);
            return(transformation);
        }
예제 #3
0
        public List <QVTRelations.IRelationalTransformation> ConstructRelationalTransformations()
        {
            // Future result: a list of qvt transformations
            List <QVTRelations.IRelationalTransformation> result = new List <QVTRelations.IRelationalTransformation>();

            // We browse in the EA repo all the elements with the "qvtTransformation" stereotype
            IList <EnAr.Element> transformationsElements = explorer.FindElementsWithTypeAndStereotype("component", "qvtTransformation");

            foreach (EnAr.Element transformationElement in transformationsElements)
            {
                QVTRelations.IRelationalTransformation transformation = ConstructRelationalTransformation(transformationElement);
                result.Add(transformation);
            }

            return(result);
        }
예제 #4
0
        private void ConstructRelationDomain(QVTRelations.IRelationalTransformation relationTransformation, QVTRelations.IRelation relation, EnAr.Connector qvtTransformationLinkConnector)
        {
            // We look in the EA "domain" Element pointed by the qvtTransformationLinkConnector
            EnAr.Element domainObjectElement = explorer.GetTargetElement(qvtTransformationLinkConnector);

            // We construct (or get) the typed model, if any
            QVTBase.ITypedModel candidateTypedModel = ConstructTypedModel(relationTransformation, qvtTransformationLinkConnector);

            // If no typed model, it must be a primitive type
            // TODO maybe check for a tag?
            if (candidateTypedModel == null)
            {
                ConstructPrimitiveRelationDomain(relation, qvtTransformationLinkConnector, domainObjectElement);
                return;
            }

            // Else, we construct a regular domain
            ConstructNonPrimitiveRelationDomain(relation, candidateTypedModel, qvtTransformationLinkConnector, domainObjectElement);
        }
예제 #5
0
 private QVTRelations.IRelation FindRelation(QVTRelations.IRelationalTransformation transformation, string relationName)
 {
     return((QVTRelations.IRelation)transformation.Rule.FirstOrDefault(r => r.Name == relationName));
 }
예제 #6
0
 private QVTBase.IFunction FindFunction(QVTRelations.IRelationalTransformation relationalTransformation, string toString)
 {
     return((QVTBase.IFunction)relationalTransformation.OwnedOperation.FirstOrDefault(o => o.Name == toString));
 }
예제 #7
0
        private QVTBase.ITypedModel ConstructTypedModel(QVTRelations.IRelationalTransformation relationTransformation, EnAr.Connector qvtTransformationLinkConnector)
        {
            // We determine the typedmodel based on the FQN given on the connector
            string modelNameTag        = explorer.GetTaggedValue(qvtTransformationLinkConnector, "modelName");
            string metaModelNameTag    = explorer.GetTaggedValue(qvtTransformationLinkConnector, "metaModelName");
            string typedModelName      = "";
            string metamodelFQNOrAlias = "";

            EMOF.IPackage metamodelPackage = null;
            if (!modelNameTag.IsNullOrEmpty())
            {
                if (modelNameTag.Contains(':'))
                {
                    string[] split = modelNameTag.Split(':');
                    typedModelName      = split[0];
                    metamodelFQNOrAlias = split[1];
                }
                else if (metaModelNameTag != null)
                {
                    typedModelName = modelNameTag;
                }
            }

            if (metamodelFQNOrAlias.IsNullOrEmpty() && metaModelNameTag != null)
            {
                // Case real link
                if (metaModelNameTag.StartsWith("{"))
                {
                    EnAr.Package enArMetamodelPackage = explorer.GetPackageByGuid(metaModelNameTag);
                    metamodelPackage = emofImporter.GetEMOFPackage(enArMetamodelPackage);
                }
                // Case string name
                else
                {
                    metamodelFQNOrAlias = metaModelNameTag;
                }
            }

            if (metamodelPackage == null)
            {
                // The metamodel package can be found either using the FQN or one of its aliases
                metamodelPackage = metamodels.FirstOrDefault(metamodel => EnArImporterEMOF.GetFQN(metamodel) == metamodelFQNOrAlias || (aliases.ContainsKey(metamodelFQNOrAlias) && metamodel == aliases[metamodelFQNOrAlias]));
            }

            /*if (typedModelName.IsNullOrEmpty() && metamodelPackage == null)
             * {
             *  throw new InvalidQVTRelationsModelException("A domain link must either indicate the model name with the pattern <model name>:<metamodel name>, or must provide a tag 'metaModelName'.", qvtTransformationLinkConnector);
             * }*/

            // Case primitive domains... could probably be managed better
            if (metamodelPackage == null)
            {
                return(null);
            }

            // We first check that the relational transformation doesn't already have this typed model
            QVTBase.ITypedModel typedModel = relationTransformation.ModelParameter.FirstOrDefault(p => (typedModelName.IsNullOrEmpty() || p.Name == typedModelName) && p.UsedPackage.FirstOrDefault(p2 => p2 == metamodelPackage) != null);

            // If there is none, we create one
            if (typedModel == null)
            {
                typedModel = new QVTBase.TypedModel()
                {
                    Name           = typedModelName,
                    Transformation = relationTransformation,
                };
                typedModel.UsedPackage.Add(metamodelPackage);
            }

            return(typedModel);
        }