Exemplo n.º 1
0
        private int ChooseMultiplicity(MultiplicityElement multiplicityElement)
        {
            int lower = multiplicityElement.Lower.HasValue ? (int)multiplicityElement.Lower.Value : 0;
            int upper = multiplicityElement.Upper != NUml.Uml2.UnlimitedNatural.Infinity ? (int)multiplicityElement.Upper.Value : InfinityBound;

            if (multiplicityElement is PSMAssociation)
            {
                PSMAssociation association = (PSMAssociation)multiplicityElement;
                int            occurrences = GetElementOccurrences(association);
                if (occurrences > 10 && association.Lower > 0)
                {
                    Log.AddError(string.Format("Association {0} is recursive and causes infinite nesting.", association));
                    throw new XmlSchemaException(string.Format("Association {0} is recursive and causes infinite nesting.", association));
                }
                if (MinimalTree)
                {
                    return(lower);
                }
                else
                {
                    return(RandomGenerator.Next(lower, upper + 1, occurrences - 1));
                }
            }
            else
            {
                if (MinimalTree)
                {
                    return(lower);
                }
                else
                {
                    return(RandomGenerator.Next(lower, upper + 1));
                }
            }
        }
Exemplo n.º 2
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && (psmAssociation.Lower != psmAssociationO.Lower || psmAssociation.Upper != psmAssociationO.Upper));
        }
        public override bool VerifyConsistency(object superordinateObject, object candidate)
        {
            PSMAssociationMember PSMAssociationMember = (PSMAssociationMember)superordinateObject;
            PSMAssociation       PSMAssociation       = (PSMAssociation)candidate;

            return(PSMAssociationMember.ChildPSMAssociations.Contains(PSMAssociation));
        }
Exemplo n.º 4
0
        public override void FillCopy(Element copyElement, Model targetModel, ElementCopiesMap createdCopies)
        {
            base.FillCopy(copyElement, targetModel, createdCopies);
            PSMAssociation copyPSMAssociation = (PSMAssociation)copyElement;

            copyPSMAssociation.Lower = Lower;
            copyPSMAssociation.Upper = Upper;
            //copyPSMAssociation.IsUnique = IsUnique;
            //copyPSMAssociation.IsOrdered = IsOrdered;
            copyPSMAssociation.Child = (PSMAssociationChild)createdCopies[Child];
            foreach (NestingJoin nestingJoin in NestingJoins)
            {
                PIMClass coreClass;
                if (targetModel.Schema != this.Schema)
                {
                    coreClass = (PIMClass)createdCopies[nestingJoin.CoreClass];
                }
                else
                {
                    coreClass = nestingJoin.CoreClass;
                }
                copyPSMAssociation.AddNestingJoin(coreClass);
            }

            if (Parent != null && createdCopies.ContainsKey(Parent))
            {
                PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent];
                ((_ImplPSMSubordinateComponent)copyPSMAssociation).Parent = copyParent;
                copyParent.Components.Add(copyPSMAssociation);
            }
        }
Exemplo n.º 5
0
        public override Element Clone(Model targetModel, ElementCopiesMap createdCopies)
        {
            PSMSuperordinateComponent copyParent = (PSMSuperordinateComponent)createdCopies[Parent];
            PSMAssociation            clone      = (PSMAssociation)PSMAssociationFactory.Instance.Create(copyParent, targetModel.Schema);

            return(clone);
        }
Exemplo n.º 6
0
        internal override void CommandOperation()
        {
            PSMAssociation a = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMSchema      s = Project.TranslateComponent <PSMSchema>(schemaGuid);

            if (a.Parent != null)
            {
                index = a.Parent.ChildPSMAssociations.IndexOf(a);
                a.Parent.ChildPSMAssociations.Remove(a);
                parentGuid = a.Parent;
            }
            //else throw new ExolutioCommandException("Deleted association " + a.ToString() + " had null Parent", this);

            isNonTreeAssociation = a.Child.ParentAssociation != a;

            if (a.Child != null)
            {
                childGuid = a.Child;
                if (!isNonTreeAssociation)
                {
                    a.Child.ParentAssociation = null;
                    s.Roots.Add(a.Child);
                }
            }
            //else throw new ExolutioCommandException("Deleted association " + a.ToString() + " had null Child", this);

            interpretation = a.Interpretation;
            s.PSMAssociations.Remove(a);
            Project.mappingDictionary.Remove(a);
            Report = new CommandReport(CommandReports.PSM_component_deleted, a);
        }
