Example #1
0
        public string GenerateAttribute(PSMAttribute attribute)
        {
            if (attribute.Upper > 1 || attribute.Lower > 1)
            {
                Log.AddError(string.Format("Attribute {0}.{1} has upper multiplicity {2} that is not valid for XML documents. ", attribute.Class.Name, attribute.Name, attribute.MultiplicityString));
            }

            if (attribute.Lower == 1)
            {
                string value;
                if (attribute.Default != null && UseAttributesDefaultValues)
                {
                    value = attribute.Default;
                }
                else
                {
                    value = valuesGenerator.GenerateValue(attribute.Type);
                }

                string attributeName = namingSupport.NormalizeTypeName(attribute, at => at.AliasOrName);
                return(string.Format("{0}={1}{2}{1}", attributeName, AttributeQuotation, value));
            }
            else // Lower == 0
            {
                return(string.Empty);
            }
        }
        public override bool CanExecute()
        {
            if (attributeGuid == Guid.Empty)
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }
            PSMAttribute attribute = Project.TranslateComponent <PSMAttribute>(attributeGuid);
            PSMClass     oldclass  = attribute.PSMClass;
            PSMClass     newclass  = oldclass.GeneralizationAsSpecific == null ? null : oldclass.GeneralizationAsSpecific.General;

            if (newclass == null)
            {
                ErrorDescription = CommandErrors.CMDERR_NO_GENERALIZATION;
                return(false);
            }
            if (attribute.Interpretation != null)
            {
                PSMClass intclass = attribute.NearestInterpretedClass();
                if (intclass != null)
                {
                    if ((intclass.Interpretation as PIMClass) != (attribute.Interpretation as PIMAttribute).PIMClass &&
                        !(intclass.Interpretation as PIMClass).GetGeneralClasses().Contains((attribute.Interpretation as PIMAttribute).PIMClass))
                    {
                        ErrorDescription = CommandErrors.CMDERR_CANNOT_GENERALIZE_INTERPRET_ERR;
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #3
0
        public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMAttribute psmAttribute)
        {
            List <EvolutionChange> result = new List <EvolutionChange>();

            PSMAttribute psmAttributeOldVersion = (PSMAttribute)psmAttribute.GetInVersion(v1);
            PSMAttribute psmAttributeNewVersion = (PSMAttribute)psmAttribute.GetInVersion(v2);

            Debug.Assert(psmAttributeNewVersion == psmAttribute);
            if (
                (psmAttributeOldVersion.RepresentedAttribute == null && psmAttributeNewVersion.RepresentedAttribute != null) ||
                (psmAttributeOldVersion.RepresentedAttribute != null && psmAttributeNewVersion.RepresentedAttribute == null) ||
                (
                    psmAttributeOldVersion.RepresentedAttribute != null &&
                    psmAttributeNewVersion.RepresentedAttribute != null &&
                    psmAttributeOldVersion.RepresentedAttribute != psmAttributeNewVersion.RepresentedAttribute.GetInVersion(v1)
                )
                )
            {
                AttributeRepresentedAttributeChange c = new AttributeRepresentedAttributeChange(psmAttribute)
                {
                    OldVersion = v1, NewVersion = v2
                };
                result.Add(c);
            }

            return(result);
        }
Example #4
0
        public void MoveAttributeBackToClass(PSMAttribute attribute)
        {
            MoveAttributesFromAttributeContainerBackToClassMacroCommand command = (MoveAttributesFromAttributeContainerBackToClassMacroCommand)MoveAttributesFromAttributeContainerBackToClassMacroCommandFactory.Factory().Create(DiagramController);

            command.InitializeCommand(AttributeContainer, new[] { attribute });
            command.Execute();
        }
        public XElement RngAttributeAsElement(XElement parentElement, string name, PSMAttribute psmAttribute)
        {
            XElement attribute = RngElement(parentElement, name);

            GiveTypeToAttribute(attribute, psmAttribute);
            return(attribute);
        }
        public void Set(PSMAttribute attribute)
        {
            //Only PIMLess attributes
            if (attribute.RepresentedAttribute != null)
            {
                return;
            }

            ElementHolder <Property> AttributeHolder = new ElementHolder <Property>();
            NewAttributeCommand      c1 = NewAttributeCommandFactory.Factory().Create(Controller) as NewAttributeCommand;

            c1.createdAttributeHolder = AttributeHolder;
            c1.Owner   = attribute.Class.RepresentedClass;
            c1.Lower   = attribute.Lower;
            c1.Upper   = attribute.Upper;
            c1.Default = attribute.Default;
            c1.Name    = NameSuggestor <Property> .SuggestUniqueName(attribute.Class.RepresentedClass.Attributes, attribute.Name ?? attribute.Alias, property => property.Name);

            c1.Type = new ElementHolder <DataType>(attribute.Type);
            Commands.Add(c1);

            RenameElementCommand <Property> c2 = RenameElementCommandFactory <Property> .Factory().Create(Controller) as RenameElementCommand <Property>;

            c2.ContainingCollection = attribute.Class.Attributes;
            c2.RenamedElement       = attribute;
            c2.NewName = c1.Name;
            Commands.Add(c2);

            PropagatePIMLessCommand c3 = PropagatePIMLessCommandFactory.Factory().Create(Controller) as PropagatePIMLessCommand;

            c3.Set(new ElementHolder <PSMAttribute>(attribute), AttributeHolder);
            Commands.Add(c3);
        }
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAttribute psmAttribute = Project.TranslateComponent <PSMAttribute>(attributeGuid);

            psmAttribute.Element = oldForm;
            return(OperationResult.OK);
        }
Example #8
0
        private static void CheckPSMAttribute(PSMAttribute psmAttribute)
        {
            CheckPSMComponent(psmAttribute);

            Assert.IsNotNull(psmAttribute.PSMClass);
            Assert.IsTrue(psmAttribute.PSMClass.PSMAttributes.Contains(psmAttribute));
        }
Example #9
0
        internal override void CommandOperation()
        {
            PSMSuperordinateComponent p = AttributeContainerLeftOut.Parent;

            while (!(p is PSMClass) && p is PSMSubordinateComponent)
            {
                p = ((PSMSubordinateComponent)p).Parent;
            }
            parentClass = p as PSMClass;
            if (parentClass != null)
            {
                returnedAttributes = new List <PSMAttribute>();
                foreach (PSMAttribute attribute in AttributeContainerLeftOut.PSMAttributes)
                {
                    if (parentClass.PSMAttributes.Any(a => a.RepresentedAttribute == attribute.RepresentedAttribute))
                    {
                        continue;
                    }
                    PSMAttribute createdAttribute = parentClass.AddAttribute(attribute.RepresentedAttribute);
                    returnedAttributes.Add(createdAttribute);
                    if (!String.IsNullOrEmpty(attribute.Alias))
                    {
                        createdAttribute.Alias = attribute.Alias;
                    }
                }
                AttributeContainerLeftOut.RemoveMeFromModel();
                viewHelper = Diagram.DiagramElements[AttributeContainerLeftOut];
                Diagram.RemoveModelElement(AttributeContainerLeftOut);
            }
        }
Example #10
0
        public static List <PSMAttribute> GetAttributesForGroup(this PSMClass groupNode, Version oldVersion)
        {
            // take elements in the group that used to be attributes
            List <PSMAttribute>       result            = new List <PSMAttribute>();
            List <NodeElementWrapper> contentComponents = groupNode.GetSubtreeElements();

            foreach (NodeElementWrapper contentComponent in contentComponents)
            {
                if (contentComponent is SimpleNodeElement)
                {
                    SimpleNodeElement simpleNodeElement = ((SimpleNodeElement)contentComponent);
                    if (simpleNodeElement.Element is PSMAttribute)
                    {
                        PSMAttribute attribute           = (PSMAttribute)simpleNodeElement.Element;
                        PSMAttribute attributeOldVersion = (PSMAttribute)attribute.GetInVersion(oldVersion);
                        if (attributeOldVersion != null)
                        {
                            PSMElement parent = (attributeOldVersion).Class;
                            if (parent is PSMClass && ((PSMClass)parent).HasElementLabel)
                            {
                                continue;
                            }

                            if (attribute.AttributeContainer != null && attributeOldVersion.AttributeContainer == null)
                            {
                                result.Add(attribute);
                            }
                        }
                    }
                }
            }

            return(result);
        }
Example #11
0
        internal override void CommandOperation()
        {
            PSMAttribute c = Project.TranslateComponent <PSMAttribute>(PSMComponentGuid);
            PIMAttribute oldInterpretation = c.Interpretation as PIMAttribute;

            if (c.UsedGeneralizations.Count > 0)
            {
                oldUsedGeneralizations.AddRange(c.UsedGeneralizations.Select(g => g.ID));
            }
            if (c.Interpretation == null)
            {
                oldPimComponentGuid = Guid.Empty;
            }
            else
            {
                oldPimComponentGuid = c.Interpretation;
            }
            if (PIMComponentGuid != Guid.Empty)
            {
                c.Interpretation = Project.TranslateComponent <PIMAttribute>(PIMComponentGuid);
                c.UsedGeneralizations.Clear();
                foreach (PIMGeneralization g in (c.NearestInterpretedClass().Interpretation as PIMClass).GetGeneralizationPathTo((c.Interpretation as PIMAttribute).PIMClass))
                {
                    c.UsedGeneralizations.Add(g);
                }
            }
            else
            {
                c.Interpretation = null;
                c.UsedGeneralizations.Clear();
            }
            Report = new CommandReport(CommandReports.SET_INTERPRETATION, c, oldInterpretation, c.Interpretation);
        }
Example #12
0
        /// <summary>
        /// Adds visualization of <paramref name="attribute"/> to the control
        /// </summary>
        /// <param name="attribute">visualized attribute</param>
        /// <returns>Control displaying the attribute</returns>
        public PSMAttributeTextBox AddAttribute(PSMAttribute attribute)
        {
            PSMAttributeTextBox t = new PSMAttributeTextBox(attribute, attributeController);

            base.AddItem(t);
            return(t);
        }
Example #13
0
        public override bool VerifyConsistency(object superordinateObject, object candidate)
        {
            PSMClass     PSMClass     = (PSMClass)superordinateObject;
            PSMAttribute PSMAttribute = (PSMAttribute)candidate;

            return(PSMClass.PSMAttributes.Contains(PSMAttribute));
        }
Example #14
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && psmAttribute.AttributeType != psmAttributeO.AttributeType);
        }
