edu.nrao.sss.model.source.parser
Class AbstractSourceCatalogReader

java.lang.Object
  extended by edu.nrao.sss.model.source.parser.AbstractSourceCatalogReader
All Implemented Interfaces:
SourceCatalogReader
Direct Known Subclasses:
CarmaSourceCatalogReader, GbtSourceCatalogReader, OldVlbaSourceCatalogReader, PdBISourceCatalogReader, PstSourceCatalogReader, VlaCalibDbHtmlReader, VlbaSourceCatalogReader, XmlSourceCatalogReader

public abstract class AbstractSourceCatalogReader
extends Object
implements SourceCatalogReader

An abstract implementation of the common methods in the SourceCatalogReader interface.

CVS Info:

$Revision: 630 $
$Date: 2007-05-18 14:12:55 -0600 (Fri, 18 May 2007) $
$Author: dharland $


Field Summary
protected  SourceCatalog catalog
           
protected  List<edu.nrao.sss.model.source.parser.ParseError> errors
           
protected  String histRecPrefix
           
protected  boolean readWasSuccessful
           
protected  String sourceInfoOrigin
           
 
Constructor Summary
AbstractSourceCatalogReader()
           
 
Method Summary
 SourceCatalog getCatalog()
          Returns the catalog most recently created by this reader.
 String getError(int index)
          Returns the indexth error found during the most recent read.
 int getErrorCount()
          Returns the number of errors found during the most recent read.
 StringBuilder getErrors()
          Returns the combined text of all errors found during the most recent read.
 String getOriginOfSourceInformation()
           
 String getPrefixForHistoricalRecords()
           
 boolean getSuccess()
          Returns true if the most recently read data caused no parsing errors.
protected  void putError(int lineNum, String message)
          Adds a new parsing error to our list.
 boolean read(InputStream in)
          A default implementation of SourceCatalogReader.read(InputStream).
 boolean read(InputStream in, FileCompressionFormat format)
          A default implementation of SourceCatalogReader.read(InputStream, FileCompressionFormat).
 boolean read(InputStream in, SourceCatalog destination)
          A default implementation of SourceCatalogReader.read(InputStream, SourceCatalog).
 boolean read(InputStream in, SourceCatalog destination, FileCompressionFormat format)
          This method prepares the input stream in to be passed as an InputStreamReader to read(Reader, SourceCatalog).
 boolean read(Reader in)
          A default implementation of SourceCatalogReader.read(Reader).
abstract  boolean read(Reader in, SourceCatalog destination)
          An abstract method that must be implemented by subclasses.
 boolean read(String fileName)
          A default implementation of SourceCatalogReader.read(String).
 boolean read(String fileName, SourceCatalog destination)
          A default implementation of SourceCatalogReader.read(String, SourceCatalog).
 void setOriginOfSourceInformation(String origin)
          Sets text that will be used as the source of information for each source read by this reader.
 void setPrefixForHistoricalRecords(String prefix)
          Sets text that will be used as a prefix for any historical source records generated by this reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

catalog

protected SourceCatalog catalog

readWasSuccessful

protected boolean readWasSuccessful

errors

protected List<edu.nrao.sss.model.source.parser.ParseError> errors

sourceInfoOrigin

protected String sourceInfoOrigin

histRecPrefix

protected String histRecPrefix
Constructor Detail

AbstractSourceCatalogReader

public AbstractSourceCatalogReader()
Method Detail

read

public boolean read(String fileName)
             throws FileNotFoundException
A default implementation of SourceCatalogReader.read(String). This calls read(String, SourceCatalog) with a null catalog.

Specified by:
read in interface SourceCatalogReader
Parameters:
fileName - the name of a data file.
Returns:
true if nothing unexpected occurred while reading data.
Throws:
FileNotFoundException - if the data file could not be found.
See Also:
SourceCatalogReader.read(Reader, SourceCatalog)

read

public boolean read(String fileName,
                    SourceCatalog destination)
             throws FileNotFoundException
A default implementation of SourceCatalogReader.read(String, SourceCatalog). This calls read(Reader, SourceCatalog), wrapping fileName with a FileReader.

Specified by:
read in interface SourceCatalogReader
Parameters:
fileName - the name of a data file.
destination - the catalog to which the sources should be added. If this parameter is null, a new catalog will be created.
Returns:
true if nothing unexpected occurred while reading data.
Throws:
FileNotFoundException - if the data file could not be found.
See Also:
SourceCatalogReader.read(Reader, SourceCatalog)

read

public boolean read(Reader in)
A default implementation of SourceCatalogReader.read(Reader). This calls read(Reader, SourceCatalog) with a null catalog.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
SourceCatalogReader.read(Reader, SourceCatalog)

read

public boolean read(InputStream in)
A default implementation of SourceCatalogReader.read(InputStream). This calls read(InputStream, SourceCatalog, FileCompressionFormat) with a null catalog and a UNCOMPRESSED format.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
SourceCatalogReader.read(InputStream, SourceCatalog)

read

public boolean read(InputStream in,
                    SourceCatalog destination)