Exemplo n.º 7
0
        /**
         * Vraci asociace, ktere ovlivnuji asociaci association podle toho, v jake casti tvorby konecneho automatu se nachazime.
         *
         * atribut mode urcuje, v jake casti tvorby konecneho automatu se nachazime
         **/
        public static List <PSMAssociation> getAssociations(PSMAssociation association, CreationPhase mode)
        {
            List <PSMAssociation> associations = null;

            switch (mode)
            {
            case CreationPhase.ATTRIBUTE:
                associations = AssociationsUtils.associationsPropagatingAttributes(association, false);
                break;

            case CreationPhase.ELEMENT_ATTRIBUTE:
                associations = AssociationsUtils.associationsPropagatingAttributes(association, true);
                break;

            case CreationPhase.ELEMENT:
                associations = AssociationsUtils.associationsPropagatingElements(association);
                break;

            case CreationPhase.CONTENT_MODEL:
                associations = AssociationsUtils.associationsPropagatingAttributes(association, true);
                associations.AddRange(AssociationsUtils.associationsPropagatingElements(association));
                break;
            }
            return(associations);
        }
Exemplo n.º 8
0
        protected override void TranslateChoiceContentModel(PSMContentModel choiceModel, DataGeneratorContext context)
        {
            TranslateComments(choiceModel, context);
            PSMAssociation chosenAssociation = choiceModel.ChildPSMAssociations.ChooseOneRandomly();

            TranslateAssociation(chosenAssociation, context);
        }
        public override bool CanExecute()
        {
            if (AssociationGuid == Guid.Empty || PSMClassGuid == Guid.Empty)
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }

            PSMAssociation association = Project.TranslateComponent <PSMAssociation>(AssociationGuid);
            PSMClass       oldclass    = association.Parent as PSMClass;

            if (oldclass == null)
            {
                ErrorDescription = CommandErrors.CMDERR_PARENT_NOT_PSMCLASS;
                return(false);
            }

            PSMClass newclass = Project.TranslateComponent <PSMClass>(PSMClassGuid);

            if (!oldclass.GetGeneralClasses().Contains(newclass))
            {
                ErrorDescription = CommandErrors.CMDERR_CLASS_NOT_GENERAL;
                return(false);
            }

            return(true);
        }
Exemplo n.º 10
0
        private void ConvertPSMAssociation(PSMAssociation psmAssociation, PSMAssociationViewHelper psmAssociationViewHelper)
        {
            EvoX.Model.PSM.PSMAssociation evoxPSMAssociation;
            if (!TranslatedAlready(psmAssociation, out evoxPSMAssociation))
            {
                PSMAssociationMember parent = (PSMAssociationMember)ElementRef(psmAssociation.Parent);
                PSMAssociationMember child  = (PSMAssociationMember)ElementRef(psmAssociation.Child);
                evoxPSMAssociation = new EvoX.Model.PSM.PSMAssociation(evoxProject, parent, child, psmSchema);
                associationOrder[evoxPSMAssociation] = psmAssociation.ComponentIndex();
                translatedElements[psmAssociation]   = evoxPSMAssociation;
            }

            PSMClass childPSMClass = psmAssociation.Child as PSMClass;

            if (childPSMClass != null && childPSMClass.HasElementLabel)
            {
                evoxPSMAssociation.Name = childPSMClass.ElementName;
            }
            else
            {
                evoxPSMAssociation.Name = null;
            }
            PSMClassUnion psmClassUnion = psmAssociation.Child as PSMClassUnion;

            if (psmClassUnion != null)
            {
                evoxPSMAssociation.Name = null;
            }

            evoxPSMAssociation.Lower = ConvertToUint(psmAssociation.Lower);
            evoxPSMAssociation.Upper = ConvertToUnlimitedInt(psmAssociation.Upper);
        }
Exemplo n.º 11
0
 protected override void TranslateAssociation(PSMAssociation association, DataGeneratorContext context)
 {
     PathElements.Enqueue(association);
     TranslateComments(association, context);
     base.TranslateAssociation(association, context);
     PathElements.Dequeue();
 }
