/// <summary>Works like String.startsWith: 
		/// returns true iff prefix.size() <= this.size()
		/// AND if, for 0 <= i < prefix.size(), this.get(i).equals(prefix.get(i))
		/// </summary>
		public virtual bool startsWith(NuGenDatumPath prefix)
		{
			bool ret = false;
			if (prefix.size() <= this.size())
			{
				ret = true;
				for (int i = 0; i < prefix.size(); ++i)
					ret &= this.get_Renamed(i).Equals(prefix.get_Renamed(i));
			}
			return ret;
		}
Example #2
0
        /// <summary>Works like String.startsWith:
        /// returns true iff prefix.size() <= this.size()
        /// AND if, for 0 <= i < prefix.size(), this.get(i).equals(prefix.get(i))
        /// </summary>
        public virtual bool startsWith(NuGenDatumPath prefix)
        {
            bool ret = false;

            if (prefix.size() <= this.size())
            {
                ret = true;
                for (int i = 0; i < prefix.size(); ++i)
                {
                    ret &= this.get_Renamed(i).Equals(prefix.get_Renamed(i));
                }
            }
            return(ret);
        }
Example #3
0
        /// <summary>toString() outputs the path (from segmentID onward) in the ZYX[a]-b[c]-d-e
        /// style (TODO: give it a name), suitable for a key in a map of
        /// message datum paths to values.
        /// </summary>
        /// <summary>Integer values are converted to strings directly (1 => "1") so when you
        /// constructed this you should have started counting from 1 for everything but
        /// the "repeat" fields, if you truly want the ZYX[a]-b[c]-d-e style.
        /// If toString() is called when this has a size in [1, 6) (=> missing numeric
        /// elments), then we act as though the elements in [size(), 6) are 0 or 1 as
        /// appropriate for each element.  We don't provide a default for the element 0
        /// (the String element): will throw an IndexOutOfBoundsException if (size() ==
        /// 1).
        /// eg. a (new DatumPath()).add(new String("ZYX")).add(2).add(6).toString()
        /// would yield "ZYX[2]-6[0]-1-1"
        /// </summary>
        public override System.String ToString()
        {
            System.Text.StringBuilder strbuf = new System.Text.StringBuilder(15);

            if (m_path.Count >= 1)
            {
                NuGenDatumPath extendedCopy = (NuGenDatumPath)this.Clone();
                extendedCopy.setSize(s_maxSize);

                for (int i = 0; i < extendedCopy.size(); ++i)
                {
                    if (i == 0)
                    {
                        strbuf.Append("" + ((System.String)extendedCopy.get_Renamed(0)));
                    }
                    else if ((i == 1) || (i == 3))
                    {
                        strbuf.Append("[" + ((System.Int32)extendedCopy.get_Renamed(i)) + "]");
                    }
                    else if ((i == 2) || (i == 4) || (i == 5))
                    {
                        strbuf.Append("-" + (((System.Int32)extendedCopy.get_Renamed(i))));
                    }
                }
            }
            else
            {
                throw new System.IndexOutOfRangeException();
            }

            return("" + strbuf);
        }
Example #4
0
 /// <summary>like a copy constructor without the constructor </summary>
 public virtual void  copy(NuGenDatumPath other)
 {
     setSize(0);
     for (int i = 0; i < other.size(); ++i)
     {
         add(other.get_Renamed(i));
     }
 }
Example #5
0
        public override bool Equals(System.Object otherObject)
        {
            bool           ret   = false;
            NuGenDatumPath other = (NuGenDatumPath)otherObject;

            if (this.size() == other.size())
            {
                ret = true;
                for (int i = 0; i < this.size(); ++i)
                {
                    ret &= this.get_Renamed(i).Equals(other.get_Renamed(i));
                }
            }

            return(ret);
        }
		/// <summary>like a copy constructor without the constructor </summary>
		public virtual void  copy(NuGenDatumPath other)
		{
			setSize(0);
			for (int i = 0; i < other.size(); ++i)
				add(other.get_Renamed(i));
		}
