示例#1
0
        private EMOF.IPrimitiveType ConstructPrimitiveType(EnAr.Element classElement)
        {
            EMOF.IPrimitiveType result = new EMOF.PrimitiveType()
            {
                Name = classElement.Name,
            };

            string mofPrimitiveType = explorer.GetTaggedValue(classElement, "MOFPrimitiveType");

            if (!mofPrimitiveType.IsNullOrEmpty())
            {
                result.SetCsharpType(mofPrimitiveType.ToLower());
            }
            else
            {
                result.SetCsharpType(classElement.Name.ToLower());
            }


            return(result);
        }
示例#2
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);
        }