edu.iris.Fissures.seed.builder
Class ExportBuilder

java.lang.Object
  extended by edu.iris.Fissures.seed.builder.ExportBuilder
Direct Known Subclasses:
BasicExportBuilder, SacExportBuilder, SeedExportBuilder

public abstract class ExportBuilder
extends java.lang.Object

Generic Builder class for exporting objects from the Object Container to a particular file or data stream format.

Version:
7/26/2002
Author:
Robert Casey, IRIS DMC

Nested Class Summary
protected  class ExportBuilder.LogicalRecord
          Inner class representing a single logical record.
 
Field Summary
protected  java.lang.String builderType
           
protected  boolean endOfGroup
           
protected  boolean endOfLogical
           
protected  boolean endOfPhysical
           
protected  java.util.Vector exportMold
           
protected  java.lang.String[] exportScript
           
protected  int logicalPerPhysical
           
protected  ExportBuilder.LogicalRecord logicalRecord
           
protected  int logicalRecordCount
           
protected  int logicalRecordLength
           
protected  java.util.Vector logicalRecords
           
protected  int nestingDepth
           
protected  int[] nestingScore
           
protected  java.io.OutputStream outputStream
           
protected  boolean padEnabledFlag
           
protected  boolean penDown
           
protected  int physicalRecordLength
           
protected  byte recordPadding
           
protected  int scriptCursor
           
protected  int[] scriptNesting
           
protected  boolean vaxOrder
           
 
Constructor Summary
ExportBuilder()
          Create an export builder.
ExportBuilder(java.io.OutputStream outStream)
          Create an export builder connected to an output stream.
 
Method Summary
 int build(java.lang.Object obj)
          Build object into the export volume.
protected abstract  boolean checkTrigger(java.lang.String s)
          Check provided string from export script to see if it's meant to trigger a special action.
 void close()
          Close output export stream.
 void finish()
          Implement final volume closure operations.
 int getNext()
          Get next script element.
 java.lang.String getType()
          This method returns the type of builder we are in the form of a unique string.
 boolean isPaddingEnabled()
          Determines if padding is enabled or not.
 void open(java.io.OutputStream outStream)
          Open output stream for export.
protected abstract  void packToRecord()
          Pack (append) a byte array into a logical record.
protected  void padLogical()
          Pad the end of a logical record with recordPadding bytes.
protected  void padPhysical()
          Pad the end of a physical record with recordPadding bytes.
protected  void push(java.lang.Object obj)
          Push next source object into export mold.
 void setLogicalRecLen(int len)
          Set the logical record length of the output volume.
 void setPaddingEnabled(boolean b)
          Sets if padding is enabled or not.
 void setPhysicalRecLen(int len)
          Set the physical record length of the output volume.
 void setVaxOrder(boolean flag)
          Set the word-order flag for the output volume (NOT CURRENTLY IMPLEMENTED).
protected abstract  void startNewLogical(SeedObject obj, boolean continuation)
          Create a new logical record and place it in the logicalRecord instance variable SeedObject is an object to be put into the new logical record, which can help to identify the traits that that logical record will have.
 void startVolume()
          Trigger start of a new volume.
protected abstract  void volumeFinish()
          Perform any finishing operations to the export volume
protected  boolean writeRecord()
          Write a physical record of logical records to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

builderType

protected java.lang.String builderType

outputStream

protected java.io.OutputStream outputStream

exportScript

protected java.lang.String[] exportScript

scriptCursor

protected int scriptCursor

scriptNesting

protected int[] scriptNesting

nestingDepth

protected int nestingDepth

nestingScore

protected int[] nestingScore

logicalRecordLength

protected int logicalRecordLength

physicalRecordLength

protected int physicalRecordLength

logicalPerPhysical

protected int logicalPerPhysical

logicalRecordCount

protected int logicalRecordCount

logicalRecords

protected java.util.Vector logicalRecords

exportMold

protected java.util.Vector exportMold

recordPadding

protected byte recordPadding

padEnabledFlag

protected boolean padEnabledFlag

vaxOrder

protected boolean vaxOrder

endOfGroup

protected boolean endOfGroup

endOfLogical

protected boolean endOfLogical

endOfPhysical

protected boolean endOfPhysical

penDown

protected boolean penDown

logicalRecord

protected ExportBuilder.LogicalRecord logicalRecord
Constructor Detail

ExportBuilder

public ExportBuilder()
Create an export builder.


ExportBuilder

public ExportBuilder(java.io.OutputStream outStream)
              throws BuilderException
Create an export builder connected to an output stream.

Throws:
BuilderException
Method Detail

getType

public java.lang.String getType()
                         throws BuilderException
This method returns the type of builder we are in the form of a unique string.

Throws:
BuilderException

isPaddingEnabled

public boolean isPaddingEnabled()
Determines if padding is enabled or not.

Returns:
true if padding is enabled, false otherwise.

open

public void open(java.io.OutputStream outStream)
          throws BuilderException
Open output stream for export.

Throws:
BuilderException

close

public void close()
Close output export stream.


