private void MergeDiscoveredTaxonomy(string fn, Taxonomy depTax, out int numErrors ) { numErrors = 0; if (this.dependantTaxonomyFilenames.Contains(fn)) return; dependantTaxonomyFilenames.Add(fn); dependantTaxonomies.Add(depTax); this.infos.Add(new TaxonomyItem(depTax.GetTargetNamespace(), depTax.schemaFile, depTax.GetNSPrefix(), depTax.IsAucentExtension, depTax.DefinesCustomTypes)); ArrayList tmp; //merge the presentation, calculation, definition linkbases... if (!this.innerTaxonomy) { presentationInfo = MergePresentations(presentationInfo, depTax.presentationInfo, out tmp); depTax.presentationInfo = null; if (tmp.Count > 0) { numErrors += tmp.Count; errorList.AddRange(tmp); } calculationInfo = MergePresentations(calculationInfo, depTax.calculationInfo, out tmp); if (tmp.Count > 0) { numErrors += tmp.Count; errorList.AddRange(tmp); } if (this.netDefinisionInfo == null) { this.netDefinisionInfo = depTax.netDefinisionInfo; } else { netDefinisionInfo.MergeDimensionLinks(depTax.netDefinisionInfo, out tmp); if (tmp.Count > 0) { numErrors += tmp.Count; errorList.AddRange(tmp); } } } }
private bool IsValidMarkup(ContextProperty cp, Dimension.MeasureHyperCubeInfo mhci, ref ArrayList errors) { BuildValidMembersByDimension(); ListDictionary instanceDimensionInfos = new ListDictionary(); if (mhci.IsScenario) { foreach (Scenario sc in cp.Scenarios) { if (sc.DimensionInfo != null) { instanceDimensionInfos[sc.DimensionInfo.dimensionId] = sc.DimensionInfo; } } } else { //TODO: same thing for segments.. } ListDictionary validationByDimension = new ListDictionary(); int baseValidationData = 0; if (mhci.IsAllRelationShip) { baseValidationData += ValidationDataEnum.ALLRelationShip.GetHashCode(); } else { baseValidationData += ValidationDataEnum.NotAllRelationShip.GetHashCode(); } if (mhci.IsClosed) { baseValidationData += ValidationDataEnum.IsClosed.GetHashCode(); } else { baseValidationData += ValidationDataEnum.IsNotClosed.GetHashCode(); } foreach (DictionaryEntry de in validMembersByDimension) { int validationData = baseValidationData; bool found = false; bool hasDefault = false; ContextDimensionInfo cdi = instanceDimensionInfos[de.Key] as ContextDimensionInfo; instanceDimensionInfos.Remove(de.Key); if (cdi == null) { validationData += ValidationDataEnum.DimensionNotInInstance.GetHashCode(); } else { HybridDictionary validMembers = de.Value as HybridDictionary; if (validMembers != null) { found = validMembers[cdi.Id] != null; } } if (found) { validationData += ValidationDataEnum.Found.GetHashCode(); } else { validationData += ValidationDataEnum.NotFound.GetHashCode(); } if (hasDefault) { validationData += ValidationDataEnum.DimensionHasDefault.GetHashCode(); //TODO: determine if the default value is being used //which is not a good thing and is an error condition. } ValidateResult(validationData, errors); } if (instanceDimensionInfos.Keys.Count != 0) { if (mhci.IsClosed) { //this is an error condition as we have dimensions that are not part of //the cube in the instance but the cube is a closed cube and does not //allow other dimension infos //TODO: enhance the error message... string error = "Found invalid dimension for an element that is using a closed hypercube"; errors.Add(error); } } return errors.Count == 0; }
private void LoadDefinitionLinkbase( Dimension d, string linkbase, out int numErrors ) { numErrors = 0; string baseUri = GetTargetNamespace(); if ( baseUri[baseUri.Length - 1] != '/' && baseUri[baseUri.Length - 1] != '\\' ) { baseUri += "/"; } string bs = baseUri + schemaFilename; Dictionary<string, string> discoveredSchemas = new Dictionary<string, string>(); if ( linkbase.StartsWith( "http" ) ) { baseUri = linkbase.Replace( Path.GetFileName( linkbase ), string.Empty ); } d.BaseSchema = bs; d.OwnerHandle = OwnerHandle; d.Load( linkbase ); if (IsAucentExtension && skipAucentExtensions && !this.innerTaxonomy && d.IsDocumentCreatedByRivet()) { //if this is a top level aucent extension taxonomy and ... //if the skipAucentExtensions is set to true ... we want to load just the no rivet created files... //as we will merge the rivet created files later.... return; } if ( d.ErrorList.Count > 0 ) { for ( int i = 0; i < d.ErrorList.Count; i++ ) Common.WriteError( "XBRLParser.Error.Exception", validationErrors, SchemaFile + ": DEFINITION_ROLE Error: " + d.ErrorList[i] ); } d.Parse( discoveredSchemas, out numErrors ); foreach ( string val in discoveredSchemas.Values ) { string filename = Path.GetFileName( val ); string hintPath = val.Replace(filename, string.Empty); LoadAdditionalDependantTaxonomy(filename, hintPath, ref numErrors); } }
private Dimension LoadDefinitionSchema( out int numErrors ) { numErrors = 0; definitionFile = GetLinkbaseReference( TARGET_LINKBASE_URI + DEFINISION_ROLE ); if ( definitionFile == null ) return null; Hashtable tempDefHash = new Hashtable(); Dimension tempD = new Dimension(); tempD.loadingTaxonomy = this.GetLoadingTaxonomy(); tempD.PromptUser = this.PromptUser; foreach ( string file in definitionFile ) { LoadDefinitionLinkbase( tempD, file, out numErrors ); //build the presentation links if ( tempD.DefinitionLinks != null ) { IDictionaryEnumerator linkEnumer = tempD.DefinitionLinks.GetEnumerator(); while (linkEnumer.MoveNext()) { if (!tempDefHash.ContainsKey(linkEnumer.Key)) { tempDefHash[linkEnumer.Key] = linkEnumer.Value; } else { //need to merge the info.. ArrayList tmp = new ArrayList(); DefinitionLink orig = tempDefHash[linkEnumer.Key] as DefinitionLink; orig.Append(linkEnumer.Value as DefinitionLink, tmp); } } } //build the roleRefs this.MergeRoleRefsFromLinkbase(tempD.roleRefs, tempD.BaseSchema, tempD.SchemaFile, LinkbaseFileInfo.LinkbaseType.Definition); tempD.roleRefs = null; } Dimension d = new Dimension(); d.DefinitionLinks = tempDefHash; return d; }
private void LoadDefinition( out int numErrors ) { numErrors = 0; Dimension d = LoadDefinitionSchema( out numErrors ); if ( d == null && innerTaxonomy ) return; // nothing to do if ( d == null ) { d = new Dimension(); d.DefinitionLinks = new Hashtable(); } netDefinisionInfo = d; if ( !innerTaxonomy ) { if ( dependantTaxonomies.Count > 0 ) { foreach ( Taxonomy depTax in dependantTaxonomies ) { ArrayList tmp; netDefinisionInfo.MergeDimensionLinks( depTax.netDefinisionInfo, out tmp ); if ( tmp.Count > 0 ) { numErrors += tmp.Count; errorList.AddRange( tmp ); } } } } //if ( netDefinisionInfo != null ) //{ // netDefinisionInfo.RemoveRecursiveLocator( ref numErrors ); //} if ( numErrors > 0 ) { numDefErrors += numErrors; errorList.AddRange( d.ErrorList ); } }
public Node CreateNode( string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo ) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return null; } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id,true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return dn; } } } return null; //strange ..could not find the correct hierarchy.. } else { return null; } } } } current = elementToUse==null ? new Node( href ) : elementToUse.CreateNode( lang, role, false ); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if ( childLocatorsByHRef != null && recursive ) { foreach( ChildPresentationLocator cpl in childLocatorsByHRef.Values ) { PresentationLocator childLocator; if ( !pLink.TryGetLocator( cpl.HRef, out childLocator )) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip=null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) continue; currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return current; }
/// <returns>The parent node for this link</returns> /// <exception cref="AucentException">throws if this link does not contain any locator objects</exception> public Node CreateNode( string lang, string role , Dimension dimension ) { ArrayList nodeList = new ArrayList( locators.Count +1 ); Node parent = new Node(title); parent.MyPresentationLink = this; IDictionaryEnumerator enumer = locators.GetEnumerator(); while ( enumer.MoveNext() ) { PresentationLocator pl = (PresentationLocator)enumer.Value; if ( !pl.HasParent ) { // create all the nodes for this presentationLink try { Node childNode = pl.CreateNode(lang, role, 0, pl.href, parent, null, this, true, dimension); if ( childNode.Children == null && childNode.MyElement != null && childNode.MyElement.IsHyperCubeItem()) { //we might have decided to not show an hypercube.. as it does not have //any children nodes that are valid segments... return null; } //parent.AddChild(childNode); } catch ( Exception ex ) { string msg = ex.Message; } } } return parent; }
internal Dimension CreateCopyForMerging() { Dimension copy = new Dimension(); copy.BaseSchema = this.BaseSchema; copy.MyHref = this.MyHref; foreach (DictionaryEntry de in this.definitionLinks) { DefinitionLink dl = de.Value as DefinitionLink; copy.definitionLinks[de.Key] = dl.CreateCopyForMerging(); } return copy; }
/// <summary> /// Merges the <see cref="DefinitionLinks"/> for a parameter-supplied <see cref="Dimension"/> /// into the <see cref="DefinitionLinks"/> for this <see cref="Dimension"/>. /// </summary> /// <param name="child">The <see cref="Dimension"/> whose <see cref="DefinitionLinks"/> are to /// be merged.</param> /// <param name="errors">Initialized by method to new <see cref="ArrayList"/>; however, not /// otherwise updated.</param> public void MergeDimensionLinks(Dimension child, out ArrayList errors) { errors = new ArrayList(); if (child == null || child.DefinitionLinks == null || child.DefinitionLinks.Count == 0) return; if (this.DefinitionLinks == null || this.DefinitionLinks.Count == 0) { this.DefinitionLinks = child.DefinitionLinks; return; } IDictionaryEnumerator enumer = child.DefinitionLinks.GetEnumerator(); while (enumer.MoveNext()) { if (this.DefinitionLinks.ContainsKey(enumer.Key)) { ((DefinitionLink)this.DefinitionLinks[enumer.Key]).Append(enumer.Value as DefinitionLink, errors); } else { // otherwise, add it this.DefinitionLinks[enumer.Key] = enumer.Value; } } }