// -------------------------------------------------------------------- private static bool Rule23(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { return( Rule23(name, nodeIndex.GetElementsByName("equityOption"), errorHandler) & Rule23(name, nodeIndex.GetElementsByName("brokerEquityOption"), errorHandler) & Rule23(name, nodeIndex.GetElementsByName("equityForward"), errorHandler)); }
// -------------------------------------------------------------------------- private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { return( Rule05(name, nodeIndex.GetElementsByName("calculationPeriodNumberOfDays"), errorHandler) & Rule05(name, nodeIndex.GetElementsByName("observationWeight"), errorHandler) & Rule05(name, nodeIndex.GetElementsByName("periodSkip"), errorHandler)); }
//--------------------------------------------------------------------- private static bool Rule08(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { return( Rule08(name, nodeIndex.GetElementsByName("businessDateRange"), errorHandler) & Rule08(name, nodeIndex.GetElementsByName("cashSettlementPaymentDate"), errorHandler) & Rule08(name, nodeIndex.GetElementsByName("scheduleBounds"), errorHandler)); }
//--------------------------------------------------------------------------- private static bool Rule09(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { return( Rule09(name, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "RequestSubstitution"), errorHandler) & Rule09(name, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "RequestSubstitutionRetracted"), errorHandler)); } return( Rule09(name, nodeIndex.GetElementsByName("requestSubstitution"), errorHandler) & Rule09(name, nodeIndex.GetElementsByName("requestSubstitutionRetracted"), errorHandler)); }
//--------------------------------------------------------------------- private static bool Rule03(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { return( Rule03(name, nodeIndex.GetElementsByName("cashSettlementValuationDate"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("feePaymentDate"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("fixingDateOffset"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("fixingDates"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("initialFixingDate"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("paymentDaysOffset"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("rateCutOffDaysOffset"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("relativeDate"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("varyingNotionalInterimExchangePaymentDates"), errorHandler) & Rule03(name, nodeIndex.GetElementsByName("varyingNotionalFixingDates"), errorHandler)); }
//--------------------------------------------------------------------- private static bool Rule01(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { String ns = nodeIndex.Document.DocumentElement.NamespaceURI; return(Rule01(name, nodeIndex.GetElementsByType(ns, "BusinessDayAdjustments"), errorHandler)); } return( Rule01(name, nodeIndex.GetElementsByName("dateAdjustments"), errorHandler) & Rule01(name, nodeIndex.GetElementsByName("calculationPeriodDatesAdjustments"), errorHandler) & Rule01(name, nodeIndex.GetElementsByName("paymentDatesAdjustments"), errorHandler) & Rule01(name, nodeIndex.GetElementsByName("resetDatesAdjustments"), errorHandler)); }
/// <summary> /// Validates all the elements registered at construction using the /// <see cref="NodeIndex"/> to locate them as quickly as possible. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the test document.</param> /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param> /// <returns><c>true</c> if the code values pass the checks, <c>false</c> /// otherwise.</returns> protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { string ns = FpMLRuleSet.DetermineNamespace(nodeIndex); return(Validate( nodeIndex.GetElementsByType(ns, contextType), nodeIndex.GetElementsByType(ns, targetType), errorHandler)); } return(Validate( nodeIndex.GetElementsByName(contextElements), nodeIndex.GetElementsByName(targetElements), errorHandler)); }
/// <summary> /// Validates all the elements registered at construction using the /// <see cref="NodeIndex"/> to locate them as quickly as possible. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the test document.</param> /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param> /// <returns><c>true</c> if the code values pass the checks, <c>false</c> /// otherwise.</returns> protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; for (int index = 0; index < elementNames.Length; ++index) { XmlNodeList list = nodeIndex.GetElementsByName(elementNames [index]); if (parentNames == null) { result &= Validate(list, errorHandler); } else { MutableNodeList targets = new MutableNodeList(); foreach (XmlElement context in list) { XmlNode parent = context.ParentNode; if ((parent.NodeType == XmlNodeType.Element) && parent.LocalName.Equals(parentNames [index])) { targets.Add(context); } } result &= Validate(targets, errorHandler); } } return(result); }
/// <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) { HandCoded.FpML.Util.Version version; // Find the document version XmlNodeList list = nodeIndex.GetElementsByName("FpML"); if (list.Count > 0) { version = FpML.Util.Version.Parse(((XmlElement)list [0]).GetAttribute("version")); } else { list = nodeIndex.GetAttributesByName("fpmlVersion"); if (list.Count > 0) { version = FpML.Util.Version.Parse(((XmlAttribute)list [0]).Value); } else { return(false); } } // System.Console.Write ("Range (Doc=" + version // + " Min=" + ((minimumVersion != null) ? minimumVersion.ToString () : "*") // + " Max=" + ((maximumVersion != null) ? maximumVersion.ToString () : "*")); bool validMin = (minimumVersion != null) ? (version.CompareTo(minimumVersion) >= 0) : true; bool validMax = (maximumVersion != null) ? (version.CompareTo(maximumVersion) <= 0) : true; // System.Console.WriteLine (") => " + (validMin & validMax)); return(validMin & validMax); }
/// <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, bool> cache) { XmlElement rootElement; // Find the document element XmlNodeList list = nodeIndex.GetElementsByName("FpML"); if (list.Count > 0) { rootElement = (XmlElement)list [0]; } else { list = nodeIndex.GetAttributesByName("fpmlVersion"); if (list.Count > 0) { rootElement = ((XmlAttribute)list [0]).OwnerElement; } else { return(false); } } string ns = rootElement.NamespaceURI; return((ns != null) ? (ns.CompareTo(namespaceUri) == 0) : 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); }
/// <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) { HandCoded.FpML.Util.Version version; // Find the document version XmlNodeList list = nodeIndex.GetElementsByName("FpML"); if (list.Count > 0) { version = HandCoded.FpML.Util.Version.Parse(((XmlElement)list [0]).GetAttribute("version")); } else { list = nodeIndex.GetAttributesByName("fpmlVersion"); if (list.Count > 0) { version = HandCoded.FpML.Util.Version.Parse(((XmlAttribute)list [0]).Value); } else { return(false); } } return(version.Equals(targetVersion)); }
// -------------------------------------------------------------------- private static bool Rule01(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; foreach (XmlElement context in nodeIndex.GetElementsByName("hourMinuteTime")) { string value = context.InnerText; try { if (Time.Parse(value).Seconds != 0) { errorHandler("305", context, "The seconds component of the time must be zeroes", name, context.InnerText); result = false; } } catch (Exception) { errorHandler("305", context, "The time value is not in HH:MM:SS format", name, value); result = false; } } return(result); }
// -------------------------------------------------------------------- private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { return(Rule05(name, nodeIndex, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "FirstPeriodStartDate"), errorHandler)); } return(Rule05(name, nodeIndex, nodeIndex.GetElementsByName("firstPeriodStartDate"), errorHandler)); }
// -------------------------------------------------------------------- private static bool Rule38(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { return(Rule38(name, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "MandatoryEarlyTermination"), errorHandler)); } return(Rule38(name, nodeIndex.GetElementsByName("mandatoryEarlyTermination"), errorHandler)); }
// -------------------------------------------------------------------- private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.GetElementsByName("onBehalfOf").Count > 2) { if (nodeIndex.GetElementsByName("novation").Count > 0) { return(true); } errorHandler("305", nodeIndex.Document.DocumentElement, "Only novation messages can be on behalf of more than two parties", name, null); return(false); } return(true); }
// -------------------------------------------------------------------- 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)); }
// -------------------------------------------------------------------- private static bool Rule05 (string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) return ( Rule05 (name, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "InterestRatePeriod"), errorHandler)); return ( Rule05 (name, nodeIndex.GetElementsByName ("currentInterestRatePeriod"), errorHandler)); }
// -------------------------------------------------------------------- private static bool Rule10 (string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) return ( Rule10 (name, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "FacilityNotice"), errorHandler)); return ( Rule10 (name, nodeIndex.GetElementsByName ("facilityNotice"), errorHandler)); }
// -------------------------------------------------------------------- private static bool Rule01 (string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) return ( Rule01 (name, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "LoanContract"), errorHandler)); return ( Rule01 (name, nodeIndex.GetElementsByName ("loanContract"), errorHandler)); }
//--------------------------------------------------------------------------- private static bool Rule11(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { return(Rule11(name, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "InterestCalculationDetails"), errorHandler)); } return(Rule11(name, nodeIndex.GetElementsByName("interestCalculationDetails"), errorHandler)); }
//--------------------------------------------------------------------------- private static bool Rule08(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { if (nodeIndex.HasTypeInformation) { return(Rule08(name, nodeIndex.GetElementsByType(DetermineNamespace(nodeIndex), "CollateralBalance"), errorHandler)); } return( Rule08(name, nodeIndex.GetElementsByName("collateral"), errorHandler)); }
//--------------------------------------------------------------------- private static bool Rule09(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; foreach (XmlElement context in nodeIndex.GetElementsByName("cashSettlementPaymentDate")) { result &= Rule09(name, context.GetElementsByTagName("businessDateRange"), errorHandler); } return(result); }
/// <summary> /// Validates all the elements registered at construction using the /// <see cref="NodeIndex"/> to locate them as quickly as possible. /// </summary> /// <param name="nodeIndex">The <see cref="NodeIndex"/> of the test document.</param> /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param> /// <returns><c>true</c> if the code values pass the checks, <c>false</c> /// otherwise.</returns> protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; foreach (string elementName in elementNames) { result &= Validate(nodeIndex.GetElementsByName(elementName), errorHandler); } return(result); }
/// <summary> /// Returns a <see cref="XmlNodeList"/> containing all the elements /// defined in the <see cref="NodeIndex"/> that match the context /// specification. /// </summary> /// <param name="nodeIndex">A <see cref="NodeIndex"/> for the test document.</param> /// <returns>A <see cref="XmlNodeList"/> containing all the matching /// <see cref="XmlElement"/> instances, if any.</returns> public XmlNodeList GetMatchingElements(NodeIndex nodeIndex) { if (parentNames == null) { return(nodeIndex.GetElementsByName(elementNames)); } else { MutableNodeList result = new MutableNodeList(); for (int index = 0; index < elementNames.Length; ++index) { XmlNodeList matches = nodeIndex.GetElementsByName(elementNames [index]); if (parentNames [index] == null) { result.AddAll(matches); } else { for (int count = 0; count < matches.Count; ++count) { XmlElement element = (XmlElement)matches [count]; XmlNode parent = element.ParentNode; if (parent.NodeType == XmlNodeType.Element) { if (parent.LocalName.Equals(parentNames [index])) { result.Add(element); } } } } } return(result); } }
// -------------------------------------------------------------------------- private static bool Rule06(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; foreach (XmlElement context in nodeIndex.GetElementsByName("precision")) { string value = context.InnerText; try { if (Int32.Parse(value) < 0) { throw new ArgumentException("Invalid value"); } } catch (Exception) { errorHandler("305", context, "Invalid non-negative integer value", name, value); result = false; } } return(result); }
/// <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); }
//--------------------------------------------------------------------- private static bool Rule17(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler) { bool result = true; foreach (XmlElement context in XPath.Paths(nodeIndex.GetElementsByName("tradeSide"), "*", "account")) { string href = context.GetAttribute("href"); XmlElement target = nodeIndex.GetElementById(href); if (target.LocalName.Equals("account")) { continue; } errorHandler("305", context, "The value of the href attribute does not refer to an account structure", name, href); result = false; } return(result); }
/// <summary> /// Perform the file processing while timing the operation. /// </summary> protected override void Execute() { DirectoryInfo directory = new DirectoryInfo(Environment.CurrentDirectory); ArrayList files = new ArrayList(); try { for (int index = 0; index < Arguments.Length; ++index) { String location = directory.ToString(); string target = Arguments [index]; while (target.StartsWith(@"..\")) { location = location.Substring(0, location.LastIndexOf(Path.DirectorySeparatorChar)); target = target.Substring(3); } FindFiles(files, Path.Combine(location, target)); } } catch (Exception error) { log.Fatal("Invalid command line argument", error); Finished = true; return; } XmlDocument document; NodeIndex nodeIndex; try { for (int index = 0; index < files.Count; ++index) { string filename = (files [index] as FileInfo).FullName; FileStream stream = File.OpenRead(filename); document = XmlUtility.NonValidatingParse(stream); System.Console.WriteLine(">> " + filename); Release release = Specification.ReleaseForDocument(document); if (release != null) { if (release is DTDRelease) { System.Console.WriteLine("= " + release + " {" + (release as DTDRelease).PublicId + "}"); } else if (release is SchemaRelease) { System.Console.WriteLine("= " + release + " {" + (release as SchemaRelease).NamespaceUri + "}"); } else { System.Console.WriteLine("= " + release); } } if (isdaOption.Present) { if (release != Releases.R5_3_CONFIRMATION) { Conversion conversion = Conversion.ConversionFor(release, Releases.R5_3_CONFIRMATION); if (conversion == null) { Console.WriteLine("!! The contents of the file can not be converted to FpML 5.3 (Confirmation)"); continue; } document = conversion.Convert(document, new DefaultHelper()); if (document == null) { Console.WriteLine("!! Automatic conversion to FpML 5.3 (Confirmation) failed"); continue; } } nodeIndex = new NodeIndex(document); DoIsdaClassify(nodeIndex.GetElementsByName("trade")); } else { nodeIndex = new NodeIndex(document); DoClassify(nodeIndex.GetElementsByName("trade"), "Trade"); DoClassify(nodeIndex.GetElementsByName("contract"), "Contract"); } stream.Close(); } } catch (Exception error) { log.Fatal("Unexpected exception during processing", error); } Finished = true; }