internal static Facet CreateFacet(FacetDefinition Definition) { if (Definition is PatternFacetDefinition) { return(new PatternFacet(Definition)); } if (Definition is LengthFacetDefinition) { return(new LengthFacet(Definition)); } if (Definition is MaxLengthFacetDefinition) { return(new MaxLengthFacet(Definition)); } if (Definition is WhiteSpaceFacetDefinition) { return(new WhiteSpaceFacet(Definition)); } if (Definition is MinLengthFacetDefinition) { return(new WhiteSpaceFacet(Definition)); } if (Definition is EnumerationFacetDefinition) { return(new EnumerationFacet(Definition)); } string MessageFormat = AssemblyResources.GetName("FacetDefinitionNotSupportedForFacetCreation"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, Definition.GetType().ToString()); //throw new XbrlException(MessageBuilder.ToString()); return(null); }
private void ValidateSegmentInnerText(INode SegmentNode) { var text = SegmentNode.InnerText; if (string.IsNullOrEmpty(text) == true) { return; } if (this.validatingFragment.Schemas.Count == 0) { return; } var segmentNodeType = this.validatingFragment.Schemas.GetNodeType(SegmentNode); if (segmentNodeType == null) { return; } if (segmentNodeType.CanConvert(text) == false) { string MessageFormat = AssemblyResources.GetName("SegmentTextNotConvertable"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, text); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } }
private void ValidateScenarioNode(INode ScenarioNode) { if (ScenarioNode.NamespaceURI.Equals(XbrlDocument.XbrlNamespaceUri) == true) { string MessageFormat = AssemblyResources.GetName("ScenarioNodeUsingXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingContext.Id, ScenarioNode.Name); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } if (ScenarioNode.Prefix.Length > 0) { XbrlSchema NodeSchema = this.validatingFragment.GetXbrlSchemaForPrefix(ScenarioNode.Prefix); if (NodeSchema != null) { Element NodeElement = NodeSchema.GetElement(ScenarioNode.LocalName); if (NodeElement != null) { if (NodeElement.SubstitutionGroup != Element.ElementSubstitutionGroup.Unknown) { string MessageFormat = AssemblyResources.GetName("ScenarioNodeUsingSubGroupInXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingContext.Id, ScenarioNode.Name, NodeSchema.Path); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } } } } foreach (INode CurrentChild in ScenarioNode.ChildNodes) { ValidateScenarioNode(CurrentChild); } }
private void ValidateMonetaryType() { if (validatingItem.UnitRef == null) { return; } // According to Table 3 in section 4.8.2 of the XBRL spec, monetary item units cannot use // ratios; they must be single measures. This condition is checked by test 304.26 in the // XBRL-CONF-CR5-2012-01-24 conformance suite. if (validatingItem.UnitRef.Ratio == true) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("RatioFoundInMonetaryItemUnit"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, validatingItem.UnitRef.Id); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); return; } // Validate the unit's measure, if it exists. if (validatingItem.UnitRef.MeasureQualifiedNames.Count == 0) { return; } if (validatingItem.UnitRef.MeasureQualifiedNames[0] == null) { return; } string Uri = validatingItem.UnitRef.MeasureQualifiedNames[0].NamespaceUri; if (Uri == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("WrongMeasureNamespaceForMonetaryFact"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, validatingItem.UnitRef.Id, "unspecified"); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); return; } if ((Uri.Length > 0) && (Uri.Equals(XbrlDocument.XbrlIso4217NamespaceUri) == false)) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("WrongMeasureNamespaceForMonetaryFact"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, validatingItem.UnitRef.Id, validatingItem.UnitRef.MeasureQualifiedNames[0].NamespaceUri); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); return; } validatingItem.UnitRef.ValidateISO4217Code(validatingItem.UnitRef.MeasureQualifiedNames[0].LocalName); if (validatingItem.UnitRef.IsIso4217CodeValid == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("UnsupportedISO4217CodeForUnitMeasure"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, validatingItem.UnitRef.Id, validatingItem.UnitRef.MeasureQualifiedNames[0].LocalName); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); } }
private void ValidateSegmentNodeNamespace(INode SegmentNode) { if (SegmentNode.NamespaceURI.Equals(XbrlDocument.XbrlNamespaceUri) == true) { string MessageFormat = AssemblyResources.GetName("SegmentNodeUsingXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingContext.Id, SegmentNode.Name); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } }
private void ValidateNilFact(Item FactToValidate) { if ((FactToValidate.PrecisionSpecified == true) || (FactToValidate.DecimalsSpecified == true)) { string MessageFormat = AssemblyResources.GetName("NilNumericFactWithSpecifiedPrecisionOrDecimals"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, FactToValidate.Name, FactToValidate.Id); //throw new XbrlException(MessageFormatBuilder.ToString()); } }
private void ValidateNilDecimalType() { if ((validatingItem.PrecisionSpecified == true) || (validatingItem.DecimalsSpecified == true)) { string MessageFormat = AssemblyResources.GetName("NilNumericFactWithSpecifiedPrecisionOrDecimals"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, validatingItem.Name, validatingItem.Id); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageFormatBuilder.ToString())); } }
//------------------------------------------------------------------------------- // Validates a footnote arc. // // Validation is handled differently, depending on the arc's role. Note that // the XBRL specification discusses this: // // 4.11.1.3.1 @xlink:arcrole attributes on <footnoteArc> elements // The value of the @xlink:arcrole attribute MUST be a URI that indicates the // meaning of the arc. One standard arc role value has been defined for arc role // values on <footnoteArc> elements. Its value is: // // http://www.xbrl.org/2003/arcrole/fact-footnote // // This arc role value is for use on a <footnoteArc> from item or tuple Locators // to footnote resources and it indicates that the <footnote> conveys human-readable // information about the fact or facts. // // For more information, see the blog post at http://gepsio.wordpress.com/2014/07/09/better-validation-coming-for-footnote-arcs-and-arc-roles/. //------------------------------------------------------------------------------- private void ValidateFootnoteArc(FootnoteArc CurrentArc) { FootnoteLocator Locator = CurrentArc.Link.GetLocator(CurrentArc.From); if (Locator == null) { if (CurrentArc.StandardArcRole == true) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("CannotFindFootnoteLocator"); MessageBuilder.AppendFormat(StringFormat, CurrentArc.Title, CurrentArc.From); validatingFragment.AddValidationError(new FootnoteArcValidationError(CurrentArc, MessageBuilder.ToString())); return; } var fromFootnote = CurrentArc.Link.GetFootnote(CurrentArc.From); if (fromFootnote == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("CannotFindFootnoteLocatorOrFootnote"); MessageBuilder.AppendFormat(StringFormat, CurrentArc.Title, CurrentArc.From); validatingFragment.AddValidationError(new FootnoteArcValidationError(CurrentArc, MessageBuilder.ToString())); return; } CurrentArc.FromFootnote = fromFootnote; } else { if ((Locator.Href.UrlSpecified == true) && (validatingFragment.UrlReferencesFragmentDocument(Locator.Href) == false)) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("FootnoteReferencesFactInExternalDoc"); MessageBuilder.AppendFormat(StringFormat, Locator.Href.ElementId, Locator.Href.Url); validatingFragment.AddValidationError(new FootnoteArcValidationError(CurrentArc, MessageBuilder.ToString())); return; } CurrentArc.FromItem = validatingFragment.GetFact(Locator.Href.ElementId); if (CurrentArc.FromItem == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("CannotFindFactForFootnoteArc"); MessageBuilder.AppendFormat(StringFormat, CurrentArc.Title, Locator.Href); validatingFragment.AddValidationError(new FootnoteArcValidationError(CurrentArc, MessageBuilder.ToString())); return; } } CurrentArc.ToFootnote = CurrentArc.Link.GetFootnote(CurrentArc.To); if (CurrentArc.ToFootnote == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("CannotFindFootnoteForFootnoteArc"); MessageBuilder.AppendFormat(StringFormat, CurrentArc.Title, CurrentArc.To); validatingFragment.AddValidationError(new FootnoteArcValidationError(CurrentArc, MessageBuilder.ToString())); return; } }
private void ValidateContextPeriod() { if ((validatingContext.PeriodStartDate != System.DateTime.MinValue) && (validatingContext.PeriodEndDate != System.DateTime.MinValue)) { if (validatingContext.PeriodEndDate < validatingContext.PeriodStartDate) { string MessageFormat = AssemblyResources.GetName("PeriodEndDateLessThanPeriodStartDate"); var MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingContext.Id); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } } }
//------------------------------------------------------------------------------- // Validates the unit reference for the given fact. Ensures that the unit ref // can be tied to a defined unit. //------------------------------------------------------------------------------- private void ValidateUnitRef(Item ItemToValidate) { string UnitRefValue = ItemToValidate.UnitRefName; //----------------------------------------------------------------------- // According to section 4.6.2, non-numeric items must not have a unit // reference. So, if the fact's unit reference is blank, and this is a // non-numeric item, then there is nothing to validate. //----------------------------------------------------------------------- if (UnitRefValue.Length == 0) { if (ItemToValidate.SchemaElement == null) { return; } if (ItemToValidate.Type == null) { return; } if (ItemToValidate.Type.IsNumeric == false) { return; } } //----------------------------------------------------------------------- // At this point, we have a unit ref should be matched to a unit. //----------------------------------------------------------------------- bool UnitFound = false; Unit MatchingUnit = null; foreach (Unit CurrentUnit in validatingFragment.Units) { if (CurrentUnit.Id == UnitRefValue) { UnitFound = true; MatchingUnit = CurrentUnit; ItemToValidate.UnitRef = MatchingUnit; } } //----------------------------------------------------------------------- // Check to see if a unit is found. //----------------------------------------------------------------------- if (UnitFound == false) { string MessageFormat = AssemblyResources.GetName("CannotFindUnitForUnitRef"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, UnitRefValue); validatingFragment.AddValidationError(new ItemValidationError(ItemToValidate, MessageBuilder.ToString())); } }
/// <summary> /// Validates one of the attribute on the fact. /// </summary> /// <param name="currentAttribute"> /// the attribute to validate. /// </param> private void ValidateAttribute(IAttribute currentAttribute) { var attributeType = validatingFragment.Schemas.GetAttributeType(currentAttribute); if (attributeType != null) { if (attributeType.CanConvert(currentAttribute.Value) == false) { string MessageFormat = AssemblyResources.GetName("AttributeTextNotConvertable"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingFact.Id, currentAttribute.Value); this.validatingFragment.AddValidationError(new FactValidationError(validatingFact, MessageBuilder.ToString())); } } }
//------------------------------------------------------------------------------- // Validate the "requires element" connection between two facts referenced in a // definition arc. //------------------------------------------------------------------------------- private void ValidateRequiresElementFacts(DefinitionArc RequiresElementDefinitionArc) { Locator CurrentFromLocator = RequiresElementDefinitionArc.FromLocator; Locator CurrentToLocator = RequiresElementDefinitionArc.ToLocator; int FromFactCount = CountFactInstances(CurrentFromLocator.HrefResourceId); int ToFactCount = CountFactInstances(CurrentToLocator.HrefResourceId); if (FromFactCount > ToFactCount) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("NotEnoughToFactsInRequiresElementRelationship"); MessageBuilder.AppendFormat(StringFormat, CurrentFromLocator.HrefResourceId, CurrentToLocator.HrefResourceId); validatingFragment.AddValidationError(new DefinitionArcValidationError(RequiresElementDefinitionArc, MessageBuilder.ToString())); } }
private void ValidateFacet(INode FacetNode) { foreach (FacetDefinition CurrentFacetDefinition in thisConstrainingFacetDefinitions) { if (CurrentFacetDefinition.Name.Equals(FacetNode.Name) == true) { ProcessFacet(CurrentFacetDefinition, FacetNode); return; } } string MessageFormat = AssemblyResources.GetName("UnsupportedFacet"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, FacetNode.Name, this.GetType().Name); //throw new XbrlException(MessageBuilder.ToString()); }
private void CreateRestrictionType(INode CurrentChildNode, INamespaceManager namespaceManager) { string BaseValue = CurrentChildNode.Attributes["base"].Value; var BaseValueAsQualifiedName = Container.Resolve <IQualifiedName>(); BaseValueAsQualifiedName.FullyQualifiedName = BaseValue; //var NamespaceUri = string.Empty; //if (string.IsNullOrEmpty(BaseValueAsQualifiedName.Namespace) == false) // NamespaceUri = namespaceManager.LookupNamespace(BaseValueAsQualifiedName.Namespace); thisRestrictionType = AnyType.CreateType(BaseValueAsQualifiedName.Name, CurrentChildNode); if (thisRestrictionType == null) { string MessageFormat = AssemblyResources.GetName("UnsupportedRestrictionBaseSimpleType"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, BaseValue); //throw new XbrlException(MessageBuilder.ToString()); } }
//------------------------------------------------------------------------------- // Validate arcrole references. // // According to test 308.02 of the CR5 conformance suite, each arcrole reference // must reference a unique URI. //------------------------------------------------------------------------------- private void ValidateArcroleReferences() { var uniqueUris = new Dictionary <string, ArcroleReference>(); foreach (var currentArcroleReference in validatingFragment.ArcroleReferences) { var currentArcroleReferenceUriAsString = currentArcroleReference.Uri.ToString(); if (uniqueUris.ContainsKey(currentArcroleReferenceUriAsString) == true) { string MessageFormat = AssemblyResources.GetName("DuplicateArcroleReferenceUri"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, currentArcroleReferenceUriAsString); validatingFragment.AddValidationError(new ArcroleReferenceValidationError(currentArcroleReference, MessageBuilder.ToString())); return; } uniqueUris.Add(currentArcroleReferenceUriAsString, currentArcroleReference); } }
/// <summary> /// Validate shares item types. /// </summary> private void ValidateSharesType() { bool SharesMeasureFound = true; string UnitMeasureLocalName = string.Empty; Unit UnitReference = validatingItem.UnitRef; if (UnitReference.MeasureQualifiedNames.Count != 1) { SharesMeasureFound = false; } if (SharesMeasureFound == true) { UnitMeasureLocalName = UnitReference.MeasureQualifiedNames[0].LocalName; SharesMeasureFound = UnitMeasureLocalName.Equals("shares"); } if (SharesMeasureFound == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("SharesItemTypeUnitLocalNameNotShares"); MessageBuilder.AppendFormat(StringFormat, validatingItem, UnitReference.Id, UnitMeasureLocalName); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); return; } var SharesNamespaceCorrect = true; string Uri = UnitReference.MeasureQualifiedNames[0].NamespaceUri; if (string.IsNullOrEmpty(Uri) == true) { SharesNamespaceCorrect = false; } else if (Uri.Equals(XbrlDocument.XbrlNamespaceUri) == false) { SharesNamespaceCorrect = false; } if (SharesNamespaceCorrect == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("WrongMeasureNamespaceForSharesFact"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, UnitReference.Id, Uri); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); } }
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------- internal override void ValidateFact(Item FactToValidate) { base.ValidateFact(FactToValidate); Unit UnitReference = FactToValidate.UnitRef; if (UnitReference == null) { return; } if (UnitReference.MeasureQualifiedNames[0] == null) { return; } string Uri = UnitReference.MeasureQualifiedNames[0].NamespaceUri; if (Uri == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("WrongMeasureNamespaceForMonetaryFact"); MessageBuilder.AppendFormat(StringFormat, FactToValidate.Name, UnitReference.Id, "unspecified"); //throw new XbrlException(MessageBuilder.ToString()); } if ((Uri.Length > 0) && (Uri.Equals(XbrlDocument.XbrlIso4217NamespaceUri) == false)) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("WrongMeasureNamespaceForMonetaryFact"); MessageBuilder.AppendFormat(StringFormat, FactToValidate.Name, UnitReference.Id, UnitReference.MeasureQualifiedNames[0].NamespaceUri); //throw new XbrlException(MessageBuilder.ToString()); } UnitReference.SetCultureAndRegionInfoFromISO4217Code(UnitReference.MeasureQualifiedNames[0].LocalName); if ((UnitReference.CultureInformation == null) && (UnitReference.RegionInformation == null)) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("UnsupportedISO4217CodeForUnitMeasure"); MessageBuilder.AppendFormat(StringFormat, FactToValidate.Name, UnitReference.Id, UnitReference.MeasureQualifiedNames[0].LocalName); //throw new XbrlException(MessageBuilder.ToString()); } }
private void CreateRestrictionType(INode restrictionNode, INamespaceManager namespaceManager) { string BaseValue = restrictionNode.Attributes["base"].Value; var BaseValueAsQualifiedName = Container.Resolve <IQualifiedName>(); BaseValueAsQualifiedName.FullyQualifiedName = BaseValue; thisRestrictionType = AnyType.CreateType(BaseValueAsQualifiedName.Name, restrictionNode); if (thisRestrictionType == null) { string MessageFormat = AssemblyResources.GetName("UnsupportedRestrictionBaseSimpleType"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, BaseValue); } foreach (INode childNode in restrictionNode.ChildNodes) { if (childNode.LocalName.Equals("attribute") == true) { ProcessRestrictionAttribute(childNode); } } }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ private void SetPeriodType(string PeriodType) { this.PeriodType = ElementPeriodType.Unknown; if (PeriodType == "instant") { this.PeriodType = ElementPeriodType.Instant; } else if (PeriodType == "duration") { this.PeriodType = ElementPeriodType.Duration; } else { // We can't identify the type, so throw an exception. string MessageFormat = AssemblyResources.GetName("InvalidElementPeriodType"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, this.Schema.SchemaReferencePath, PeriodType, this.Name); this.Schema.Fragment.AddValidationError(new ElementValidationError(this, MessageFormatBuilder.ToString())); } }
private void ValidateSegmentNodePrefix(INode SegmentNode) { if (SegmentNode.Prefix.Length > 0) { XbrlSchema NodeSchema = this.validatingFragment.GetXbrlSchemaForPrefix(SegmentNode.Prefix); if (NodeSchema != null) { Element NodeElement = NodeSchema.GetElement(SegmentNode.LocalName); if (NodeElement != null) { if (NodeElement.SubstitutionGroup != Element.ElementSubstitutionGroup.Unknown) { string MessageFormat = AssemblyResources.GetName("SegmentNodeUsingSubGroupInXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, validatingContext.Id, SegmentNode.Name, NodeSchema.Path); this.validatingFragment.AddValidationError(new ContextValidationError(validatingContext, MessageBuilder.ToString())); } } } } }
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------- private void ValidateFootnoteLocation(string FootnoteLocationReference) { HyperlinkReference Reference = new HyperlinkReference(FootnoteLocationReference); if (Reference.UrlSpecified == true) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("FootnoteReferencesFactInExternalDoc"); MessageBuilder.AppendFormat(StringFormat, Reference.ElementId, Reference.Url); validatingFragment.AddValidationError(new HyperlinkReferenceValidationError(Reference, MessageBuilder.ToString())); return; } if (validatingFragment.GetFact(Reference.ElementId) == null) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("NoFactForFootnoteReference"); MessageBuilder.AppendFormat(StringFormat, FootnoteLocationReference); validatingFragment.AddValidationError(new HyperlinkReferenceValidationError(Reference, MessageBuilder.ToString())); return; } }
private void ProcessFacet(FacetDefinition CurrentFacetDefinition, INode FacetNode) { Facet NewFacet; NewFacet = Facet.CreateFacet(CurrentFacetDefinition); foreach (IAttribute CurrentAttribute in FacetNode.Attributes) { foreach (FacetPropertyDefinition CurrentPropertyDefinition in CurrentFacetDefinition.PropertyDefinitions) { if (CurrentAttribute.Name.Equals(CurrentPropertyDefinition.Name) == true) { NewFacet.AddFacetProperty(CurrentPropertyDefinition, CurrentAttribute.Value); thisFacets.Add(NewFacet); return; } } string MessageFormat = AssemblyResources.GetName("UnsupportedFacetProperty"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, CurrentAttribute.Name, CurrentFacetDefinition.Name); //throw new XbrlException(MessageBuilder.ToString()); } }
//------------------------------------------------------------------------------- // Validates the context reference for the given fact. Ensures that the context // ref can be tied to a defined context. //------------------------------------------------------------------------------- private void ValidateContextRef(Item ItemToValidate) { string ContextRefValue = ItemToValidate.ContextRefName; if (ContextRefValue.Length == 0) { return; } try { Context MatchingContext = validatingFragment.ContextDictionary[ContextRefValue]; ItemToValidate.ContextRef = MatchingContext; } catch (KeyNotFoundException) { string MessageFormat = AssemblyResources.GetName("CannotFindContextForContextRef"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, ContextRefValue); validatingFragment.AddValidationError(new ItemValidationError(ItemToValidate, MessageBuilder.ToString())); } }
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------- private void ValidateContextTimeSpansAgainstPeriodTypes() { foreach (Fact CurrentFact in validatingFragment.Facts) { if (CurrentFact is Item) { var CurrentItem = CurrentFact as Item; switch (CurrentItem.SchemaElement.PeriodType) { case Element.ElementPeriodType.Duration: if (CurrentItem.ContextRef != null) { if (CurrentItem.ContextRef.DurationPeriod == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("ElementSchemaDefinesDurationButUsedWithNonDurationContext"); MessageBuilder.AppendFormat(StringFormat, CurrentItem.SchemaElement.Schema.Path, CurrentItem.Name, CurrentItem.ContextRef.Id); validatingFragment.AddValidationError(new ItemValidationError(CurrentItem, MessageBuilder.ToString())); } } break; case Element.ElementPeriodType.Instant: if (CurrentItem.ContextRef != null) { if (CurrentItem.ContextRef.InstantPeriod == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("ElementSchemaDefinesInstantButUsedWithNonInstantContext"); MessageBuilder.AppendFormat(StringFormat, CurrentItem.SchemaElement.Schema.Path, CurrentItem.Name, CurrentItem.ContextRef.Id); validatingFragment.AddValidationError(new ItemValidationError(CurrentItem, MessageBuilder.ToString())); } } break; } } } }
/// <summary> /// Validate pure item types. /// </summary> private void ValidatePureType() { string UnitMeasureLocalName = string.Empty; Unit UnitReference = validatingItem.UnitRef; bool PureMeasureFound = true; if (UnitReference.MeasureQualifiedNames.Count != 1) { PureMeasureFound = false; } if (PureMeasureFound == true) { UnitMeasureLocalName = UnitReference.MeasureQualifiedNames[0].LocalName; PureMeasureFound = UnitMeasureLocalName.Equals("pure"); } if (PureMeasureFound == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("PureItemTypeUnitLocalNameNotPure"); MessageBuilder.AppendFormat(StringFormat, validatingItem.Name, UnitReference.Id, UnitMeasureLocalName); validatingFragment.AddValidationError(new ItemValidationError(validatingItem, MessageBuilder.ToString())); } }
internal override void ValidateFact(Item FactToValidate) { base.ValidateFact(FactToValidate); string UnitMeasureLocalName = string.Empty; Unit UnitReference = FactToValidate.UnitRef; bool PureMeasureFound = true; if (UnitReference.MeasureQualifiedNames.Count != 1) { PureMeasureFound = false; } if (PureMeasureFound == true) { UnitMeasureLocalName = UnitReference.MeasureQualifiedNames[0].LocalName; PureMeasureFound = UnitMeasureLocalName.Equals("pure"); } if (PureMeasureFound == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("PureItemTypeUnitLocalNameNotPure"); MessageBuilder.AppendFormat(StringFormat, FactToValidate.Name, UnitReference.Id, UnitMeasureLocalName); //throw new XbrlException(MessageBuilder.ToString()); } }
/// <summary> /// Validates a given summation concept. /// </summary> /// <param name="CurrentCalculationLink"> /// The calculation link that defines the given summation concept. /// </param> /// <param name="CurrentSummationConcept"> /// The summation concept to be validated. /// </param> /// <param name="FactList"> /// The collection of items that should be searched when looking for summation or contributing items. /// </param> private void ValidateSummationConcept(CalculationLink CurrentCalculationLink, SummationConcept CurrentSummationConcept, FactCollection FactList) { Element SummationConceptElement = LocateElement(CurrentSummationConcept.SummationConceptLocator); Item SummationConceptItem = LocateItem(SummationConceptElement, FactList); // If the summation concept item doesn't exist, then there is no calculation // to perform. if (SummationConceptItem == null) { return; } // If the summation concept item has a "nil" value, then there is no calculation // to perform. if (SummationConceptItem.NilSpecified == true) { return; } double SummationConceptRoundedValue = SummationConceptItem.RoundedValue; double ContributingConceptRoundedValueTotal = 0; var ContributingConceptItemsFound = false; var AtLeastOneItemWithZeroPrecision = false; foreach (Locator CurrentLocator in CurrentSummationConcept.ContributingConceptLocators) { // Some decisions need to be made before the code can actually add the value of the // contributing concept to the total that the code is keeping. var IncludeContributingConceptItemInCalculation = true; // Find the calculation arc for the given calculation link. CalculationArc ContributingConceptCalculationArc = CurrentCalculationLink.GetCalculationArc(CurrentLocator); if (ContributingConceptCalculationArc == null) { IncludeContributingConceptItemInCalculation = false; } // Find the elemement for the given locator. Element ContributingConceptElement = LocateElement(CurrentLocator); if (ContributingConceptElement == null) { IncludeContributingConceptItemInCalculation = false; } // Find all items for the given element. If there is more than one, and at least // one of them is not p-equals with at least one of the other ones, then // the entire calculation validation is forfeit, according to test 397.12 in // the XBRL-CONF-CR3-2007-03-05 conformance suite. var AllMatchingItems = LocateItems(ContributingConceptElement, FactList); if (AllItemsNotPEquals(AllMatchingItems) == false) { return; } // Find the item for the given element. if (AllMatchingItems.Count == 0) { IncludeContributingConceptItemInCalculation = false; } else { foreach (var ContributingConceptItem in AllMatchingItems) { if (IncludeContributingConceptItemInCalculation == true) { IncludeContributingConceptItemInCalculation = ContributingConceptItemEligibleForUseInCalculation(ContributingConceptItem, SummationConceptItem); } if (IncludeContributingConceptItemInCalculation == true) { ContributingConceptItemsFound = true; if ((ContributingConceptItem.PrecisionSpecified == true) && (ContributingConceptItem.Precision == 0) && (ContributingConceptItem.InfinitePrecision == false)) { AtLeastOneItemWithZeroPrecision = true; } double ContributingConceptRoundedValue = ContributingConceptItem.RoundedValue; if (ContributingConceptCalculationArc.Weight != (decimal)(1.0)) { ContributingConceptRoundedValue = ContributingConceptRoundedValue * (double)(ContributingConceptCalculationArc.Weight); } ContributingConceptRoundedValueTotal += ContributingConceptRoundedValue; } } } } if (ContributingConceptItemsFound == true) { if (AtLeastOneItemWithZeroPrecision == true) { var MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("SummationConceptUsesContributingItemWithPrecisionZero"); MessageBuilder.AppendFormat(StringFormat, SummationConceptItem.Name); ValidatedFragment.AddValidationError(new SummationConceptValidationError(CurrentSummationConcept, MessageBuilder.ToString())); return; } ContributingConceptRoundedValueTotal = SummationConceptItem.Round(ContributingConceptRoundedValueTotal); if (SummationConceptRoundedValue != ContributingConceptRoundedValueTotal) { var MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("SummationConceptError"); MessageBuilder.AppendFormat(StringFormat, SummationConceptItem.Name, SummationConceptRoundedValue, ContributingConceptRoundedValueTotal); ValidatedFragment.AddValidationError(new SummationConceptValidationError(CurrentSummationConcept, MessageBuilder.ToString())); return; } } }
//------------------------------------------------------------------------------- // Validate the essence alias between two given facts. //------------------------------------------------------------------------------- private void ValidateEssenceAliasedFacts(Item FromItem, Item ToItem) { // Essence alias checks for c-equals items are a bit tricky, according to the // XBRL-CONF-CR3-2007-03-05 conformance suite. Test 392.11 says that it is valid // to have two items with contexts having the same structure but different // period values is valid; however, test 392.13 says that it is invalid two have // two items with contexts having a different structure. if (FromItem.ContextEquals(ToItem) == false) { if ((FromItem.ContextRef != null) && (ToItem.ContextRef != null)) { if (FromItem.ContextRef.PeriodTypeEquals(ToItem.ContextRef) == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("EssenceAliasFactsNotContextEquals"); MessageBuilder.AppendFormat(StringFormat, FromItem.Name, ToItem.Name, FromItem.Id, ToItem.Id); var validationError = new ItemsValidationError(MessageBuilder.ToString()); validationError.AddItem(FromItem); validationError.AddItem(ToItem); validatingFragment.AddValidationError(validationError); return; } } return; } if (FromItem.ParentEquals(ToItem) == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("EssenceAliasFactsNotParentEquals"); MessageBuilder.AppendFormat(StringFormat, FromItem.Name, ToItem.Name, FromItem.Id, ToItem.Id); var validationError = new ItemsValidationError(MessageBuilder.ToString()); validationError.AddItem(FromItem); validationError.AddItem(ToItem); validatingFragment.AddValidationError(validationError); return; } if (FromItem.UnitEquals(ToItem) == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("EssenceAliasFactsNotUnitEquals"); MessageBuilder.AppendFormat(StringFormat, FromItem.Name, ToItem.Name, FromItem.Id, ToItem.Id); var validationError = new ItemsValidationError(MessageBuilder.ToString()); validationError.AddItem(FromItem); validationError.AddItem(ToItem); validatingFragment.AddValidationError(validationError); return; } // At this point, the valies of the items need to be compared. Check the item's type // to ensure that the correct value is being compared. var ItemValuesMatch = true; if (FromItem.SchemaElement.TypeName.Name.Equals("stringItemType") == true) { ItemValuesMatch = FromItem.Value.Equals(ToItem.Value); } else { if (FromItem.RoundedValue != ToItem.RoundedValue) { ItemValuesMatch = false; } } if (ItemValuesMatch == false) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("EssenceAliasFactsHaveDifferentRoundedValues"); MessageBuilder.AppendFormat(StringFormat, FromItem.Name, ToItem.Name, FromItem.Id, FromItem.RoundedValue.ToString(), ToItem.Id, ToItem.RoundedValue.ToString()); var validationError = new ItemsValidationError(MessageBuilder.ToString()); validationError.AddItem(FromItem); validationError.AddItem(ToItem); validatingFragment.AddValidationError(validationError); return; } }