Example #15
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && (psmAttribute.Lower != psmAttributeO.Lower || psmAttribute.Upper != psmAttributeO.Upper));
        }
        private void CheckUniqueAliasName(object sender, RoutedEventArgs e)
        {
            PSMAttribute oldContext = (PSMAttribute)((TextBox)sender).DataContext;

            string text = ((TextBox)sender).Text;

            if (text == String.Empty)
            {
                text = null;
            }

            if (oldContext.AliasOrName == text)
            {
                return;
            }

            foreach (PSMAttribute p in oldContext.AttributeContainer.PSMAttributes)
            {
                if (p.AliasOrName == text)
                {
                    ErrDialog d = new ErrDialog();
                    d.SetText("Change alias of an attribute on a PSM diagram\n", "Name \"" + text + "\" cannot be used because it is already used in the collection.");
                    d.ShowDialog();

                    ((TextBox)sender).DataContext = null;
                    ((TextBox)sender).DataContext = oldContext;
                    return;
                }
            }
        }
Example #17
0
 public void attributeAsElement(string name, PSMAttribute attribute)
 {
     if (silence)
     {
         return;
     }
     lastCreated = Document.attributeAsElement(Element, name, attribute);
 }
Example #18
0
        public void ChangeAttributeAlias(PSMAttribute attribute, string newAlias)
        {
            ChangeAttributeAliasCommand changeAttributeAliasCommand = (ChangeAttributeAliasCommand)ChangeAttributeAliasCommandFactory.Factory().Create(DiagramController);

            changeAttributeAliasCommand.Attribute = attribute;
            changeAttributeAliasCommand.NewAlias  = newAlias;
            changeAttributeAliasCommand.Execute();
        }
