net.sourceforge.esw.collection
Class FixedPositionTransducer

java.lang.Object
  |
  +--net.sourceforge.esw.collection.ATransducer
        |
        +--net.sourceforge.esw.collection.AIOTransducer
              |
              +--net.sourceforge.esw.collection.FixedPositionTransducer
All Implemented Interfaces:
IIOTransducer, ITransducer, java.io.Serializable

public class FixedPositionTransducer
extends AIOTransducer

Transduces data that has a fixed position within a stream.

This transduction occurs both ways; put() takes data from the IMetaCollection instance to which this ITransducer instance is attached and places it into the data source represented by this ITransducer instance. The get() method takes data from the data source represented by this ITransducer instance and places it into the IMetaCollection instance to which this ITransducer instance is attached.

This IIOTransducer instance provides stream-based access for stream-based ITransducer implementors. It abstracts out the setting and getting of the streams, or the Reader instances and the Writer instances, into this interface.

Fixed position data is data that has a fixed width for each data element. For example, the first data element has 10 characters, the secondhas 20 characters, and etc.

Example:

    IMetaCollection meta = MetaFactory.createMetaCollection();
    FixedPositionTransducer transducer = new FixedPositionTransducer();
    transducer.setReader( getMyReader() ); // for files or strings or others...
    transducer.addWidth( 10 ); // this sets the first column to 10 characters
    transducer.addWidth( 20 ); // this sets the second column to 20 characters
    ...
    meta.setTransducer( transducer );
    try {
      meta.get();
    }
    catch ( TransducerException te ) {
      te.printStackTrace(); // in case something went wrong.
    }
 

See Also:
Serialized Form

Field Summary
protected  java.util.ArrayList positions
          The widths of each of the columns, in the order which they occur in the data.
 
Fields inherited from class net.sourceforge.esw.collection.AIOTransducer
reader, writer
 
Fields inherited from class net.sourceforge.esw.collection.ATransducer
contextFactory
 
Constructor Summary
FixedPositionTransducer()
          Creates a new FixedPositionTransducer instance.
FixedPositionTransducer(java.util.List aWidths)
          Creates a new FixedPositionTransducer instance with the specified widths.
 
Method Summary
 void addWidth(int aWidth)
          Adds a width to this FixedPositionTransducer instance.
 void get(IMetaCollection aCollection)
          Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.
 int getWidth(int aPosition)
          Returns the width at the specified position for this FixedPositionTransducer instance.
 void put(IMetaCollection aCollection)
          Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
protected  INode setupBasicNodeStructure()
          Returns the graph from the INodeContextFactory instance.
 void setWidth(int aPosition, int aWidth)
          Sets the width at the specified position for this FixedPositionTransducer instance.
 
Methods inherited from class net.sourceforge.esw.collection.AIOTransducer
getReader, getWriter, setReader, setWriter
 
Methods inherited from class net.sourceforge.esw.collection.ATransducer
getContextFactory, setContextFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.esw.collection.ITransducer
getContextFactory, setContextFactory
 

Field Detail

positions

protected java.util.ArrayList positions
The widths of each of the columns, in the order which they occur in the data.
Constructor Detail

FixedPositionTransducer

public FixedPositionTransducer()
Creates a new FixedPositionTransducer instance.

FixedPositionTransducer

public FixedPositionTransducer(java.util.List aWidths)
Creates a new FixedPositionTransducer instance with the specified widths.
Parameters:
aWidths - a List of widths to add to this FixedPositionTransducer instance.
Method Detail

setWidth

public void setWidth(int aPosition,
                     int aWidth)
Sets the width at the specified position for this FixedPositionTransducer instance.
Parameters:
aWidth - the width at the position for this FixedPositionTransducer instance to use.
aPosition - the position of the width.
Throws:
java.lang.IndexOutOfBoundsException - if the specified position is greater than the number of previously added widths.
See Also:
getWidth( int ), addWidth( int )

addWidth

public void addWidth(int aWidth)
Adds a width to this FixedPositionTransducer instance.
Parameters:
aWidth - the width to add to this FixedPositionTransducer instance.
See Also:
getWidth( int ), setWidth( int, int )

getWidth

public int getWidth(int aPosition)
Returns the width at the specified position for this FixedPositionTransducer instance.
Parameters:
aPosition - the position of the width to return.
See Also:
addWidth( int ), setWidth( int, int )

get

public void get(IMetaCollection aCollection)
         throws TransducerException
Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.

This implementation cannot pad data or provide missing fields.

Parameters:
aCollection - the IMetaCollection instance into which to read.
Throws:
TransducerException - if an error occurs during transduction.
See Also:
put( IMetaCollection )

put

public void put(IMetaCollection aCollection)
         throws TransducerException
Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
Parameters:
aCollection - the IMetaCollection instance from which to take data.
Throws:
TransducerException - if an error occurs during transduction.
See Also:
get( IMetaCollection )

setupBasicNodeStructure

protected INode setupBasicNodeStructure()
Returns the graph from the INodeContextFactory instance. If the graph doesn't contain enough depth to support the current number of delimiters, builds the structure up until the depth of the graph is equal to the number of delimiters.
Returns:
INode The graph structure.


Copyright 2002 Free Software Foundation. All Rights Reserved.