示例#1
0
        /// <summary>pass in a whole segment (of type other than MSH), including message type
        /// at the start, according to encodingChars, and we'll parse the contents and
        /// put them in props.
        /// </summary>
        protected internal static void  parseSegmentWhole(System.Collections.Specialized.NameValueCollection props, System.Collections.IDictionary segmentId2nextRepIdx, System.Collections.ArrayList msgMask, NuGenEncodingCharacters encodingChars, System.String segment)
        {
            try
            {
                System.String segmentId = segment.Substring(0, (3) - (0));

                int currentSegmentRepIdx = 0;
                if (segmentId2nextRepIdx.Contains(segmentId))
                {
                    currentSegmentRepIdx = ((System.Int32)segmentId2nextRepIdx[segmentId]);
                }
                else
                {
                    currentSegmentRepIdx = 0;
                }
                segmentId2nextRepIdx[segmentId] = (System.Int32)(currentSegmentRepIdx + 1);

                // will only bother to parse this segment if any of it's contents will
                // be dumped to props.
                bool           parseThisSegment     = false;
                NuGenDatumPath segmentIdAsDatumPath = (new NuGenDatumPath()).add(segmentId);
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = segmentIdAsDatumPath.startsWith((NuGenDatumPath)(maskIt.Current));
                }
                for (System.Collections.IEnumerator maskIt = msgMask.GetEnumerator(); !parseThisSegment && maskIt.MoveNext();)
                {
                    parseThisSegment = ((NuGenDatumPath)(maskIt.Current)).startsWith(segmentIdAsDatumPath);
                }

                if (parseThisSegment && (segment[3] == encodingChars.FieldSeparator))
                {
                    ER7SegmentHandler handler = new ER7SegmentHandler();
                    handler.m_props         = props;
                    handler.m_encodingChars = encodingChars;
                    handler.m_segmentId     = segmentId;
                    if (msgMask != null)
                    {
                        handler.m_msgMask = msgMask;
                    }
                    else
                    {
                        handler.m_msgMask = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                        handler.m_msgMask.Add(new NuGenDatumPath());                         // everything will pass this
                        // (every DatumPath startsWith the zero-length DatumPath)
                    }
                    handler.m_segmentRepIdx = currentSegmentRepIdx;

                    System.Collections.ArrayList nodeKey = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                    nodeKey.Add(0);
                    parseSegmentGuts(handler, segment.Substring(4), nodeKey);
                }
            }
            catch (System.NullReferenceException)
            {
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
示例#2
0
            public virtual void  putDatum(System.Collections.ArrayList valNodeKey, System.String value_Renamed)
            {
                // make a DatumPath from valNodeKey and info in this:
                NuGenDatumPath valDatumPath = new NuGenDatumPath();

                valDatumPath.add(m_segmentId).add(m_segmentRepIdx);
                for (int i = 0; i < valNodeKey.Count; ++i)
                {
                    // valNodeKey: everything counts from 0 -- not so with DatumPath ... sigh.
                    int itval = ((System.Int32)valNodeKey[i]);
                    valDatumPath.add((System.Object)(i == 1?itval:itval + 1));
                }

                // see if valDatumPath passes m_msgMask:
                bool valDatumPathPassesMask = false;

                for (System.Collections.IEnumerator maskIt = m_msgMask.GetEnumerator(); !valDatumPathPassesMask && maskIt.MoveNext();)
                {
                    valDatumPathPassesMask = valDatumPath.startsWith((NuGenDatumPath)(maskIt.Current));
                }

                if (valDatumPathPassesMask)
                {
                    m_props[valDatumPath.ToString()] = value_Renamed;
                }
            }
示例#3
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();
                }
            }