Example #7
0
			/* doc location == msgID & curPath together.  
			If we've encountered an element called "elementNam", then this tries 
			to determine what it is, based on what we already know about the document.
			returns true if we can make sense of this new element name given the
			position we're at (represented by msgID / curPath), 
			false if we can't (which probably means this should be a useless element). 
			returning true doesn't mean that we actually changed msgID or curPath, it
			might mean that we just passed through a segment group element OK.
			*/
			protected internal static bool tryToGrowDocLocationFromElementName(System.Text.StringBuilder msgID, NuGenDatumPath curPath, System.Collections.IDictionary segmentId2nextRepIdx, NuGenDatumPath lastDumpedPath, System.String elementName)
			{
				bool ok = false; // ok == can we make sense of this new element?
				// hmm ... where are we in the document: 
				if ((msgID.Length == 0) && (curPath.size() == 0))
				{
					// we're entering a message
					msgID.Replace(msgID.ToString(0, msgID.Length - 0), elementName, 0, msgID.Length - 0);
					segmentId2nextRepIdx.Clear();
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() == 0))
				{
					// we're entering either a segment-group element (eg. <ADT_A01.PROCEDURE>)
					// or an actual segment element.
					if (!(elementName.StartsWith("" + msgID + '.')))
					{
						// must be an actual segment.
						curPath.add(elementName);
						
						if (segmentId2nextRepIdx.Contains(elementName))
							curPath.add(segmentId2nextRepIdx[elementName]);
						else
							curPath.add((System.Object) 0);
						
						segmentId2nextRepIdx[elementName] = (System.Int32) (((System.Int32) curPath.get_Renamed(curPath.size() - 1)) + 1);
					}
					ok = true;
				}
				else if ((msgID.Length > 0) && (curPath.size() > 0))
				{
					// we're entering a field or a component or a subcomponent.
					if (curPath.size() == 2)
					{
						// we're entering a field element
						// all fields should start with segment-ID + '.' 
						if (elementName.StartsWith("" + curPath.get_Renamed(0) + '.'))
						{
							try
							{
								int fieldIdxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
								
								curPath.add((System.Object) fieldIdxFromElementName);
								
								// now add the repetition idx to curPath: 
								if ((lastDumpedPath.size() >= 4) && (((System.Int32) lastDumpedPath.get_Renamed(2)) == fieldIdxFromElementName))
								{
									// lastDumpedPath has a fieldIdx and a fieldRepIdx.
									curPath.add((System.Object) (((System.Int32) lastDumpedPath.get_Renamed(3)) + 1));
								}
								else
									curPath.add((System.Object) 0);
								
								ok = true;
							}
							catch (System.FormatException)
							{
							}
						} // else => this isn't a field -- must be useless.
					}
					else if ((curPath.size() == 4) || (curPath.size() == 5))
					{
						// we're entering a component or subcomponent element
						try
						{
							int idxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
							curPath.add((System.Object) idxFromElementName);
							ok = true;
						}
						catch (System.FormatException)
						{
						}
					}
				}
				return ok;
			}
Example #8
0
            /* doc location == msgID & curPath together.
             * If we've encountered an element called "elementNam", then this tries
             * to determine what it is, based on what we already know about the document.
             * returns true if we can make sense of this new element name given the
             * position we're at (represented by msgID / curPath),
             * false if we can't (which probably means this should be a useless element).
             * returning true doesn't mean that we actually changed msgID or curPath, it
             * might mean that we just passed through a segment group element OK.
             */
            protected internal static bool tryToGrowDocLocationFromElementName(System.Text.StringBuilder msgID, NuGenDatumPath curPath, System.Collections.IDictionary segmentId2nextRepIdx, NuGenDatumPath lastDumpedPath, System.String elementName)
            {
                bool ok = false;                 // ok == can we make sense of this new element?

                // hmm ... where are we in the document:
                if ((msgID.Length == 0) && (curPath.size() == 0))
                {
                    // we're entering a message
                    msgID.Replace(msgID.ToString(0, msgID.Length - 0), elementName, 0, msgID.Length - 0);
                    segmentId2nextRepIdx.Clear();
                    ok = true;
                }
                else if ((msgID.Length > 0) && (curPath.size() == 0))
                {
                    // we're entering either a segment-group element (eg. <ADT_A01.PROCEDURE>)
                    // or an actual segment element.
                    if (!(elementName.StartsWith("" + msgID + '.')))
                    {
                        // must be an actual segment.
                        curPath.add(elementName);

                        if (segmentId2nextRepIdx.Contains(elementName))
                        {
                            curPath.add(segmentId2nextRepIdx[elementName]);
                        }
                        else
                        {
                            curPath.add((System.Object) 0);
                        }

                        segmentId2nextRepIdx[elementName] = (System.Int32)(((System.Int32)curPath.get_Renamed(curPath.size() - 1)) + 1);
                    }
                    ok = true;
                }
                else if ((msgID.Length > 0) && (curPath.size() > 0))
                {
                    // we're entering a field or a component or a subcomponent.
                    if (curPath.size() == 2)
                    {
                        // we're entering a field element
                        // all fields should start with segment-ID + '.'
                        if (elementName.StartsWith("" + curPath.get_Renamed(0) + '.'))
                        {
                            try
                            {
                                int fieldIdxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));

                                curPath.add((System.Object)fieldIdxFromElementName);

                                // now add the repetition idx to curPath:
                                if ((lastDumpedPath.size() >= 4) && (((System.Int32)lastDumpedPath.get_Renamed(2)) == fieldIdxFromElementName))
                                {
                                    // lastDumpedPath has a fieldIdx and a fieldRepIdx.
                                    curPath.add((System.Object)(((System.Int32)lastDumpedPath.get_Renamed(3)) + 1));
                                }
                                else
                                {
                                    curPath.add((System.Object) 0);
                                }

                                ok = true;
                            }
                            catch (System.FormatException)
                            {
                            }
                        }                         // else => this isn't a field -- must be useless.
                    }
                    else if ((curPath.size() == 4) || (curPath.size() == 5))
                    {
                        // we're entering a component or subcomponent element
                        try
                        {
                            int idxFromElementName = System.Int32.Parse(elementName.Substring(elementName.IndexOf('.') + 1));
                            curPath.add((System.Object)idxFromElementName);
                            ok = true;
                        }
                        catch (System.FormatException)
                        {
                        }
                    }
                }
                return(ok);
            }
