The NodeIndex class builds an index of the elements that comprise a DOM tree to allow subsequent queries to be efficiently executed.
A typical DOM document instance performs an expensive in-order traversal of the DOM tree every time the GetElementsByName method is called. This class does a one off traversal on construction and then uses the cached results to return XmlNodeList instances.

The NodeIndex also indexes 'id' attributes as the DOM has been found to be unreliable at indexing these during post parse schema validation.

Since TFP 1.2 the NodeIndex also attempts to capture schema type information for the XmlDocument as it explores it. Derivation relationships between types are determined and cached as calls to GetElementsByType are made.

        /// <summary>
        /// Evaluates this <see cref="Precondition"/> against the contents of the
        /// indicated <see cref="NodeIndex"/>.
        /// </summary>
        /// <param name="nodeIndex">The <see cref="NodeIndex"/> of a <see cref="XmlDocument"/>.</param>
        /// <param name="cache">A cache of previously evaluated precondition results.</param>
        /// <returns>A <see cref="bool"/> value indicating the applicability of this
        /// <see cref="Precondition"/> to the <see cref="XmlDocument"/>.</returns>
        public override bool Evaluate(NodeIndex nodeIndex, Dictionary<Precondition, bool> cache)
        {
            foreach (string rootElement in release.RootElements) {
                XmlNodeList list = nodeIndex.GetElementsByName (rootElement);

                if (list.Count == 1) {
                    XmlElement	fpml = list [0] as XmlElement;

                    if (fpml.LocalName.Equals("FpML"))
                        return (fpml.GetAttribute ("version").Equals (release.Version));
                    else
                        return (fpml.GetAttribute ("fpmlVersion").Equals (release.Version));
                }
            }
            return (false);
        }
        /// <summary>
        /// Evaluates this <see cref="Precondition"/> against the contents of the
        /// indicated <see cref="NodeIndex"/>.
        /// </summary>
        /// <param name="nodeIndex">The <see cref="NodeIndex"/> of a <see cref="XmlDocument"/></param>
        /// <param name="cache">A cache of previously evaluated precondition results.</param>
        /// <returns>A <see cref="bool"/> value indicating the applicability of this
        /// <see cref="Precondition"/> to the <see cref="XmlDocument"/>.</returns>
        public override bool Evaluate(NodeIndex nodeIndex, Dictionary<Precondition, bool> cache)
        {
            if (nodeIndex.HasTypeInformation) {
                string ns = FpMLRuleSet.DetermineNamespace (nodeIndex);

                foreach (string type in types) {
                    XmlNodeList list = nodeIndex.GetElementsByType (ns, type);

                    if ((list != null) && (list.Count > 0)) return (true);
                }
            }
            else {
                foreach (String element in elements) {
                    XmlNodeList list = nodeIndex.GetElementsByName (element);

                    if ((list != null) && (list.Count > 0)) return (true);
                }
            }
            return (false);
        }
        private static bool Rule02(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in list) {
                XmlElement	    startDate	= XPath.Path (context, "novation", "firstPeriodStartDate");
                XmlAttribute	href;

                if ((startDate == null) || (href = startDate.GetAttributeNode ("href"))== null) continue;

                XmlElement		target	= nodeIndex.GetElementById (href.Value);

                if ((target == null) || !target.LocalName.Equals("party")) {
                    errorHandler ("305", context,
                        "The @href attribute on the firstPeriodStartDate must reference a party",
                        name, href.Value);

                    result = false;
                }
            }
            return (result);
        }
 internal bool PerformValidation(NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Validate (nodeIndex, errorHandler));
 }
示例#5
0
 /// <summary>
 /// Determines if the <b>Rule</b> applies to a document but evaluating
 /// its <see cref="Precondition"/>.
 /// </summary>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the document.</param>
 /// <returns><c>true</c> if the <b>Rule</b> applies, <c>false</c> otherwise.</returns>
 public bool AppliesTo(NodeIndex nodeIndex)
 {
     return (precondition.Evaluate (nodeIndex, new Dictionary<Precondition,bool> ()));
 }
        // --------------------------------------------------------------------
        private static bool Rule01(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            if (nodeIndex.HasTypeInformation)
                return (Rule01 (name, nodeIndex, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "PricingDataPointCoordinate"), errorHandler));

            return (Rule01 (name, nodeIndex, nodeIndex.GetElementsByName ("coordinate"), errorHandler));
        }
        // --------------------------------------------------------------------
        private static bool Rule02(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            if (nodeIndex.HasTypeInformation)
                return (Rule02 (name, nodeIndex, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "PaymentCalculationPeriod"), errorHandler));

            return (Rule02 (name, nodeIndex, nodeIndex.GetElementsByName ("paymentCalculationPeriod"), errorHandler));
        }
