Example #1
0
			/// <summary>
			/// Once we know that we need to create a new entry/import class, we need to know where
			/// to insert the new entry.  We used to be linear (stack based) but are now tree based so
			/// a more robust routine is now needed.
			/// This will make the newly added entry the 'current' as well as closing any that need
			/// to be closed.
			/// </summary>
			/// <param name="name"></param>
			/// <returns></returns>
			public bool AddNewEntry(string name, string sfm, byte[] sfmData, int line, bool isUnique, out ImportObject addedEntry)
			{
				addedEntry = null;
//				ClsHierarchyEntry entry = m_converter.m_Hierarchy[name] as ClsHierarchyEntry;

				// find all the currently open parent objects for this new entry
				ArrayList possibleParents = new ArrayList();
				SearchHierarcyForParentsOf(m_root, name, ref possibleParents);

				ImportObject bestParent = GetBestOpenParent(possibleParents);
				if (bestParent != null)
				{
					ImportObject newEntry = new ImportObject(name, bestParent);
					addedEntry = newEntry;
					bestParent.AddChild(newEntry);
					this.AddNewObject(newEntry);	// will set current and add to m_opennodes hash
					newEntry.AddPendingSfmData(sfm, sfmData, line, isUnique);
#if TracingOutput
					System.Diagnostics.Debug.WriteLine("Adding pending sfm to <" + newEntry.Name + "> : " + sfm);
#endif
					return true;
				}
				else	// no possible open parent, have to add atleast one entry
				{
				}
//				if (possibleParents.Count == 0)
//				{
//					ArrayList neededParents = new ArrayList();
//					//neededParents.Add(
//					// this is a case where one or more parents are needed first
//					// ex: found the begin marker for a 'picture' but there isn't
//					//     currently a 'sense' open.
//				}
#if false

				// First lets take the currentPath items and put them into a hash and add the depth
				// as the value item.
				Hashtable currentPathDepths = new Hashtable();
				int currentPathDepth = 0;

				// walk the tree building the hashtable, just from current up to root
				ImportObject node = this.Current;
				while (node != null)
				{
					currentPathDepths.Add(node.Name, currentPathDepth++);
					node = node.Parent;
				}

					// see if the destination is in the currentPath
					if (currentPathDepths.ContainsKey(name))
					{
						downPath.Push( new ClsPathObject(destination.KEY));
					}
					else
					{
						// check each ancestor of the destination item
						string currentBestAncestor = null;
						int currentBestDepth = Int32.MaxValue;
						foreach(string name in destination.Ancestors)
						{
							if (currentPathDepths.ContainsKey(name))
							{
								int depth = (int)(currentPathDepths[name]);
								if (depth < currentBestDepth)
								{
									currentBestAncestor = name;
									currentBestDepth = depth;
								}
							}
						}

						// see if we've found a common ancestor
						if (currentBestAncestor != null)
						{
							downPath.Push(new ClsPathObject(destination.KEY));
							downPath.Push(new ClsPathObject(currentBestAncestor));
						}
					}

					return downPath;
#endif
				return false;
			}