Example #9
0
            public override void  startElement(System.String uri, System.String localName, System.String qName, SaxAttributesSupport attributes)
            {
                //System.err.println("startelem: " + qName + " curpathsize; " +
                //m_curPath.size());
                bool ok = false;

                if (m_startedDocument)
                {
                    // A single unit of text data will be within a single element,
                    // -- none of it will be in sub-elements and there will be no
                    // sub-elements fragmenting the data text.
                    // Right now we're entering a new element: this means that anything
                    // in m_chars will be whitespace (likely), or text left over from,
                    // say, the last field, or text that was somewhere it shouldn't have been.
                    // (ex. "<ZYX.9> shouldn't be here <PT.1> P </PT.1> </ZYX.9>"
                    m_chars.Remove(0, m_chars.Length - 0);

                    if (m_depthWithinUselessElement >= 0)
                    {
                        ++m_depthWithinUselessElement;
                    }
                    else
                    {
                        int oldCurPathSize = m_curPath.size();
                        if (tryToGrowDocLocationFromElementName(m_msgID, m_curPath, m_segmentId2nextRepIdx, m_lastDumpedPath, qName))
                        {
                            if (m_curPath.size() > oldCurPathSize)
                            {
                                // assert (m_depthWithinUselessElement == -1) // m_curPath
                                // should not have grown if we're within a useless element.
                                if (m_depthWithinUsefulElement == -1)
                                {
                                    // this new element could match one of the DatumPaths in
                                    // m_msgMask -- if that's the case, we've just entered a
                                    // useful element.
                                    // TODO: functional stylee (a la C++'s std::accumulate) ?
                                    bool curPathStartsWithAMaskElem = false;
                                    for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !curPathStartsWithAMaskElem && maskIt.MoveNext();)
                                    {
                                        curPathStartsWithAMaskElem = m_curPath.startsWith((NuGenDatumPath)maskIt.Current);
                                    }

                                    if (curPathStartsWithAMaskElem)
                                    {
                                        m_depthWithinUsefulElement = 0;
                                    }
                                    else
                                    {
                                        // so this element we're entering is not specified by m_msgMask
                                        // to be useful -- but might it contains elements that
                                        // are?
                                        bool aMaskElemStartsWithCurPath = false;
                                        for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !aMaskElemStartsWithCurPath && maskIt.MoveNext();)
                                        {
                                            aMaskElemStartsWithCurPath = ((NuGenDatumPath)maskIt.Current).startsWith(m_curPath);
                                        }

                                        if (!aMaskElemStartsWithCurPath)
                                        {
                                            // ... nope!  useless.
                                            m_depthWithinUselessElement = 0;
                                            m_curPath.setSize(oldCurPathSize);
                                        }                                         // else => ok, carry on, m_depthWithinUse{less,ful}Element
                                                                                  // still both -1.
                                    }
                                }
                                // else => already within a useful element, don't need to compare
                                // against m_msgMask.
                            }
                        }
                        else
                        {
                            m_depthWithinUselessElement = 0;
                        }
                    }
                    ok = true;
                }

                if (!ok)
                {
                    clear();
                    throw new StopParsingException();
                }
            }