示例#8
0
        // --------------------------------------------------------------------
        private static bool Rule14(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                foreach (XmlElement seller in XPath.Paths (context, "protectionTerms", "creditEvents", "creditEventNotice", "notifyingParty", "sellerPartyReference")) {
                    if (Equal (seller.GetAttribute ("href"),
                            XPath.Path (context, "generalTerms", "sellerPartyReference").GetAttribute ("href")))
                        continue;

                    errorHandler ("305", context,
                        "If protectionTerms/creditEvents/creditEventNotice/notifyingParty/sellerPartyReference " +
                        "is present, its @href attribute must match that of generalTerms/sellerPartyReference",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#9
0
        // --------------------------------------------------------------------
        private static bool Rule12(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("referenceInformation")) {
                if (Exists (context ["referencePrice"])) {
                    if (GreaterOrEqual (context ["referencePrice"], 0.0))
                        continue;

                    errorHandler ("305", context,
                        "If referencePrice is present it must not have a negative " +
                        "value",
                        name, context ["referencePrice"].InnerText);

                    result = false;
                }
            }
            return (result);
        }
示例#10
0
 // --------------------------------------------------------------------
 private static bool Rule37(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule37 (name, nodeIndex.GetElementsByName ("cashSettlementTerms"), errorHandler));
 }
示例#11
0
 // --------------------------------------------------------------------
 private static bool Rule36(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule36 (name, XPath.Paths (nodeIndex.GetElementsByName ("creditEvents"), "creditEventNotice", "publiclyAvailableInformation"), errorHandler));
 }
示例#12
0
 // --------------------------------------------------------------------
 private static bool Rule35(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule35 (name, nodeIndex.GetElementsByName ("creditEvents"), errorHandler));
 }
示例#13
0
 // --------------------------------------------------------------------
 private static bool Rule34(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule34 (name, nodeIndex.GetElementsByName ("deliverableObligations"), errorHandler));
 }
示例#14
0
 // --------------------------------------------------------------------
 private static bool Rule33(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule33 (name, nodeIndex.GetElementsByName ("periodicPayment"), errorHandler));
 }
