/// <summary> /// Returns attributes under a node (when called for a superordinate component, attributes /// from all subordinate PSM classes without element labels are included in the result too) /// </summary> /// <param name="node">node where to search for attributes</param> /// <returns></returns> public static IEnumerable <NodeAttributeWrapper> GetAttributesUnderNode(this PSMElement node) { List <NodeAttributeWrapper> result = new List <NodeAttributeWrapper>(); GetAttributesUnderNode(node, true, ref result); return(result); }
private void ConvertPSMElement(PSMElement element, ViewHelper viewHelper) { if (element is PSMClass) { ConvertPSMClass((PSMClass)element, (PSMElementViewHelper)viewHelper); } else if (element is PSMAssociation) { ConvertPSMAssociation((PSMAssociation)element, (PSMAssociationViewHelper)viewHelper); } else if (element is PSMContentContainer) { ConvertPSMContentContainer((PSMContentContainer)element, (PSMElementViewHelper)viewHelper); } else if (element is PSMContentChoice) { ConvertPSMContentChoice((PSMContentChoice)element, (PSMElementViewHelper)viewHelper); } else if (element is PSMClassUnion) { ConvertPSMClassUnion((PSMClassUnion)element, (PSMElementViewHelper)viewHelper); } else if (element is PSMAttributeContainer) { ConvertPSMAttributeContainer((PSMAttributeContainer)element, (PSMElementViewHelper)viewHelper); } else if (element is Generalization) { } else { throw new NotImplementedException(string.Format("Member EvoXExport.ConvertPSMElement not implemented for type {0}.", element.GetType().Name)); } }
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); }
public bool IsUnderContentGroup(PSMElement element, out PSMElement groupElement) { //Debug.Assert(PSMTreeIterator.ModelsElement(element)); groupElement = null; if (element.ModelsElement() /* && !(element is PSMAttribute) */) { return(false); } PSMTreeIterator it = new PSMTreeIterator(element); while (it.CanGoToParent()) { it.GoToParent(); if (IsContentGroupNode(it.CurrentNode)) { groupElement = it.CurrentNode; return(true); } if (it.CurrentNodeModelsElement()) { return(false); } } return(false); }
public string GenerateSubtree(PSMElement element) { DataGeneratorContext c = new DataGeneratorContext(); if (element is PSMClass) { TranslateClass((PSMClass)element, c); } else if (element is PSMAssociation) { TranslateAssociation((PSMAssociation)element, c); } else if (element is PSMClassUnion) { TranslateClassUnion((PSMClassUnion)element, c); } else if (element is PSMContentChoice) { TranslateContentChoice((PSMContentChoice)element, c); } else if (element is PSMContentContainer) { TranslateContentContainer((PSMContentContainer)element, c); } else if (element is PSMAttributeContainer) { TranslateAttributeContainer((PSMAttributeContainer)element, c); } else if (element is PSMAttribute) { TranslateAttributeAsElement((PSMAttribute)element, c); } return(c.Document.InnerXml); }
internal XsltGeneratorContext CreateCopy(PSMElement newBodyNode) { XsltGeneratorContext newContext = CreateCopy(); newContext.BodyNode = newBodyNode; return(newContext); }
private static IEnumerable <FollowedPath> FollowPath(PSMElement element, FollowedPath followedPath) { List <FollowedPath> result = new List <FollowedPath>(); PSMTreeIterator it = new PSMTreeIterator(element); followedPath.Add(element); while (it.CanGoToParent()) { it.GoToParent(); PSMClass psmClass = it.CurrentNode as PSMClass; if (psmClass != null && psmClass.IsReferencedFromStructuralRepresentative()) { foreach (PSMClass representative in psmClass.Diagram.DiagramElements.Keys.OfType <PSMClass>().Where(rClass => rClass.RepresentedPSMClass == psmClass)) { result.AddRange(FollowPath(representative, followedPath.Copy())); } } followedPath.Add(it.CurrentNode); } if (followedPath.Last() is PSMClass && ((PSMClass)followedPath.Last()).HasElementLabel) { result.Add(followedPath); } return(result); }
public static uint GetLowerMultiplicityOfContentElement(PSMElement node) { { PSMAssociationChild c = node as PSMAssociationChild; if (c != null) { if (c.ParentUnion != null) { return(1); } if (c.ParentAssociation != null) { Debug.Assert(c.ParentAssociation.Lower != null); return(c.ParentAssociation.Lower.Value); } else { return(1); // root class } } } if (node is PSMContentContainer) { return(1); } if (node is PSMAttribute) { Debug.Assert(((PSMAttribute)node).Lower != null); return(((PSMAttribute)node).Lower.Value); } // should never get here... throw new ArgumentException(); }
/// <summary> /// returns the path to the closest ancestor of <see cref="addedNode"/> /// that existed in the previous version. /// </summary> /// <param name="addedNode">The added node.</param> /// <param name="oldVersion">The old version.</param> /// <returns>xpath expression</returns> private static XPathExpr GetXPathForAddedNode(PSMElement addedNode, Version oldVersion) { PSMTreeIterator it = new PSMTreeIterator(addedNode); PSMElement ancestorOldVersion = null; while (ancestorOldVersion == null) { if (it.CanGoToParent()) { it.GoToParent(); } else { return(null); } it.CurrentNode = it.GetSignificantAncestorOrSelf(); if (it.CurrentNode != null) { ancestorOldVersion = (PSMElement)it.CurrentNode.GetInVersion(oldVersion); } else { break; } } return(ancestorOldVersion != null?ancestorOldVersion.XPathE() : null); }
/// <summary> /// Gets the nearest PSMClass on the path from <paramref name="E"/> to a root /// </summary> /// <param name="E">The PSMElement to start the search in</param> /// <returns>PSMClass that is the parent</returns> public static PSMClass GetPSMClassParent(this PSMElement E) { PSMSuperordinateComponent parent; if (E is PSMSubordinateComponent) { parent = (E as PSMSubordinateComponent).Parent; } else if (E is PSMClass) { parent = (E as PSMClass).ParentAssociation == null ? null : (E as PSMClass).ParentAssociation.Parent; } else { parent = null; } while (parent != null && !(parent is PSMClass)) { if (parent is PSMSubordinateComponent) { parent = (parent as PSMSubordinateComponent).Parent; } else { parent = null; } } return(parent as PSMClass); }
public static UnlimitedNatural GetUpperMultiplicityOfContentElement(PSMElement node) { { PSMClass c = node as PSMClass; if (c != null) { if (c.ParentUnion != null) { throw new NotImplementedException("Can't handle class union yet. "); } if (c.ParentAssociation != null) { return(c.ParentAssociation.Upper);//.Value; } else { return(1); // root class } } } if (node is PSMContentContainer) { return(1); } if (node is PSMAttribute) { return(((PSMAttribute)node).Upper.Value); } // should never get here... throw new ArgumentException("Node is not correct significant node."); }
/// <summary> /// Gets all leaf PSMClasses in the subtree of <paramref name="E"/> /// </summary> /// <param name="E">Root of the searched subtree</param> /// <returns>List of PSMClasses that are leaves (in the sense of PSMClasses only) of the subtree of <paramref name="E"/></returns> public static List <PSMClass> GetAllPSMClassLeaves(this PSMElement E) { List <PSMClass> AllSubClasses = E.GetAllPSMSubClasses(); List <PSMClass> Leaves = AllSubClasses.Where <PSMClass>(C => C.GetAllPSMSubClasses().Count == 0).ToList <PSMClass>(); return(Leaves); }
/// <summary> /// Gets all PSMElements on the path from <paramref name="E"/> to the root of the PSM Diagram /// </summary> /// <param name="E">The PSMElement to start the search in</param> /// <returns>List of PSMElement ancestors</returns> public static List <PSMElement> GetAllAncestors(this PSMElement E) { List <PSMElement> Ancestors = new List <PSMElement>(); PSMElement current = E; while (current != null) { if (current is PSMSubordinateComponent) { current = (current as PSMSubordinateComponent).Parent; } else if (current is PSMClass) { current = (current as PSMClass).ParentAssociation; if (current != null) { Ancestors.Add(current); current = (current as PSMAssociation).Parent; } } if (current != null) { Ancestors.Add(current); } } return(Ancestors); }
/// <summary> /// Marks nodes blue or red if there is a change in the represented /// class/subtree. /// </summary> private void FixStructuralRepresentatives() { PSMTreeIterator.NodeMarker additionalNodeMarker = IsContentGroupNode; foreach (PSMClass sr in Diagram.DiagramElements.Keys.OfType <PSMClass>().Where(c => c.IsStructuralRepresentative)) { foreach (PSMTreeIterator.NodeMarker nodeMarker in new[] { null, additionalNodeMarker }) { PSMElement representedClassSignificantAncestor = PSMTreeIterator.GetSignificantAncestorOrSelf(sr.RepresentedPSMClass, nodeMarker); PSMElement structuralRepresentativeSignificantAncestor = PSMTreeIterator.GetSignificantAncestorOrSelf(sr, nodeMarker); if (redNodes.Contains(representedClassSignificantAncestor)) { redNodes.AddIfNotContained(structuralRepresentativeSignificantAncestor); blueNodes.Remove(structuralRepresentativeSignificantAncestor); greenNodes.Remove(structuralRepresentativeSignificantAncestor); MakeAncestorsBlue(structuralRepresentativeSignificantAncestor, nodeMarker); } else if (blueNodes.Contains(representedClassSignificantAncestor) && !redNodes.Contains(structuralRepresentativeSignificantAncestor)) { blueNodes.AddIfNotContained(structuralRepresentativeSignificantAncestor); greenNodes.Remove(structuralRepresentativeSignificantAncestor); MakeAncestorsBlue(structuralRepresentativeSignificantAncestor, nodeMarker); } } } }
public static bool EncompassesAttributesForParentSignificantNode(this PSMElement child) { PSMClass childClass = child as PSMClass; if (childClass != null && !childClass.HasElementLabel) { if (childClass.PSMAttributes.Count > 0) { return(true); } if (childClass.IsStructuralRepresentative && childClass.RepresentedPSMClass.EncompassesAttributesForParentSignificantNode()) { return(true); } return(childClass.Components.Any(EncompassesAttributesForParentSignificantNode)); } if (child is PSMClassUnion) { return(((PSMClassUnion)child).Components.Any(EncompassesAttributesForParentSignificantNode)); } if (child is PSMAssociation) { return(EncompassesAttributesForParentSignificantNode(((PSMAssociation)child).Child)); } return(false); }
public static PSMElement GetSignificantAncestorOrSelf(PSMElement element, NodeMarker additionalSignificantNodeMarker) { PSMTreeIterator helper = new PSMTreeIterator(element); while (!((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) && helper.CanGoToParent()) { helper.GoToParent(); } if ((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) { return(helper.CurrentNode); } //else if (!helper.CanGoToParent()) // return helper.CurrentNode; else { return(null); } }
private void CategorizeSubtree(PSMTreeIterator iterator) { if (iterator.CurrentNodeModelsElement() || IsContentGroupNode(iterator.CurrentNode)) { significantNodes.Add(iterator.CurrentNode); bool isRed = false; if ((changesByTargetSignificantNode.ContainsKey(iterator.CurrentNode) && !changesByTargetSignificantNode[iterator.CurrentNode].All(c => c.Element == iterator.CurrentNode && c is ICanBeIgnoredOnTarget)) || GetState(iterator.CurrentNode) == EContentPlacementState.Added) { redNodes.Add(iterator.CurrentNode); isRed = true; } PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; PSMElement firstFoundRedChild = iterator.GetChildNodes().FirstOrDefault(child => (child is PSMAssociation) && redNodes.Contains(((PSMAssociation)child).Child) && IsContentGroupNode(((PSMAssociation)child).Child)); if (!isRed && firstFoundRedChild != null) { isRed = true; int index = redNodes.IndexOf(((PSMAssociation)firstFoundRedChild).Child); redNodes.Insert(index, iterator.CurrentNode); } if (!isRed) { if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { blueNodes.Add(iterator.CurrentNode); } else { greenNodes.Add(iterator.CurrentNode); } } } else { PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { insignificantBlueNodes.Add(iterator.CurrentNode); } } }
public static bool FullAttributeTemplateNeeded(PSMElement element, EvolutionChangeSet changeSet) { List <NodeAttributeWrapper> allAttributes = new List <NodeAttributeWrapper>(); List <NodeAttributeWrapper> represenetedAttributes = element.GetRepresentedAttributes(); IEnumerable <NodeAttributeWrapper> nodeContents = element.GetAttributesUnderNode(); allAttributes.AddRange(represenetedAttributes); allAttributes.AddRange(nodeContents); return(allAttributes.Count() > 0 && changeSet.AttributesInvalidated(element) /*&& allAttributes.Inline().Any(e => PSMTreeIterator.GetLowerMultiplicityOfContentElement(e) != 0)*/); }
private void MakeAncestorsBlue(PSMElement node, PSMTreeIterator.NodeMarker nodeMarker) { foreach (PSMElement ancestor in PSMTreeIterator.SignificantAncestors(node, nodeMarker)) { if (!redNodes.Contains(ancestor)) { blueNodes.AddIfNotContained(ancestor); greenNodes.Remove(ancestor); } } }
public static bool FullElementsTemplateNeeded(PSMElement element, EvolutionChangeSet changeSet) { List <NodeElementWrapper> allContent = new List <NodeElementWrapper>(); List <NodeElementWrapper> represenetedContents = element.GetRepresentedElements(); List <NodeElementWrapper> nodeContents = element.GetSubtreeElements(); allContent.AddRange(represenetedContents); allContent.AddRange(nodeContents); return(allContent.Count() > 0 && changeSet.ContentInvalidated(element) /*&& allContent.Inline().Any(e => PSMTreeIterator.GetLowerMultiplicityOfContentElement(e) != 0)*/); }
static List <PSMElement> GetAllPSMSubElements(this PSMElement E, bool IncludeCurrent) { List <PSMElement> OC = new List <PSMElement>(); GetSubElements(OC, E); if (!IncludeCurrent) { OC.Remove(E); } return(OC); }
/// <summary> /// Returns all XPath expressions where PSM element can appear in an XML document. Each structural /// representative in a diagram can contribute with one expression, where an element can appear. /// </summary> /// <param name="element"></param> /// <returns></returns> public static IEnumerable <XPathExpr> PathsWhereElementAppears(PSMElement element) { List <FollowedPath> result = new List <FollowedPath>(); FollowedPath followedPath = new FollowedPath(); result.AddRange(FollowPath(element, followedPath)); return(from p in result where p.Count > 0 && PSMTreeIterator.IsInSignificantSubtree(p.Last()) select p.ToXPath()); }
public void SetToRoot(int i) { if (Diagram.Roots.Count == 0) { throw new PSMDiagramException("Diagram has no roots", Diagram); } else if (Diagram.Roots.Count - 1 < i) { throw new PSMDiagramException("Index out of range", Diagram); } CurrentNode = Diagram.Roots[i]; }
public static bool EncompassesAttributesForParentSignificantNodeOrSelf(this PSMElement node) { if (node is PSMClass) { PSMClass c = (PSMClass)node; if (c.PSMAttributes.Count > 0) { return(true); } } return(node.EncompassesAttributesForParentSignificantNode()); }
/// <summary> /// Gets path to a content grop /// </summary> /// <param name="containingClass">The containing class of the group.</param> /// <param name="oldVersion">The old version.</param> /// <returns>path to a content group</returns> private static XPathExpr GetXPathForContentGroup(PSMElement containingClass, Version oldVersion) { PSMElement groupElementOldVersion = (PSMElement)containingClass.GetInVersion(oldVersion); if (groupElementOldVersion != null) { return(groupElementOldVersion.XPathE()); } else { return(GetXPathForAddedNode(containingClass, oldVersion).Append("/$cg")); } }
/// <summary> /// Gets the X path for a node. If the node existed in the previous version, the old /// path is returned. For new nodes it returns the path to the closest ancestor /// that existed in the previous version. /// </summary> /// <param name="node">The node.</param> /// <param name="oldVersion">The old version.</param> /// <returns>xpath expression</returns> public static XPathExpr GetXPathForNode(PSMElement node, Version oldVersion) { PSMElement nodeOldVersion = (PSMElement)node.GetInVersion(oldVersion); if (nodeOldVersion != null) { return(nodeOldVersion.XPathE()); } else { return(GetXPathForAddedNode(node, oldVersion)); } }
private PSMElement groupingFuncBySignificantNode(EvolutionChange change) { PSMElement target = (change is ISubelementChange) ? ((ISubelementChange)change).ChangedSubelement : change.Element; if (target.ModelsElement()) { return(target); } else { return(PSMTreeIterator.GetSignificantAncestorOrSelf(target, IsContentGroupNode)); } }
public IMultiplicityChange GetMultiplicityChange(PSMElement psmElement) { if (psmElement is PSMAssociation) { AssociationMultiplicityChange find = this.OfType <AssociationMultiplicityChange>().FirstOrDefault(ec => ec.Association == psmElement); return(find); } else { Debug.Assert(changesByTarget[psmElement].Count(c => c is IMultiplicityChange) <= 1); return(changesByTarget[psmElement].OfType <IMultiplicityChange>().FirstOrDefault()); } }
public static void CheckPsmElementsDiagram(PSMDiagram diagram) { foreach (Element element in diagram.DiagramElements.Keys) { PSMElement psmElement = element as PSMElement; if (psmElement != null) { if (psmElement.Diagram != diagram) { throw new ModelConsistencyException(string.Format("Element {0} has wrong diagram.", psmElement)); } } } }
public static IEnumerable <PSMElement> SignificantAncestors(PSMElement element, NodeMarker nodeMarker) { List <PSMElement> result = new List <PSMElement>(); PSMTreeIterator it = new PSMTreeIterator(element); while (it.CanGoToParent()) { it.GoToParent(); PSMElement significantAncestorOrSelf = it.GetSignificantAncestorOrSelf(nodeMarker); result.AddIfNotContained(significantAncestorOrSelf); } return(result); }