Exemplo n.º 12
0
            public Context(Context context)
            {
                Document = context.Document;
                Element  = context.Element;
                if (context.ComposedAttributes == null)
                {
                    ComposedAttributes = new List <ComposedAttrGroup>();
                }
                else
                {
                    ComposedAttributes = new List <ComposedAttrGroup>(context.ComposedAttributes);
                }
                if (context.ComposedContent == null)
                {
                    ComposedContent = new List <XmlNode>();
                }
                else
                {
                    ComposedContent = new List <XmlNode>(context.ComposedContent);
                }

                ReferencedModelGroups     = context.ReferencedModelGroups;
                ReferencedAttributeGroups = context.ReferencedAttributeGroups;
                LeadingAssociation        = context.LeadingAssociation;
                silence = false;
//                ARHeap = context.ARHeap.Copy();
            }
Exemplo n.º 13
0
 private StackedCommand GetNormalizationCommand(PSMSchema schema)
 {
     // (d) Content model association normalization
     if (!modelVerifier.TestSchemaClassChildrenAreClasses(schema))
     {
         PSMContentModel         cm      = (PSMContentModel)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(cm.ParentAssociation.ID);
         return(command);
     } // (c) Empty name association
     else if (!modelVerifier.TestSchemaClassChildrenNames(schema))
     {
         PSMAssociation          a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller);
         command.Set(a.ID);
         return(command);
     } // (e) Root content model normalization
     else if (!modelVerifier.TestRootsAreNotContentModels(schema))
     {
         PSMContentModel cm = (PSMContentModel)modelVerifier.LastViolatingComponent;
         MacroCommand    m  = new MacroCommand(Controller);
         foreach (PSMAssociation childPsmAssociation in cm.ChildPSMAssociations)
         {
             cmdDeletePSMAssociation delA = new cmdDeletePSMAssociation(Controller);
             delA.Set(childPsmAssociation.ID);
             m.Commands.Add(delA);
         }
         cmdDeletePSMContentModel delCM = new cmdDeletePSMContentModel(Controller);
         delCM.Set(cm.ID);
         m.Commands.Add(delCM);
         return(m);
     } // (f) Root class normalization
     else if (!modelVerifier.TestRootsAreReferenced(schema))
     {
         PSMClass c = (PSMClass)modelVerifier.LastViolatingComponent;
         cmdDeleteRootPSMClass command = new cmdDeleteRootPSMClass(Controller);
         command.Set(c.ID);
         return(command);
     } // (a) Cardinality normalization
     else if (!modelVerifier.TestSchemaClassChildrenCardinality(schema))
     {
         PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdUpdatePSMAssociationCardinality command = new cmdUpdatePSMAssociationCardinality(Controller);
         command.Set(a.ID, 1, 1);
         return(command);
     } // (b) Name normalization
     else if (!modelVerifier.TestContentModelsAssociationNames(schema))
     {
         PSMAssociation     a       = (PSMAssociation)modelVerifier.LastViolatingComponent;
         cmdRenameComponent command = new cmdRenameComponent(Controller)
         {
             ComponentGuid = a.ID, NewName = String.Empty
         };
         return(command);
     }
     else
     {
         throw new InvalidOperationException("Schema is already normalized. ");
     }
 }
Exemplo n.º 14
0
 public PSMBridgeAssociation(string defaultName, List <string> aliases, PSMAssociation sourceAss, AssociationDirection direction, PropertyType propertyType, Classifier type) :
     base(defaultName, propertyType, type, BridgePropertyType.Association)
 {
     this.DefaultName        = defaultName;
     this.Aliases            = aliases;
     this.SourceAsscociation = sourceAss;
     this.Direction          = direction;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Sets this command for execution
 /// </summary>
 /// <param name="association">The PSM association</param>
 /// <param name="parentPath">List of NestingJoinSteps describing the ParentPath</param>
 public void Set(PSMAssociation association, List <NestingJoinStep> parentPath)
 {
     Association = new ElementHolder <PSMAssociation>()
     {
         Element = association
     };
     ParentPath = parentPath;
 }
Exemplo n.º 16
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmAssociationO.Parent, psmAssociation.Parent));
        }
Exemplo n.º 17
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation = ((PSMAssociation)candidate);

            return(new AssociationAddedInstance(candidate, oldVersion, newVersion)
            {
                Parent = psmAssociation.Parent, Index = psmAssociation.Index
            });
        }