示例#15
0
        // --------------------------------------------------------------------
        private static bool Rule30(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                XmlElement	paymentDate;
                XmlElement	terminationDate;

                if (And (
                    Exists (paymentDate = XPath.Path (context, "feeLeg", "periodicPayment", "lastRegularPaymentDate")),
                    Exists (terminationDate = XPath.Path (context, "generalTerms", "scheduledTerminationDate", "adjustableDate", "unadjustedDate")))) {
                    if (Less (paymentDate, terminationDate)) continue;

                    errorHandler ("305", context,
                        "Last regular periodic payment date '" + paymentDate.InnerText + "' " +
                        "must be before the termination date '" + terminationDate.InnerText + "'",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#16
0
        // --------------------------------------------------------------------
        private static bool Rule10(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("referenceInformation")) {
                string			primaryReference;
                string			primaryId;

                foreach (XmlElement primary in XPath.Paths (context, "referenceObligation", "guarantorReference")) {
                    if (Equal (
                            primaryReference = primary.GetAttribute ("href"),
                            primaryId		 = context ["referenceEntity"].GetAttribute ("id")))
                        continue;

                    errorHandler ("305", context,
                        "Primary obligor reference '" + primaryReference +
                        "' should point to the reference entity ' " + primaryId + "'",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#17
0
        // --------------------------------------------------------------------
        private static bool Rule11(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement trade in nodeIndex.GetElementsByName ("trade")) {
                if (IsIsda2003 (trade) && IsLongForm (trade)) {
                    XmlElement	context = XPath.Path (trade, "creditDefaultSwap", "generalTerms", "referenceInformation") as XmlElement;

                    if (Exists (XPath.Path (context, "allGuarantees"))) continue;

                    errorHandler ("305", context,
                        "allGuarantees element missing in protection terms",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#18
0
        // --------------------------------------------------------------------
        private static bool Rule41(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement		tranche		= XPath.Path (context, "indexReferenceInformation", "tranche");
                XmlElement		delivery	= XPath.Path (context, "modifiedEquityDelivery");

                if ((tranche == null) && (delivery != null)) {
                    errorHandler ("305", context,
                        "If indexReferenceInformation/tranche is not present then modifiedEquityDelivery must not be present.",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#19
0
        // --------------------------------------------------------------------
        private static bool Rule13(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                foreach (XmlElement buyer in XPath.Paths (context, "protectionTerms", "creditEvents", "creditEventNotice", "notifyingParty", "buyerPartyReference")) {
                    string		buyerName;
                    string		referenceName;

                    if (Equal (
                            buyerName = buyer.GetAttribute ("href"),
                            referenceName = XPath.Path (context, "generalTerms", "buyerPartyReference").GetAttribute ("href")))
                        continue;

                    errorHandler ("305", context,
                        "Credit event notice references buyer party reference " + buyerName +
                        " but general terms references " + referenceName,
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#20
0
        // --------------------------------------------------------------------
        private static bool Rule42(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement	basket			= XPath.Path (context, "basketReferenceInformation");
                XmlElement	substitution	= XPath.Path (context, "substitution");

                if ((basket == null) && (substitution != null)) {
                    errorHandler ("305", context,
                        "If basketReferenceInformation is not present then substitution must not be present.",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
示例#21
0
        // --------------------------------------------------------------------
        private static bool Rule16(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result = true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                if (Implies (
                        And (
                            Equal (
                                Count (XPath.Paths (context, "generalTerms", "referenceInformation", "referenceObligation")), 1),
                            Exists (XPath.Path (context, "cashSettlementTerms", "valuationDate", "multipleValuationDates"))),
                        Or (
                            Equal (
                                XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                "AverageMarket"),
                            Or (
                                Equal (
                                    XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                    "Highest"),
                                Equal (
                                    XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                    "AverageHighest")))))
                    continue;

                errorHandler ("305", context,
                    "If there is exactly one generalTerms/referenceInformation/referenceObligation " +
                    "and cashSettlementTerms/valuationDate/multipleValuationDates occurs " +
                    "then the value of cashSettlementTerms/valuationMethod must be " +
                    "AverageMarket, Highest or AverageHighest",
                    name, XPath.Path (context, "cashSettlementTerms", "valuationMethod").InnerText);

                result = false;
            }
            return (result);
        }
示例#22
0
        // --------------------------------------------------------------------
        private static bool Rule43(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                if (!IsSingleName (context)) continue;

                if (!Exists (XPath.Path(context, "feeLeg", "initialPayment"))) continue;

                XmlElement	payer		= XPath.Path (context, "feeLeg", "initialPayment", "payerPartyReference");
                XmlElement	receiver 	= XPath.Path (context, "feeLeg", "initialPayment", "receiverPartyReference");
                XmlElement	seller		= XPath.Path (context, "generalTerms", "sellerPartyReference");
                XmlElement	buyer		= XPath.Path (context, "generalTerms", "buyerPartyReference");

                if ((payer != null) && (seller != null) && (receiver != null) && (buyer != null)) {
                    if (payer.GetAttribute ("href").Equals (buyer.GetAttribute ("href")) &&
                        receiver.GetAttribute ("href").Equals (seller.GetAttribute ("href")))
                        continue;
                }

                errorHandler ("305", context,
                    "The initial payment should be paid by the protection buyer to the protection seller",
                    name, null);

                result = false;
            }
            return (result);
        }
        private static bool Rule02(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in list) {
                XmlAttribute	href;
                XmlElement		target;

                if (((href = context.GetAttributeNode ("href")) == null) ||
                    ((target = nodeIndex.GetElementById (href.Value)) == null)) continue;

                string targetName = target.LocalName;

                if (targetName.Equals ("creditCurve") ||
                    targetName.Equals ("fxCurve") ||
                    targetName.Equals ("volatilityRepresentation") ||
                    targetName.Equals ("yieldCurve")) continue;

                errorHandler ("305", context,
                    "@href must match the @id attribute of an element of type PricingStructure",
                    name, targetName);

                result = false;
            }
            return (result);
        }
示例#24
0
 // --------------------------------------------------------------------
 private static bool Rule44(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule44 (name, nodeIndex.GetElementsByName ("creditDefaultSwap"), errorHandler));
 }
        private static bool Rule01(string name, NodeIndex nodeIndex, XmlNodeList list,
            ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement	 context in list) {
                XmlElement		generic	= XPath.Path (context, "generic");
                XmlAttribute	href;
                XmlElement		target;

                if ((generic == null) ||
                    ((href = generic.GetAttributeNode ("href")) == null) ||
                    ((target = nodeIndex.GetElementById (href.Value)) == null)) continue;

                string targetName = target.LocalName;

                if (targetName.Equals ("basket") ||
                    targetName.Equals ("cash") ||
                    targetName.Equals ("commodity") ||
                    targetName.Equals ("deposit") ||
                    targetName.Equals ("bond") ||
                    targetName.Equals ("convertibleBond") ||
                    targetName.Equals ("equity") ||
                    targetName.Equals ("exchangeTradedFund") ||
                    targetName.Equals ("index") ||
                    targetName.Equals ("future") ||
                    targetName.Equals ("fxRate") ||
                    targetName.Equals ("loan") ||
                    targetName.Equals ("mortgage") ||
                    targetName.Equals ("mutualFund") ||
                    targetName.Equals ("rateIndex") ||
                    targetName.Equals ("simpleCreditDefautSwap") ||
                    targetName.Equals ("simpleFra") ||
                    targetName.Equals ("simpleIrSwap") ||
                    targetName.Equals ("dealSummary") ||
                    targetName.Equals ("facilitySummary")) continue;

                errorHandler ("305", context,
                    "generic/@href must match the @id attribute of an element of type Asset",
                    name, targetName);

                result = false;
            }
            return (result);
        }
示例#26
0
        // --------------------------------------------------------------------
        private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                if (Exists (XPath.Path (context, "scheduledTerminationDate", "adjustableDate"))) {
                    XmlNode			effectiveDate	= XPath.Path (context, "effectiveDate", "unadjustedDate");
                    XmlNode			terminationDate	= XPath.Path (context, "scheduledTerminationDate", "adjustableDate", "unadjustedDate");

                    if ((effectiveDate == null) || (terminationDate == null) || Less (effectiveDate, terminationDate ))
                        continue;

                    errorHandler ("305", context,
                        "Effective date " + effectiveDate.InnerText.Trim () + " is not " +
                        "before scheduled termination date " + terminationDate.InnerText.Trim (),
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
 /// <summary>
 /// Evaluates this <b>Precondition</b> against the contents of the
 /// indicated <see cref="NodeIndex"/>.
 /// </summary>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> of a <see cref="XmlDocument"/>.</param>
 /// <param name="cache">A cache of previously evaluated precondition results.</param>
 /// <returns>A <c>bool</c> value indicating the applicability of this
 /// <b>Precondition</b> to the <see cref="XmlDocument"/>.</returns>
 public override bool Evaluate(NodeIndex nodeIndex, Dictionary<Precondition, Boolean> cache)
 {
     return (function (nodeIndex, cache));
 }
示例#28
0
        // --------------------------------------------------------------------
        private static bool Rule06(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement  buyer   = context ["buyerPartyReference"];
                XmlElement  seller  = context ["sellerPartyReference"];

                if ((buyer == null) || (seller == null) ||
                    NotEqual (buyer.GetAttribute ("href"), seller.GetAttribute ("href")))
                    continue;

                errorHandler ("305", context,
                    "Buyer party reference is equal to seller party reference",
                    name, seller.GetAttribute ("href"));

                result = false;
            }
            return (result);
        }
示例#29
0
 /// <summary>
 /// Determines if the <see cref="XmlDocument"/> instance indexed by the
 /// provided <see cref="NodeIndex"/> has business data content that passes a
 /// validation test. If errors are detected they will be reported through
 /// the <see cref="ValidationErrorHandler"/> instance passed as an argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> instance used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 protected abstract bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler);
示例#30
0
 // --------------------------------------------------------------------
 private static bool Rule08(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (
           Rule08 (name, nodeIndex.GetElementsByName ("trade"), errorHandler)
         & Rule08 (name, nodeIndex.GetElementsByName ("contract"), errorHandler));
 }