setLogicalRecLen

public void setLogicalRecLen(int len)
Set the logical record length of the output volume.


setPaddingEnabled

public void setPaddingEnabled(boolean b)
Sets if padding is enabled or not.

Parameters:
b - true if padding is enabled, false otherwise.

setPhysicalRecLen

public void setPhysicalRecLen(int len)
Set the physical record length of the output volume.


setVaxOrder

public void setVaxOrder(boolean flag)
Set the word-order flag for the output volume (NOT CURRENTLY IMPLEMENTED).


startVolume

public void startVolume()
                 throws BuilderException
Trigger start of a new volume.

Throws:
BuilderException

getNext

public int getNext()
            throws java.lang.Exception
Get next script element. Return the next object type in a scripted series object type numbers, representing a concrete subclass of this builder. The script is a String array, with each element containing either a non-zero integer value, a trigger string, or a control character.
-- The a positive integer value corresponds to an object type. This value is returned to the caller.
-- A -1 value indicates that there are no more script elements. Return this value to the caller. The caller should properly interpret this as end of script.
-- A -2 value indicates end of pass, which means that there may be more script elements, but that the director providing the source data should reset its object sequencer to release all of its objects again for build() calls. In Director parlance, its ExportTemplate has all of its indexes reset to 1. A -2 may be needed by the concrete builder to do a two-pass or multi-pass compilation of object data.
-- Brackets ('[' and ']') signify that a group of values in between constitute a single output byte array element. Brackets cannot be nested.
-- Parentheses ('(' and ')') signify that a loop occurs over the elements between them until no more objects can be drawn out of the loop. These loops can be nested.
-- A less-than symbol ('<') signifies that the logical record should be ended, with character padding added to fill out the logical record.
-- A double less-than ('<<') signifies that the physical record should be ended, with character padding added to fill out the physical record. This also forces a write to the export stream.
-- A caret ('^') signals 'pen-up', which means that calls to writeRecord() will not result in logicalRecord and physicalRecord data going to the OutputStream.
This is typically used for build simulations to get information on the volume's structure.
-- A lower-case vee ('v') character signals 'pen-down', which resets writeRecord() to output data in the logical and physical records to the OutputStream. This is the default mode.
-- Other strings can be used to trigger actions between object type acquisition. These actions must be implemented by the checkTrigger() method in the concrete version of ExportBuilder.
The script represents the pattern of objects required by this builder to construct an output stream of bytes of the intended data format.

Throws:
java.lang.Exception

build

public int build(java.lang.Object obj)
          throws java.lang.Exception
Build object into the export volume. Director passes next object to the builder to be incorporated into the export volume. Return the number of *new* logical records constructed during this method call. pen-up mode (simulation) object processing will not count the logical records produced.

Throws:
java.lang.Exception

finish

public void finish()
            throws java.lang.Exception
Implement final volume closure operations.

Throws:
java.lang.Exception

push

protected void push(java.lang.Object obj)
             throws java.lang.Exception
Push next source object into export mold. This is followed by packing to a byte array, followed by packing to a physical record, followed by output to the output stream.

Throws:
java.lang.Exception

writeRecord

protected boolean writeRecord()
                       throws java.lang.Exception
Write a physical record of logical records to the output stream. Dequeue the logical records used in the physical record from the logicalRecords vector. if penDown is false, then nothing is written to the output stream, and the logical records are simply dequeued. return true if there is still logicalRecord data remaining.

Throws:
java.lang.Exception

padLogical

protected void padLogical()
Pad the end of a logical record with recordPadding bytes. Shift the logical record position to equal logicalRecordLength. Push the logical record onto the vector and clear the current register.


padPhysical

protected void padPhysical()
                    throws java.lang.Exception
Pad the end of a physical record with recordPadding bytes. Push the latest partial logical record onto the logical records vector and pad it. Generate extra empty logical records if necessary.

Throws:
java.lang.Exception

packToRecord

protected abstract void packToRecord()
                              throws java.lang.Exception
Pack (append) a byte array into a logical record. Use objects from the exportMold as the data source. If the current logical record is full, append the current one to the logicalRecords vector and start a new one. This method knows how to properly start, preface, and finish a complete logical record.

Throws:
java.lang.Exception

checkTrigger

protected abstract boolean checkTrigger(java.lang.String s)
                                 throws java.lang.Exception
Check provided string from export script to see if it's meant to trigger a special action. If so, implement the intended action. Return true if the string is a trigger.

Throws:
java.lang.Exception

volumeFinish

protected abstract void volumeFinish()
                              throws BuilderException
Perform any finishing operations to the export volume

Throws:
BuilderException

startNewLogical

protected abstract void startNewLogical(SeedObject obj,
                                        boolean continuation)
                                 throws java.lang.Exception
Create a new logical record and place it in the logicalRecord instance variable SeedObject is an object to be put into the new logical record, which can help to identify the traits that that logical record will have. If SeedObject is null, this implies that a blank logical record is being created. continuation, when set to true, can mark the logical record as a continuation of the last one.

Throws:
java.lang.Exception