Exemplo n.º 18
0
 public FakePSMAssociation(PSMAssociation p)
     : this()
 {
     Name                      = p.Name;
     Multiplicity              = p.GetCardinalityString();
     SourceAssociation         = p;
     RepresentedPIMAssociation = (PIMAssociation)p.Interpretation;
     Checked                   = true;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Checks if the given component is present in a tree with given root.
        /// The search starts in the given root and recursively continues to the
        /// subordinate components (associations, containers, choices, unions) and
        /// finally it descends through the specializations (inheritance) of the classes.
        /// </summary>
        /// <param name="root">Reference to the root of the searched subtree</param>
        /// <param name="item">Reference to the item being searched</param>
        /// <returns>
        /// True if the item is present in the subtree with the given root, false otherwise.
        /// </returns>
        public static bool SubtreeContains(PSMSuperordinateComponent root, object item)
        {
            if (root == item)
            {
                return(true);
            }

            foreach (PSMSubordinateComponent component in root.Components)
            {
                if (component == item)
                {
                    return(true);
                }

                if (component is PSMSuperordinateComponent)
                {
                    if (SubtreeContains(component as PSMSuperordinateComponent, item))
                    {
                        return(true);
                    }
                }
                else if (component is PSMAssociation)
                {
                    PSMAssociation assoc = component as PSMAssociation;
                    if (assoc.Child is PSMClass)
                    {
                        if (SubtreeContains(assoc.Child as PSMClass, item))
                        {
                            return(true);
                        }
                    }
                    if (assoc.Child is PSMClassUnion)
                    {
                        if (ClassUnionContains(assoc.Child as PSMClassUnion, item))
                        {
                            return(true);
                        }
                    }
                }
            }

            if (root is PSMClass)
            {
                PSMClass rc = root as PSMClass;

                foreach (Generalization gen in rc.Specifications)
                {
                    if (SubtreeContains(gen.Specific as PSMClass, item))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 20
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(new AssociationIndexChangedInstance(candidate, oldVersion, newVersion)
            {
                OldIndex = psmAssociationO.Index,
                NewIndex = psmAssociation.Index
            });
        }
Exemplo n.º 21
0
        private static void CheckPSMAssociation(PSMAssociation psmAssociation)
        {
            CheckPSMComponent(psmAssociation);

            Assert.IsNotNull(psmAssociation.Child);
            Assert.IsNotNull(psmAssociation.Parent);
            Assert.IsTrue(psmAssociation.Parent.ChildPSMAssociations.Contains(psmAssociation));
            Assert.IsTrue(psmAssociation.Child.ParentAssociation == psmAssociation);

            CollectionAssert.Contains(psmAssociation.Schema.SchemaComponents, psmAssociation.Child);
        }
Exemplo n.º 22
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAssociation psmAssociation = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMClass       generalClass   = Project.TranslateComponent <PSMClass>(generalClassGuid);
            PSMClass       specialClass   = Project.TranslateComponent <PSMClass>(specialClassGuid);

            specialClass.ChildPSMAssociations.Remove(psmAssociation);
            psmAssociation.Parent = generalClass;
            generalClass.ChildPSMAssociations.Insert(psmAssociation, index);
            return(OperationResult.OK);
        }
Exemplo n.º 23
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAssociation psmAssociation = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMClass       oldClass       = Project.TranslateComponent <PSMClass>(oldParentGuid);
            PSMClass       newClass       = oldClass.GeneralizationAsSpecific.General;

            newClass.ChildPSMAssociations.Remove(psmAssociation);
            psmAssociation.Parent = oldClass;
            oldClass.ChildPSMAssociations.Insert(psmAssociation, index);
            return(OperationResult.OK);
        }
Exemplo n.º 24
0
        protected override void TranslateAssociation(PSMAssociation association, ChangesDetectorContext context)
        {
            context.ScopeStack.Push(EChangeScope.Association);
            context.CurrentPSMElement = association;

            ChangesLookupManager.DetectLocalChanges(context);
            TranslateAssociationChild(association.Child, context);

            EChangeScope pop = context.ScopeStack.Pop();

            Debug.Assert(pop == EChangeScope.Association);
        }
Exemplo n.º 25
0
        /**
         * Vraci asociace, ktere propaguji atributy do asociace topAssociation.
         *
         * atribute elementAttribute urcije, zda vracime asociace propagujci element atributy, nebo pouze obycejne atributy
         **/
        private static List <PSMAssociation> associationsPropagatingAttributes(PSMAssociation topAssociation, bool elementAttributes)
        {
            List <PSMAssociation>        resultAssociations = new List <PSMAssociation>();
            IEnumerable <PSMAssociation> associations       = null;

            if (topAssociation.Child is PSMClass)
            {
                associations = ((PSMClass)topAssociation.Child).GetActualChildPSMAssociations();
            }
            else
            if (topAssociation.Child is PSMContentModel)
            {
                associations = ((PSMContentModel)topAssociation.Child).ChildPSMAssociations;
            }
            foreach (PSMAssociation association in associations)
            {
                if (!association.IsNamed)
                {
                    if (association.Child is PSMClass && !((PSMClass)association.Child).Final && !association.IsNonTreeAssociation)
                    {
                        if (((PSMClass)association.Child).GetActualPSMAttributes().Count() > 0)
                        {
                            foreach (PSMAttribute att in ((PSMClass)association.Child).GetActualPSMAttributes())
                            {
                                if (att.Element && elementAttributes || !att.Element && !elementAttributes)
                                {
                                    resultAssociations.Add(association);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            resultAssociations.AddRange(associationsPropagatingAttributes(association, elementAttributes));
                        }
                    }
                    else
                    {
                        if (association.Child is PSMContentModel)
                        {
                            List <PSMAssociation> associationForContentModel = associationsPropagatingAttributes(association, elementAttributes);
                            if (associationForContentModel.Count > 0)
                            {
                                resultAssociations.Add(association);
                            }
                        }
                    }
                }
            }

            return(resultAssociations);
        }
Exemplo n.º 26
0
        protected override void TranslateAssociation(PSMAssociation association, DataGeneratorContext context)
        {
            TranslateComments(association, context);
            PathElements.Enqueue(association);

            uint count = association.Parent is PSMSchemaClass ? 1 : ChooseCardinality(association);

            if (count > association.Upper)
            {
                throw new Exception();
            }
            if (association.IsNamed && !(association.Child is PSMContentModel))
            {
                string elementName = namingSupport.NormalizeTypeName(association);

                for (int i = 0; i < count; i++)
                {
                    //XElement xmlElement = new XElement(ProjectNamespace + elementName);
                    XElement xmlElement = new XElement(elementName);
                    if (context.RootCreated)
                    {
                        context.CurrentElement.Add(xmlElement);
                    }
                    else
                    {
                        if (association.Lower != 1 || association.Upper != 1)
                        {
                            Log.AddErrorFormat(LogMessages.Cardinality_of_association__0__treated_as__1__1__because_it_is_a_root_association_, association);
                        }
                        context.RootCreated = true;
                        context.Document.Add(xmlElement);
                        context.CurrentElement = xmlElement;
                        AddSchemaArguments(xmlElement, context);
                    }

                    // set new current element
                    XElement prevCurrentElement = context.CurrentElement;
                    context.CurrentElement = xmlElement;
                    TranslateAssociationChild(association.Child, context);
                    // return current element to previous value
                    context.CurrentElement = prevCurrentElement;
                }
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    TranslateAssociationChild(association.Child, context);
                }
            }
            PathElements.Dequeue();
        }
Exemplo n.º 27
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(new AssociationCardinalityChangedInstance(candidate, oldVersion, newVersion)
            {
                OldLower = psmAssociationO.Lower,
                OldUpper = psmAssociationO.Upper,
                NewLower = psmAssociation.Lower,
                NewUpper = psmAssociation.Upper
            });
        }
        public override bool CanExecute()
        {
            if (ForceExecute)
            {
                return(true);
            }
            if (!(PSMComponentGuid != Guid.Empty &&
                  PIMComponentGuid == Guid.Empty || (Project.VerifyComponentType <PSMAssociation>(PSMComponentGuid) && Project.VerifyComponentType <PIMAssociation>(PIMComponentGuid))
                  ))
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }

            if (PIMComponentGuid == Guid.Empty)
            {
                return(true);
            }

            PIMAssociation pimAssoc = Project.TranslateComponent <PIMAssociation>(PIMComponentGuid);
            PSMAssociation psmAssoc = Project.TranslateComponent <PSMAssociation>(PSMComponentGuid);
            PSMClass       child    = psmAssoc.Child as PSMClass;

            if (child == null)
            {
                ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_CHILD_NOT_CLASS;
                return(false);
            }

            if (child.Interpretation == null)
            {
                ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_CMDERR_CANNOT_SET_INTERPRETATION_CHILD_NOT_INTERPRETED;
                return(false);
            }

            PSMClass intclass = psmAssoc.NearestInterpretedClass();

            if (intclass == null)
            {
                ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_NO_INTCLASS;
                return(false);
            }

            if (!(child.Interpretation as PIMClass).GetAssociationsWithIncludeInherited(intclass.Interpretation as PIMClass).Contains <PIMAssociation>(pimAssoc))
            {
                ErrorDescription = CommandErrors.CMDERR_NO_COMMON_INTERPRETED_ASSOCIATION;
                return(false);
            }
            return(true);
        }
