示例#1
0
        internal XsltGeneratorContext CreateCopy(PSMElement newBodyNode)
        {
            XsltGeneratorContext newContext = CreateCopy();

            newContext.BodyNode = newBodyNode;
            return(newContext);
        }
示例#2
0
        internal XsltGeneratorContext CreateCopy(XmlElement newBodyElement)
        {
            XsltGeneratorContext newContext = CreateCopy();

            newContext.BodyElement = newBodyElement;
            return(newContext);
        }
示例#3
0
        /// <summary>
        /// <para>
        /// Returns expresion where <paramref name="attributes" /> are converted to their relative
        /// XPath expressions and joined with "," operator.
        /// </para>
        /// The XPath expressions are modified so that the part belonging to represented class
        /// is replaced with the part belonging to structural representative
        /// </summary>
        /// <example>
        /// sequence {Item/prod-red/@ProductSet Item/prod-red/@Category}
        /// is returned as  "Item/prod-blue/@ProductSet, Item/prod-blue/@Category"
        /// where prod-blue is a structural representative of prod-red.
        /// </example>
        public static XPathExpr AttributeListWithSRSubstitution(XsltGeneratorContext context, IEnumerable <NodeAttributeWrapper> attributes, IFromStructuralRepresentative structuralRepresentativeReplacement, bool onlyExisting, string concatOperator)
        {
            List <XPathExpr> modified = new List <XPathExpr>();

            foreach (PSMAttribute attribute in attributes.Inline())
            {
                if (onlyExisting && !attribute.ExistsInVersion(context.ChangeSet.OldVersion))
                {
                    continue;
                }
                XPathExpr expr;
                if (structuralRepresentativeReplacement != null)
                {
                    expr = GroupAwareProjectXPathWithSRSubstitution(context, attribute, structuralRepresentativeReplacement);
                }
                else
                {
                    expr = GroupAwareProjectXPath(context, attribute, context.ChangeSet.OldVersion);
                }

                modified.Add(expr);
            }

            return(new XPathExpr(modified.ConcatWithSeparator(concatOperator)));
        }
示例#4
0
        internal XsltGeneratorContext CreateCopy(Modifiers addedModifiers)
        {
            XsltGeneratorContext newContext = CreateCopy();

            newContext.Modifiers |= addedModifiers;
            return(newContext);
        }
示例#5
0
        internal XsltGeneratorContext CreateCopy(XmlElement newBodyElement, Modifiers addedModifiers)
        {
            XsltGeneratorContext newContext = CreateCopy();

            newContext.Modifiers  |= addedModifiers;
            newContext.BodyElement = newBodyElement;
            return(newContext);
        }
示例#6
0
        /// <summary>
        /// Converts path <paramref name="oldPath"/>
        /// into a path relative to <paramref name="context"/>.<see cref="XsltGeneratorContext.ProcessedPath"/>.
        /// (and also relative to <paramref name="context"/>.<see cref="XsltGeneratorContext.ContentGroupPath"/> if it is used).
        /// </summary>
        /// <param name="context">current generator context</param>
        /// <param name="oldPath">projected path</param>
        /// <returns>relative xpath expression</returns>
        public static XPathExpr GroupAwareProjectXPathWithoutAttributeCorrection(XsltGeneratorContext context, XPathExpr oldPath)
        {
            if (context.InGroup && oldPath.HasPrefix(context.ContentGroupPath))
            {
                oldPath = oldPath.InsertAfterPrefix(context.ContentGroupPath, "/$cg");
            }
            XPathExpr tmp = ProjectXPath(context.ProcessedPath, oldPath, context.InGroup);

            return(tmp);
        }
示例#7
0
        /// <summary>
        /// <para>
        /// Returns expresion where <paramref name="nodeContents" /> are converted to their relative
        /// XPath expressions and joined with "," operator.
        /// </para>
        /// The XPath expressions are modified so that the part belonging to represented class
        /// is replaced with the part belonging to structural representative
        /// </summary>
        /// <example>
        /// sequence {Item/prod-red/ProductSet Item/prod-red/Category}
        /// is returned as  "Item/prod-blue/ProductSet, Item/prod-blue/Category"
        /// where prod-blue is a structural representative of prod-red.
        /// </example>
        public static XPathExpr ElementsListWithSRSubstitution(XsltGeneratorContext context, IEnumerable <NodeElementWrapper> nodeContents, IFromStructuralRepresentative structuralRepresentativeReplacement, string concatOperator)
        {
            List <XPathExpr> modified = new List <XPathExpr>();

            foreach (PSMElement element in nodeContents.Inline().Where(c => c.ModelsElement()))
            {
                XPathExpr expr;
                if (structuralRepresentativeReplacement != null)
                {
                    expr = GroupAwareProjectXPathWithSRSubstitution(context, element, structuralRepresentativeReplacement);
                }
                else
                {
                    expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion);
                }
                modified.Add(expr);
            }

            return(new XPathExpr(modified.ConcatWithSeparator(concatOperator)));
        }
