Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private QVTRelations.IRelationDomain ConstructNonPrimitiveRelationDomain(QVTRelations.IRelation relation, QVTBase.ITypedModel typedModel, EnAr.Connector qvtTransformationLinkConnector, EnAr.Element domainObjectElement)
        {
            //if (domainObjectElement.Stereotype != "domain")
            //    throw new InvalidQVTRelationsModelException("A domain element must have the \"domain\" stereotype", domainObjectElement);
            // TODO replace by warning?

            QVTRelations.RelationDomain relationDomain = new QVTRelations.RelationDomain()
            {
                Name          = qvtTransformationLinkConnector.Name,
                IsCheckable   = true,
                IsEnforceable = explorer.GetTaggedValue(qvtTransformationLinkConnector, "CEType").ToLower() == "enforce",
                TypedModel    = typedModel,
                //DefaultAssignment = null // TODO
                Rule = relation
            };

            QVTRelations.IDomainPattern domainpattern = ConstructDomainPattern(relation, domainObjectElement);
            relationDomain.Pattern       = domainpattern;
            relationDomain.RootVariable  = domainpattern.TemplateExpression.BindsTo;
            domainpattern.RelationDomain = relationDomain;
            return(relationDomain);
        }
Ejemplo n.º 3
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);
        }