Example #19
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmAttributeO.PSMClass, psmAttribute.PSMClass));
        }
Example #20
0
        public XElement RngAttribute(XElement parentElement, string name, PSMAttribute psmAttribute)
        {
            XElement attribute = RngGenericElement(parentElement, "attribute");

            AddAttributeWithValue(attribute, "name", name);
            GiveTypeToAttribute(attribute, psmAttribute);
            return(attribute);
        }
Example #21
0
 public void attribute(string name, PSMAttribute attribute, bool forceOptional)
 {
     if (silence)
     {
         return;
     }
     lastCreated = Document.attribute(Element, name, attribute, forceOptional);
 }
Example #22
0
 public PSMAttributeTextBox GetTextBoxOfAttribute(PSMAttribute psmAttribute)
 {
     if (RepresentantsCollection.ContainsKey(psmAttribute.PSMClass))
     {
         PSMClassView cv = (PSMClassView)RepresentantsCollection[psmAttribute.PSMClass];
         return(cv.AttributeTextBoxes.FirstOrDefault(tb => tb.PSMAttribute == psmAttribute));
     }
     return(null);
 }
Example #23
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute = ((PSMAttribute)candidate);

            return(new AttributeAddedInstance(candidate, oldVersion, newVersion)
            {
                Parent = psmAttribute.PSMClass, Index = psmAttribute.Index
            });
        }
Example #24
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAttribute a = Project.TranslateComponent <PSMAttribute>(AttributeGuid);

            Project.TranslateComponent <PSMSchema>(schemaGuid).PSMAttributes.Remove(a);
            Project.TranslateComponent <PSMClass>(classGuid).PSMAttributes.Remove(a);
            Project.mappingDictionary.Remove(AttributeGuid);
            return(OperationResult.OK);
        }