示例#8
0
        /// <summary>
        /// Converts path to <paramref name="psmElementNewVersion"/>
        /// into a path relative to <paramref name="context"/>.<see cref="XsltGeneratorContext.ProcessedPath"/>.
        /// (and also relative to <paramref name="context"/>.<see cref="XsltGeneratorContext.ContentGroupPath"/> if it is used).
        /// If context is in group (<see cref="XsltGeneratorContext"/>.<see cref="XsltGeneratorContext.InGroup"/>) which
        /// has group attributes and <paramref name="psmElementNewVersion"/> is one of these attributes, the returned path
        /// is modified to use the '$attributes' variable.
        /// </summary>
        /// <param name="context">current generator context</param>
        /// <param name="psmElementNewVersion">element for which the path is projected</param>
        /// <param name="oldVersion">old version, used to determine the path to <paramref name="psmElementNewVersion"/> in the
        /// old version of the diagram</param>
        /// <returns>relative xpath expression</returns>
        public static XPathExpr GroupAwareProjectXPath(XsltGeneratorContext context, PSMElement psmElementNewVersion, Version oldVersion)
        {
            XPathExpr oldPath = ((PSMElement)psmElementNewVersion.GetInVersion(oldVersion)).XPathE();

            if (context.InGroup && oldPath.HasPrefix(context.ContentGroupPath))
            {
                oldPath = oldPath.InsertAfterPrefix(context.ContentGroupPath, "/$cg");
            }
            XPathExpr tmp = ProjectXPath(context.ProcessedPath, oldPath, context.InGroup);

            if (context.InGroup && context.ContentGroupAttributes != null && psmElementNewVersion is PSMAttribute &&
                context.ContentGroupAttributes.Contains((PSMAttribute)psmElementNewVersion))
            {
                if (tmp.ToString().StartsWith(XPathExpr.CurrentGroupVariableExpr))
                {
                    tmp = new XPathExpr(tmp.ToString().Replace(XPathExpr.CurrentGroupVariableExpr, "$attributes"));
                }
            }

            return(tmp);
        }
示例#9
0
        internal XsltGeneratorContext CreateCopy()
        {
            XsltGeneratorContext newContext = new XsltGeneratorContext(this.ChangeSet, this.BodyNode)
            {
                BodyElement            = this.BodyElement,
                Modifiers              = this.Modifiers,
                CurrentContentNode     = this.CurrentContentNode,
                Template               = this.Template,
                ProcessedPath          = this.ProcessedPath,
                CurrentAttribute       = this.CurrentAttribute,
                CurrentContentGroup    = this.CurrentContentGroup,
                InGroup                = this.InGroup,
                ContentGroupAttributes = this.ContentGroupAttributes,
                CurrentStructuralRepresentativeElements   = this.CurrentStructuralRepresentativeElements,
                CurrentStructuralRepresentativeAttributes = this.CurrentStructuralRepresentativeAttributes,
                CurrentChoiceElements   = this.CurrentChoiceElements,
                CurrentChoiceAttributes = this.CurrentChoiceAttributes,
                CurrentUnionElements    = this.CurrentUnionElements,
                CurrentUnionAttributes  = this.CurrentUnionAttributes
            };

            return(newContext);
        }
示例#10
0
        /// <summary>
        /// Performs <see cref="GroupAwareProjectXPath"/> and substitutes steps in the result path according
        /// to structural representative information. (So the path is relative to the structural representative)
        /// </summary>
        /// <param name="context">The generator context.</param>
        /// <param name="element">The element.</param>
        /// <param name="structuralRepresentativeReplacement">The structural representative replacement.</param>
        /// <returns></returns>
        public static XPathExpr GroupAwareProjectXPathWithSRSubstitution(XsltGeneratorContext context, PSMElement element, IFromStructuralRepresentative structuralRepresentativeReplacement)
        {
            XPathExpr expr;

            if (structuralRepresentativeReplacement != null)
            {
                var cp = context.ProcessedPath;

                //if (PSMTreeIterator.AreInTheSamePSMTree(structuralRepresentativeReplacement.RepresentedPSMClass, structuralRepresentativeReplacement.StructuralRepresentative))


                PSMElement representedOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.RepresentedPSMClass.GetInVersion(context.ChangeSet.OldVersion));
                PSMElement structuralRepresentativeOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.StructuralRepresentative.GetInVersion(context.ChangeSet.OldVersion));

                if (representedOldAnc != null)
                {
                    context.ProcessedPath = GetXPathForNode(representedOldAnc, context.ChangeSet.OldVersion);
                }
                else
                {
                    context.ProcessedPath = new XPathExpr("<virt-root>");
                    if (context.InGroup)
                    {
                        context.ProcessedPath = context.ProcessedPath.Append("/$cg");
                    }
                }

                string from = representedOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(representedOldAnc) : null;

                string to = structuralRepresentativeOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(structuralRepresentativeOldAnc) : null;

                XPathExpr e = null;

                if (from != null && to != null &&
                    !(context.ProcessedPath.ToString().EndsWith(from) && cp.ToString().EndsWith(to)))
                {
                    e = ProjectXPath(cp, context.ProcessedPath, false);
                    if (!XPathExpr.IsNullOrEmpty(e) && !String.IsNullOrEmpty(to) && !String.IsNullOrEmpty(from))
                    {
                        if (e.ToString().Contains(from))
                        {
                            e = new XPathExpr(e.ToString().Replace(from, to));
                        }
                    }
                }
                expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion);

                if (!XPathExpr.IsNullOrEmpty(e))
                {
                    // ReSharper disable PossibleNullReferenceException
                    expr = e.Append("/" + expr);
                }
                // ReSharper restore PossibleNullReferenceException

                context.ProcessedPath = cp;
            }
            else
            {
                expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion);
            }

            return(expr);
        }