Example #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 string CreateFullBranchedParentContext(TemplateConstraint aTemplateConstraint, TemplateConstraint aPerspectiveConstraint = null, bool aIgnoreParent = false, bool isTarget = false)
        {
            string constraintParentContext = string.Empty;

            if (aTemplateConstraint.Parent != null && !aIgnoreParent)
            {
                constraintParentContext = CreateFullBranchedParentContext(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(this.prefix, element, aTemplateConstraint);
            }

            ContextBuilder builder      = ContextBuilder.CreateFromElementAndAttribute(element, attribute, this.prefix);
            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(child, aIgnoreParent: true));
                    }
                }
            }

            string context = builder.GetFullyQualifiedContextString() + childStrings;

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

            return(constraintParentContext + context);
        }
Example #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)
            {
                if (!string.IsNullOrEmpty(aConstraint.Value))
                {
                    element.Value = aConstraint.Value;
                }

                asb = new AssertionLineBuilder(this.tdb, element, this.igType, this.igTypeSchema);

                var containedTemplates = (from tcr in aConstraint.References
                                          join t in this.allTemplates on tcr.ReferenceIdentifier equals t.Oid
                                          where tcr.ReferenceType == ConstraintReferenceTypes.Template
                                          select new { Identifier = t.Oid, t.PrimaryContextType }).ToList();

                foreach (var containedTemplate in containedTemplates)
                {
                    asb.ContainsTemplate(containedTemplate.Identifier, containedTemplate.PrimaryContextType);
                }
            }
            else if (attribute != null)
            {
                if (!string.IsNullOrEmpty(aConstraint.Value))
                {
                    attribute.SingleValue = aConstraint.Value;
                }

                asb = new AssertionLineBuilder(this.tdb, attribute, this.igType, this.igTypeSchema);
            }
            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);
        }