Description of TaggedValueMapping.
Inheritance: Mapping
示例#1
0
        public static List <Mapping> createNewMappings(TSF.UmlToolingFramework.Wrappers.EA.Attribute attribute, string basepath, ElementWrapper targetRootElement)
        {
            List <Mapping> returnedMappings = new List <Mapping>();

            //connectors from owned attributes
            foreach (ConnectorWrapper mappedConnector in attribute.relationships.OfType <ConnectorWrapper>())
            {
                if (!mappedConnector.taggedValues.Any(x => x.name == mappingSourcePathName && x.tagValue.ToString() != basepath))
                {
                    //get the target base path
                    ConnectorMapping connectorMapping;
                    var    targetTV       = mappedConnector.taggedValues.FirstOrDefault(x => x.name == mappingTargetPathName);
                    string targetBasePath = string.Empty;
                    if (targetTV != null)
                    {
                        targetBasePath = targetTV.tagValue.ToString();
                    }
                    if (!string.IsNullOrEmpty(targetBasePath))
                    {
                        connectorMapping = new ConnectorMapping(mappedConnector, basepath, targetBasePath);
                    }
                    else
                    {
                        connectorMapping = new ConnectorMapping(mappedConnector, basepath, targetRootElement);
                    }
                    returnedMappings.Add(connectorMapping);
                }
            }
            //tagged value references from owned attributes
            foreach (TaggedValue mappedTaggedValue in attribute.taggedValues.Where(x => x.tagValue is Element))
            {
                string mappingSourcePath = KeyValuePairsHelper.getValueForKey(mappingSourcePathName, mappedTaggedValue.comment);
                string targetBasePath    = KeyValuePairsHelper.getValueForKey(mappingTargetPathName, mappedTaggedValue.comment);

                //if not filled in or corresponds to the attributeBasePath or the attributeBasePath + the name of the attribute
                if (string.IsNullOrEmpty(mappingSourcePath) || mappingSourcePath == basepath ||
                    mappingSourcePath == basepath + "." + attribute.name)
                {
                    TaggedValueMapping tagMapping;
                    if (!string.IsNullOrEmpty(targetBasePath))
                    {
                        tagMapping = new TaggedValueMapping(mappedTaggedValue, basepath, targetBasePath);
                    }
                    else
                    {
                        tagMapping = new TaggedValueMapping(mappedTaggedValue, basepath, targetRootElement);
                    }
                    returnedMappings.Add(tagMapping);
                }
            }
            //add the mappings for the type of the attribute
            var attributeType = attribute.type as ElementWrapper;

            if (attributeType != null)
            {
                returnedMappings.AddRange(createOwnedMappings(attributeType, basepath + "." + attribute.name, false));
            }
            return(returnedMappings);
        }
        public static List<Mapping> createNewMappings(TSF.UmlToolingFramework.Wrappers.EA.Attribute attribute,string basepath,ElementWrapper targetRootElement)
        {
            List<Mapping> returnedMappings = new List<Mapping>();
            //connectors from owned attributes
            foreach (ConnectorWrapper mappedConnector in attribute.relationships.OfType<ConnectorWrapper>())
            {
                if (! mappedConnector.taggedValues.Any( x => x.name == mappingSourcePathName && x.tagValue.ToString() != basepath))
                {
                    //get the target base path
                    ConnectorMapping connectorMapping;
                    var targetTV = mappedConnector.taggedValues.FirstOrDefault(x => x.name == mappingTargetPathName);
                    string targetBasePath = string.Empty;
                    if (targetTV != null) targetBasePath = targetTV.tagValue.ToString();
                    if (! string.IsNullOrEmpty(targetBasePath))
                    {
                        connectorMapping = new ConnectorMapping(mappedConnector,basepath,targetBasePath);
                    }
                    else
                    {
                        connectorMapping = new ConnectorMapping(mappedConnector,basepath,targetRootElement);
                    }
                    returnedMappings.Add(connectorMapping);
                }
            }
            //tagged value references from owned attributes
            foreach (TaggedValue mappedTaggedValue in attribute.taggedValues.Where(x => x.tagValue is Element) )
            {
                string mappingSourcePath = getValueForKey(mappingSourcePathName,mappedTaggedValue.comment);
                string targetBasePath = getValueForKey(mappingTargetPathName,mappedTaggedValue.comment);

                //if not filled in or corresponds to the attributeBasePath
                if (string.IsNullOrEmpty(mappingSourcePath) || mappingSourcePath == basepath)
                {
                    TaggedValueMapping tagMapping;
                    if (! string.IsNullOrEmpty(targetBasePath))
                    {
                        tagMapping = new TaggedValueMapping(mappedTaggedValue,basepath,targetBasePath);
                    }
                    else
                    {
                        tagMapping = new TaggedValueMapping(mappedTaggedValue,basepath,targetRootElement);
                    }
                    returnedMappings.Add(tagMapping);
                }
            }
            //add the mappings for the type of the attribute
            var attributeType = attribute.type as ElementWrapper;
            if (attributeType != null) returnedMappings.AddRange(createOwnedMappings(attributeType,basepath + "." + attribute.name));
            return returnedMappings;
        }