Exemplo n.º 29
0
        public override bool CanExecute()
        {
            if (!(schemaGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMSchema>(schemaGuid) &&
                  associationGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMAssociation>(associationGuid)))
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }

            PSMAssociation a = Project.TranslateComponent <PSMAssociation>(associationGuid);

            if (a.Interpretation != null)
            {
                return(true);
            }

            if (a.Child != null && a.Child is PSMClass && (a.Child as PSMClass).Interpretation != null)
            {
                return(true);
            }

            PSMAssociationMember c = a.Child; //Uninterpreted child

            IEnumerable <PSMClass> unInterpretedSubClasses = c.UnInterpretedSubClasses(true);

            //PSM attributes within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .SelectMany <PSMClass, PSMAttribute>(cl => cl.PSMAttributes)
                .All <PSMAttribute>(at => at.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ATTRIBUTES_INTERPRETED;
                return(false);
            }

            //PSM associations within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .Select <PSMClass, PSMAssociation>(cl => cl.ParentAssociation)
                .All <PSMAssociation>(assoc => assoc.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ASSOCIATIONS_INTERPRETED;
                return(false);
            }

            return(true);
        }
        internal override void CommandOperation()
        {
            PSMAssociation    psmAssociation    = Project.TranslateComponent <PSMAssociation>(PSMComponentGuid);
            PIMAssociation    oldInterpretation = psmAssociation.Interpretation as PIMAssociation;
            PIMAssociationEnd childAE           = childAssociationEnd == Guid.Empty ? null : Project.TranslateComponent <PIMAssociationEnd>(childAssociationEnd);

            if (psmAssociation.UsedGeneralizations.Count > 0)
            {
                oldUsedGeneralizations.AddRange(psmAssociation.UsedGeneralizations.Select(g => g.ID));
            }
            if (psmAssociation.Interpretation == null)
            {
                oldPimComponentGuid    = Guid.Empty;
                oldChildAssociationEnd = Guid.Empty;
            }
            else
            {
                oldPimComponentGuid    = psmAssociation.Interpretation;
                oldChildAssociationEnd = psmAssociation.InterpretedAssociationEnd;
            }
            if (PIMComponentGuid != Guid.Empty)
            {
                psmAssociation.Interpretation            = Project.TranslateComponent <PIMAssociation>(PIMComponentGuid);
                psmAssociation.InterpretedAssociationEnd = childAE;

                //Get used generalizations on the child and the parent end
                psmAssociation.UsedGeneralizations.Clear();
                List <PIMGeneralization> gens = new List <PIMGeneralization>();

                PIMAssociation interpretation = psmAssociation.Interpretation as PIMAssociation;
                PIMClass       nicint         = psmAssociation.NearestInterpretedClass().Interpretation as PIMClass;
                PIMClass       childint       = (psmAssociation.Child as PSMClass).Interpretation as PIMClass;

                gens.AddRange(childint.GetGeneralizationPathTo(childAE.PIMClass));
                gens.AddRange(nicint.GetGeneralizationPathTo(interpretation.PIMAssociationEnds.Single(ae => ae != childAE).PIMClass));

                foreach (PIMGeneralization g in gens)
                {
                    psmAssociation.UsedGeneralizations.Add(g);
                }
            }
            else
            {
                psmAssociation.Interpretation            = null;
                psmAssociation.InterpretedAssociationEnd = null;
                psmAssociation.UsedGeneralizations.Clear();
            }
            Report = new CommandReport(CommandReports.SET_INTERPRETATION, psmAssociation, oldInterpretation, psmAssociation.Interpretation);
        }