Example #25
0
        public void ChangeAttributeType(PSMAttribute attribute, ElementHolder <DataType> newType)
        {
            ChangeAttributeTypeCommand c = (ChangeAttributeTypeCommand)ChangeAttributeTypeCommandFactory.Factory().Create(DiagramController.ModelController);

            c.AssociatedElements.Add(Class);
            c.Attribute = attribute;
            c.NewType   = newType;
            c.Execute();
        }
Example #26
0
        public void RenameAttribute(PSMAttribute attribute, string newName)
        {
            RenameElementCommand <PSMAttribute> renameElementCommand = (RenameElementCommand <PSMAttribute>) RenameElementCommandFactory <PSMAttribute> .Factory().Create(DiagramController.ModelController);

            renameElementCommand.NewName              = newName;
            renameElementCommand.RenamedElement       = attribute;
            renameElementCommand.ContainingCollection = Class.PSMAttributes;
            renameElementCommand.Execute();
        }
Example #27
0
 /// <summary>
 /// Writes <see cref="PSMAttribute"/> as an XML element (with name, value and multiplicity)
 /// </summary>
 /// <param name="name">name of the attribute</param>
 /// <param name="attribute">written attribute</param>
 /// <param name="simpleTypeWriter">if a simpleType must be created for the attribute, it is written in this writer</param>
 public void AttributeAsElement(string name, PSMAttribute attribute, ref SimpleTypesWriter simpleTypeWriter)
 {
     Writer.WriteStartElement(NamespacePrefix, "element", "http://www.w3.org/2001/XMLSchema");
     Writer.WriteAttributeString("name", name);
     TypeAttribute(attribute, ref simpleTypeWriter, true, false);
     Writer.WriteEndElement();
     IsEmpty = false;
     AfterWriteDebug();
 }
Example #28
0
        public void ChangeAttributeDefaultValue(PSMAttribute attribute, string newDefaultValue)
        {
            ChangeAttributeDefaultValueCommand changeAttributeDefaultValueCommand = (ChangeAttributeDefaultValueCommand)ChangeAttributeDefaultValueCommandFactory.Factory().Create(DiagramController.ModelController);

            changeAttributeDefaultValueCommand.Attribute = attribute;
            changeAttributeDefaultValueCommand.AssociatedElements.Add(Class);
            changeAttributeDefaultValueCommand.NewDefault = newDefaultValue;
            changeAttributeDefaultValueCommand.Execute();
        }
        internal override void CommandOperation()
        {
            PSMAttribute psmAttribute = Project.TranslateComponent <PSMAttribute>(attributeGuid);

            oldDefaultValue           = psmAttribute.DefaultValue;
            psmAttribute.DefaultValue = newDefaultValue;

            Report = new CommandReport("Default value of '{0}' changed from '{1}' to '{2}'.", psmAttribute, oldDefaultValue, newDefaultValue);
        }
Example #30
0
        protected override void TranslateAttribute(PSMAttribute attribute, DataGeneratorContext context)
        {
            if (!attribute.Element && (attribute.Upper > 1 || attribute.Lower > 1))
            {
                Log.AddError(string.Format("Attribute {0}.{1} has upper multiplicity {2} that is not valid for XML documents. ", attribute.PSMClass.Name, attribute.Name, attribute.CardinalityString));
            }

            bool appears = false;

            // mandatory attribute
            if (attribute.Lower >= 1)
            {
                appears = true;
            }
            else if (attribute.Lower == 0)
            {
                appears = RandomGenerator.Toss(2, 1);
            }

            uint upper = attribute.Element ? ChooseCardinality(attribute) : 1;

            if (appears)
            {
                for (int i = 0; i < upper; i++)
                {
                    string value = string.Empty;
                    if (!EmptyValues)
                    {
                        if (attribute.DefaultValue != null && UseAttributesDefaultValues)
                        {
                            value = attribute.DefaultValue;
                        }
                        else
                        {
                            value = valuesGenerator.GenerateValue(attribute.AttributeType);
                        }
                    }
                    string attributeName = namingSupport.NormalizeTypeName(attribute);


                    if (attribute.Element)
                    {
                        //XElement element = new XElement(ProjectNamespace + attributeName);
                        XElement element = new XElement(attributeName);
                        XText    text    = new XText(value);
                        context.CurrentElement.Add(element);
                        element.Add(text);
                    }
                    else
                    {
                        XAttribute a = new XAttribute(attributeName, value);
                        context.CurrentElement.Add(a);
                    }
                }
            }
        }