A default implementation of SourceCatalogReader.read(InputStream, SourceCatalog). This calls read(InputStream, SourceCatalog, FileCompressionFormat) with a UNCOMPRESSED format.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
destination - the catalog to which the sources should be added. If this parameter is null, a new catalog will be created.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
SourceCatalogReader.getCatalog(), SourceCatalogReader.getErrors()

read

public boolean read(InputStream in,
                    FileCompressionFormat format)
A default implementation of SourceCatalogReader.read(InputStream, FileCompressionFormat). This calls read(InputStream, SourceCatalog, FileCompressionFormat) with a null catalog.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
SourceCatalogReader.getCatalog(), SourceCatalogReader.getErrors()

read

public boolean read(InputStream in,
                    SourceCatalog destination,
                    FileCompressionFormat format)
This method prepares the input stream in to be passed as an InputStreamReader to read(Reader, SourceCatalog). If format is ZIP or GZ, the InputStream is wrapped in a ZipInputStream or GZIPInputStream respectively before being wrapped in an InputStreamReader. This allows the primary read method (which is abstract in this class) to be unaware that the input was compressed. If format is null or UNCOMPRESSED, in is passed directly into the InputStreamReader constructor.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
destination - the catalog to which the sources should be added. If this parameter is null, a new catalog will be created.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
SourceCatalogReader.getCatalog(), SourceCatalogReader.getErrors()

read

public abstract boolean read(Reader in,
                             SourceCatalog destination)
An abstract method that must be implemented by subclasses. All other read methods delegate to this one.

Specified by:
read in interface SourceCatalogReader
Parameters:
in - the source of text that can be read and turned into Source objects.
destination - the catalog to which the sources should be added. If this parameter is null, a new catalog will be created.
Returns:
true if nothing unexpected occurred while reading data.
See Also:
read(Reader, SourceCatalog)

getErrors

public StringBuilder getErrors()
Description copied from interface: SourceCatalogReader
Returns the combined text of all errors found during the most recent read.

Note that an "error" is anything unexpected encountered while reading. Not all errors are harmful. The text of each error includes the line number where it occurred and an explanation of what was wrong.

Specified by:
getErrors in interface SourceCatalogReader
Returns:
the combined text of all errors found during the most recent read.
See Also:
SourceCatalogReader.getErrors()

getError

public String getError(int index)
Description copied from interface: SourceCatalogReader
Returns the indexth error found during the most recent read.

Specified by:
getError in interface SourceCatalogReader
Parameters:
index - a positional value >= zero and < SourceCatalogReader.getErrorCount().
Returns:
the indexth error found during the most recent read.
See Also:
SourceCatalogReader.getError(int)

getErrorCount

public int getErrorCount()
Description copied from interface: SourceCatalogReader
Returns the number of errors found during the most recent read.

Specified by:
getErrorCount in interface SourceCatalogReader
Returns:
the number of errors found during the most recent read.
See Also:
SourceCatalogReader.getErrorCount()

getCatalog

public SourceCatalog getCatalog()
Description copied from interface: SourceCatalogReader
Returns the catalog most recently created by this reader.

If this reader had trouble parsing the catalog data, the returned catalog may be partially or completely unfilled. If the read method has never been called, a new catalog will be returned.

Specified by:
getCatalog in interface SourceCatalogReader
Returns:
the catalog most recently created by this reader. This value is guaranteed to be non-null.
See Also:
SourceCatalogReader.getCatalog()

getSuccess

public boolean getSuccess()
Description copied from interface: SourceCatalogReader
Returns true if the most recently read data caused no parsing errors. Note that the SourceCatalog created by this reader may be perfectly fine even if this method returns false.

Specified by:
getSuccess in interface SourceCatalogReader
Returns:
true if there were no incidents during the most recent read.
See Also:
SourceCatalogReader.getSuccess()

setOriginOfSourceInformation

public void setOriginOfSourceInformation(String origin)
Description copied from interface: SourceCatalogReader
Sets text that will be used as the source of information for each source read by this reader.

Specified by:
setOriginOfSourceInformation in interface SourceCatalogReader
Parameters:
origin - text that will be used as the source of information for each source read by this reader. A value of null will be interpreted as a single not to set the source's origin of information.
See Also:
SourceCatalogReader.setOriginOfSourceInformation(String)

getOriginOfSourceInformation

public String getOriginOfSourceInformation()

setPrefixForHistoricalRecords

public void setPrefixForHistoricalRecords(String prefix)
Description copied from interface: SourceCatalogReader
Sets text that will be used as a prefix for any historical source records generated by this reader.

Specified by:
setPrefixForHistoricalRecords in interface SourceCatalogReader
Parameters:
prefix - text that will be used as a prefix for any historical source records generated by this reader.
See Also:
SourceCatalogReader.setPrefixForHistoricalRecords(String)

getPrefixForHistoricalRecords

public String getPrefixForHistoricalRecords()

putError

protected void putError(int lineNum,
                        String message)
Adds a new parsing error to our list.



Copyright © 2009. All Rights Reserved.