org.jmonks.batch.io
Class FileSpec

java.lang.Object
  extended byorg.jmonks.batch.io.FileSpec
Direct Known Subclasses:
DelimitedFlatFileFileSpec, FixedWidthFlatFileFileSpec, XMLFileSpec

public abstract class FileSpec
extends java.lang.Object

FileSpec represents the file contains specification (spec for short) of any file to read or write using this package. This provides the factory method to create the FileSpec object from a file contains the spec and necessary methods to access the record spec objects.

File spec defines the file type and possible records could exists in the file. Every file spec will contains one or more record specs. Element file-spec should contain one attribute file-type defines the type of the file this spec is going to represent. Based on the file type, there could be other attributes in file-spec element along with file-type attribute. These attributes can be found from the javadoc of the particular file type file specs. Here is a sample file-spec configuration.

      <file-spec file-type="fixed-width-flat">
          <record-spec record-type="DETAIL">
          </record-spec>
      </file-spec>
  

Since:
1.0
Version:
1.0
Author:
Suresh Pragada

Field Summary
static java.lang.String FILE_SPEC_TAG_NAME
          Constant defines the file spec tage name.
static java.lang.String FILE_TYPE_ATTRIB_NAME
          Constant defines the attribute name file type should contain.
protected  FileType fileType
          Holds the type of the file this spec is representing.
protected  java.util.Map recordSpecMap
          Map holds the record specs with their record types as keys.
 
Constructor Summary
protected FileSpec(FileType fileType)
          Constructs the FileSpec object by accepting file type.
 
Method Summary
protected  boolean addRecordSpec(RecordSpec recordSpec)
          Adds the record spec to the file spec.
static FileSpec createFileSpec(java.io.InputStream fileSpecInputStream)
           Creates the file spec object from the file contains the spec.
 FileType getFileType()
          Gets the file type.
 RecordSpec getRecordSpec(RecordType recordType)
          Gets the record spec associated with the given record type.
 java.util.Collection getRecordSpecs()
           Gets all the record spec's in this file spec as a list.
 boolean isValidRecordType(RecordType recordType)
          Tells whether a record spec is exists with the given record type in the file spec.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileType

protected FileType fileType
Holds the type of the file this spec is representing.


recordSpecMap

protected java.util.Map recordSpecMap
Map holds the record specs with their record types as keys.


FILE_SPEC_TAG_NAME

public static final java.lang.String FILE_SPEC_TAG_NAME
Constant defines the file spec tage name.

See Also:
Constant Field Values

FILE_TYPE_ATTRIB_NAME

public static final java.lang.String FILE_TYPE_ATTRIB_NAME
Constant defines the attribute name file type should contain.

See Also:
Constant Field Values
Constructor Detail

FileSpec

protected FileSpec(FileType fileType)
Constructs the FileSpec object by accepting file type.

Parameters:
fileType - Type of the file this spec is representing.
Method Detail

addRecordSpec

protected boolean addRecordSpec(RecordSpec recordSpec)
Adds the record spec to the file spec.

Parameters:
recordSpec - Record spec to be added to the file spec.
Returns:
Returns true, if record spec is added, false otherwise.
Throws:
java.lang.IllegalArgumentException - If recordSpec is null.
FileSpecException - If multiple record specs configured with same record type.

getRecordSpecs

public java.util.Collection getRecordSpecs()

Gets all the record spec's in this file spec as a list. TODO :: There is chance that client might misuse this list. Based on the performance create a new list and return it.

Returns:
Returns record spec's as a collection.

getRecordSpec

public RecordSpec getRecordSpec(RecordType recordType)
Gets the record spec associated with the given record type.

Parameters:
recordType - Record types associated with the record spec.
Returns:
Retruns the record spec associated with the record type, null if record spec could not be found.
Throws:
java.lang.IllegalArgumentException - If recordType is null.

isValidRecordType

public boolean isValidRecordType(RecordType recordType)
Tells whether a record spec is exists with the given record type in the file spec.

Parameters:
recordType - Type of the record to check in the file spec.
Returns:
Return true if there is a record spec with this type, false otherwise.

getFileType

public FileType getFileType()
Gets the file type.

Returns:
Returns the file type.

createFileSpec

public static FileSpec createFileSpec(java.io.InputStream fileSpecInputStream)

Creates the file spec object from the file contains the spec. This looks for the file-type attribute in file-spec element and creates the appropriate file spec object.

Parameters:
fileSpecInputStream - Input stream represents the file spec.
Returns:
Returns the file spec object.
Throws:
FileSpecException - If file-type attribute is missing or doesnt consists of the type available FileType class or given file cannot be found or cannot parse the file.