Esempio n. 1
0
        /// <summary>
        /// Builds the full context from the given aTemplateConstraint forward. If the given aTemplateConstraint has a parent context then this will be built also,
        /// using the aPerspectiveConstraint. aPerspectiveConstraint is always the constraint we are requesting the context for. This ensures that we only traverse
        /// the perspective's children 1 time.
        /// </summary>
        /// <param name="aPrefix"></param>
        /// <param name="aTemplateConstraint"></param>
        /// <param name="aPerspectiveConstraint"></param>
        /// <param name="aIgnoreParent">Specifies whether to walk the the parent tree</param>
        /// <returns></returns>
        private static string CreateFullBranchedParentContext(string aPrefix, TemplateConstraint aTemplateConstraint, TemplateConstraint aPerspectiveConstraint = null, bool aIgnoreParent = false, bool isTarget = false)
        {
            string constraintParentContext = string.Empty;

            if (aTemplateConstraint.Parent != null && !aIgnoreParent)
            {
                constraintParentContext = CreateFullBranchedParentContext(aPrefix, aTemplateConstraint.ParentConstraint, aTemplateConstraint);
            }

            DocumentTemplateElement          element   = null;
            DocumentTemplateElementAttribute attribute = null;
            ContextParser parser = new ContextParser(aTemplateConstraint.Context);

            parser.Parse(out element, out attribute);

            if (attribute != null) //we are only looking for attributes
            {
                attribute.SingleValue = aTemplateConstraint.Value;
            }

            if (element != null)
            {
                element.IsBranch           = aTemplateConstraint.IsBranch;
                element.IsBranchIdentifier = aTemplateConstraint.IsBranchIdentifier;
                ConstraintToDocumentElementHelper.AddElementValueAndDataType(aPrefix, element, aTemplateConstraint);
            }

            ContextBuilder builder      = ContextBuilder.CreateFromElementAndAttribute(element, attribute, aPrefix);
            StringBuilder  childStrings = new StringBuilder();

            foreach (var child in aTemplateConstraint.ChildConstraints)
            {
                if (aPerspectiveConstraint == null || aPerspectiveConstraint.Id != child.Id) //since we call ourselves recursively, this ensures we only go down the path of the original caller once.
                {
                    if (child.IsBranchIdentifier == true)
                    {
                        childStrings.Append(CreateFullBranchedParentContext(aPrefix, child, aIgnoreParent: true));
                    }
                }
            }

            string context = builder.GetFullyQualifiedContextString() + childStrings;

            if (element != null && aTemplateConstraint.Parent != null)
            {
                if (element.IsBranchIdentifier || (element.IsBranch && !isTarget))
                {
                    context = "[" + context + "]";
                }
                else
                {
                    context = "/" + context;
                }
            }

            return(constraintParentContext + context);
        }
Esempio n. 2
0
        private AssertionLineBuilder CreateBranchedRootAssertionLineBuilderFromConstraint(IConstraint aConstraint)
        {
            AssertionLineBuilder             asb       = null;
            DocumentTemplateElement          element   = null;
            DocumentTemplateElementAttribute attribute = null;
            //parse the context
            ContextParser contextParser = new ContextParser(aConstraint.Context);

            contextParser.Parse(out element, out attribute);

            if (element != null)
            {
                asb = new AssertionLineBuilder(element, this.igTypePlugin.TemplateIdentifierXpath, this.igTypePlugin.TemplateVersionIdentifierXpath, this.prefix);
                if (aConstraint.ContainedTemplateId != null)
                {
                    var containedTemplate = this.tdb.Templates.Single(y => y.Id == aConstraint.ContainedTemplateId.Value);
                    if (containedTemplate != null)
                    {
                        asb.ContainsTemplate(containedTemplate.Oid);
                    }
                }
            }
            else if (attribute != null)
            {
                if (!string.IsNullOrEmpty(aConstraint.Value))
                {
                    attribute.SingleValue = aConstraint.Value;
                }
                asb = new AssertionLineBuilder(attribute, this.igTypePlugin.TemplateIdentifierXpath, this.igTypePlugin.TemplateVersionIdentifierXpath);
            }
            else
            {
                throw new Exception();
            }
            ConstraintToDocumentElementHelper.AddCardinality(aConstraint, asb);
            ConstraintToDocumentElementHelper.AddConformance(aConstraint, asb);

            foreach (var child in aConstraint.Children)
            {
                DocumentTemplateElement          childElement   = null;
                DocumentTemplateElementAttribute childAttribute = null;
                ContextParser childContextParser = new ContextParser(child.Context);
                childContextParser.Parse(out childElement, out childAttribute);

                if (child.IsBranchIdentifier)
                {
                    if (childElement != null)
                    {
                        asb.WithChildElementBuilder(CreateBranchedRootAssertionLineBuilderFromConstraint(child));
                    }
                    else if (childAttribute != null)
                    {
                        if (!string.IsNullOrEmpty(child.Value))
                        {
                            childAttribute.SingleValue = child.Value;
                        }
                        element.AddAttribute(childAttribute);
                    }
                }
            }

            if (aConstraint.IsBranch)
            {
                asb.MarkAsBranchRoot();
            }

            return(asb);
        }