001: /*
002: * @(#)DefaultParserCollator.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Part of the GroboUtils package at:
009: * http://groboutils.sourceforge.net
010: *
011: * Permission is hereby granted, free of charge, to any person obtaining a
012: * copy of this software and associated documentation files (the "Software"),
013: * to deal in the Software without restriction, including without limitation
014: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
015: * and/or sell copies of the Software, and to permit persons to whom the
016: * Software is furnished to do so, subject to the following conditions:
017: *
018: * The above copyright notice and this permission notice shall be included in
019: * all copies or substantial portions of the Software.
020: *
021: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
022: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
024: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
025: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
026: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
027: * DEALINGS IN THE SOFTWARE.
028: */
029: package net.sourceforge.groboutils.pmti.v1.itf.parser;
030:
031: import net.sourceforge.groboutils.pmti.v1.itf.ITestIssueRecord;
032: import net.sourceforge.groboutils.pmti.v1.itf.ITestIssueRecordSet;
033: import net.sourceforge.groboutils.pmti.v1.itf.impl.DefaultTestIssueRecordSet;
034:
035: import java.util.Vector;
036: import java.util.Enumeration;
037:
038: /**
039: * Logic to extract parser parsed test-issue records into logically separated
040: * sets of records.
041: *
042: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
043: * @version $Date: 2003/02/10 22:52:01 $
044: * @since July 7, 2002
045: */
046: public class DefaultParserCollator implements IParserCollator {
047:
048: private Vector parsers = new Vector();
049: private ITestIssueRecordSet parsed;
050:
051: /**
052: * Adds a new parser to the internal collection. It is up to the
053: * individual collator to lazily parse the records or parse the records
054: * at the time of this invocation.
055: * <P>
056: * It is illegal to invoke this method after a call to
057: * <tt>getRecords()</tt>.
058: *
059: * @param p parser to add, which may be <tt>null</tt> (which should never
060: * cause an error).
061: * @exception IllegalStateException thrown if this is called after the
062: * <tt>getRecords()</tt> method has been invoked.
063: */
064: public void addParser(IParser p) {
065: if (this .parsers == null) {
066: throw new IllegalStateException(
067: "already called getRecords()");
068: }
069: if (p != null) {
070: this .parsers.addElement(p);
071: }
072: }
073:
074: /**
075: * Returns the parsed test-issue records, divided into logically separated
076: * collections.
077: */
078: public synchronized ITestIssueRecordSet getRecords()
079: {
080: if (this.parsers == null)
081: {
082: return this.parsed;
083: }
084:
085: Vector records = new Vector();
086: Enumeration enum = this.parsers.elements();
087: this.parsers = null;
088: while (enum.hasMoreElements())
089: {
090: ITestIssueRecord[] r = ((IParser)enum.nextElement()).parse();
091: if (r != null)
092: {
093: for (int i = 0; i < r.length; ++i)
094: {
095: if (r[i] != null)
096: {
097: records.addElement( r[i] );
098: }
099: }
100: }
101: }
102:
103:
104: ITestIssueRecord[] r = new ITestIssueRecord[ records.size() ];
105: records.copyInto( r );
106: this.parsed = new DefaultTestIssueRecordSet( r );
107: return this.parsed;
108: }
109: }
|