示例#3
0
        public LinkedTreeNodes Link(LinkedTreeNode source, LinkedTreeNode target)
        {
            // create new mapping from link information
            var mapping = new AM.TaggedValueMapping(
                (AM.MappingEnd)source.MappedEnd, (AM.MappingEnd)target.MappedEnd
                );

            this.addMapping(mapping);

            // raise Event
            this.CreateMapping(mapping);

            // TODO? invalidated to re-render new links ?
            this.Invalidate();
            return(null);
        }
示例#4
0
        /// <summary>
        /// create a mappingSet based on the data in the CSV file
        /// </summary>
        /// <param name="model">the model that contains the elements</param>
        /// <param name="filePath">the path to the CSV file</param>
        /// <returns>a mapping set representing the mapping in the file</returns>
        public static MappingSet createMappingSet(Model model, string filePath, MappingSettings settings, Element sourceRootElement = null, Element targetRootElement = null)
        {
            MappingSet newMappingSet = null;
            var        engine        = new FileHelperEngine <CSVMappingRecord>();
            var        parsedFile    = engine.ReadFile(filePath);
            int        i             = 1;
            Package    rootPackage   = null;

            foreach (CSVMappingRecord mappingRecord in parsedFile)
            {
                //find source
                var source = findElement(model, mappingRecord.sourcePath, sourceRootElement);
                //find target
                var target = findElement(model, mappingRecord.targetPath, targetRootElement);
                if (source == null)
                {
                    EAOutputLogger.log(model, settings.outputName
                                       , string.Format("Could not find element that matches: '{0}'", mappingRecord.sourcePath)
                                       , 0, LogTypeEnum.error);
                }
                else if (target == null)
                {
                    EAOutputLogger.log(model, settings.outputName
                                       , string.Format("Could not find element that matches: '{0}'", mappingRecord.targetPath)
                                       , 0, LogTypeEnum.error);
                }
                else
                {
                    //first check if the mappingSet is already created
                    if (newMappingSet == null)
                    {
                        //determine if this should be a PackageMappingSet or an ElementMappingSet
                        if (sourceRootElement is Package)
                        {
                            rootPackage   = sourceRootElement as Package;
                            newMappingSet = new PackageMappingSet(sourceRootElement as Package);
                        }
                        else if (sourceRootElement is ElementWrapper)
                        {
                            rootPackage   = sourceRootElement.owningPackage as Package;
                            newMappingSet = new ElementMappingSet(sourceRootElement as ElementWrapper);
                        }
                        else
                        {
                            rootPackage   = source.owningPackage as Package;
                            newMappingSet = new PackageMappingSet((Package)source.owningPackage);
                        }
                    }
                    MappingLogic newMappingLogic = null;
                    //check if there is any mapping logic
                    if (!string.IsNullOrEmpty(mappingRecord.mappingLogic))
                    {
                        if (settings.useInlineMappingLogic)
                        {
                            newMappingLogic = new MappingLogic(mappingRecord.mappingLogic);
                        }
                        else
                        {
                            //Check fo an existing mapping logic
                            newMappingLogic = getExistingMappingLogic(model, settings, mappingRecord.mappingLogic, rootPackage);

                            if (newMappingLogic == null)
                            {
                                var mappingElement = model.factory.createNewElement(rootPackage, "mapping logic " + i, settings.mappingLogicType) as ElementWrapper;
                                if (mappingElement != null)
                                {
                                    //increase counter for new mapping element name
                                    i++;
                                    mappingElement.notes = mappingRecord.mappingLogic;
                                    mappingElement.save();
                                    //create the mappingLogic
                                    newMappingLogic = new MappingLogic(mappingElement);
                                }
                                else
                                {
                                    //else we create an inline mapping logic anyway
                                    newMappingLogic = new MappingLogic(mappingRecord.mappingLogic);
                                }
                            }
                        }
                    }
                    Mapping newMapping           = null;
                    var     sourceAssociationEnd = source as AssociationEnd;
                    var     targetAssociationEnd = target as AssociationEnd;
                    //create the new mapping
                    //we can't create connector mappings for mappings to or from associations so we have to use tagged value mappings for those.
                    if (settings.useTaggedValues ||
                        sourceAssociationEnd != null || targetAssociationEnd != null)
                    {
                        //if the source or target are associationEnds then we replace them by their association
                        if (sourceAssociationEnd != null)
                        {
                            source = sourceAssociationEnd.association as Element;
                        }
                        if (targetAssociationEnd != null)
                        {
                            target = targetAssociationEnd.association as Element;
                        }
                        newMapping = new TaggedValueMapping(source, target, mappingRecord.sourcePath, mappingRecord.targetPath, settings);
                    }
                    else
                    {
                        newMapping = new ConnectorMapping(source, target, mappingRecord.sourcePath, mappingRecord.targetPath, settings);
                    }
                    if (newMappingLogic != null)
                    {
                        newMapping.mappingLogic = newMappingLogic;
                    }
                    newMapping.save();
                    newMappingSet.addMapping(newMapping);
                }
            }
            return(newMappingSet);
        }