net.sourceforge.esw.collection
Class DictionaryTransducer

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

public class DictionaryTransducer
extends AIOTransducer
implements IIOTransducer

Transduces a dictionary (name=value) based data source.

Performs transduction against a stream of data from either a Reader or a Writer.

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 readers and the writers, into this interface.

For specific type of streams, like file-based streams or string-based streams, see the TransducerAdapter objects.

This DictionaryTransducer instance transduces name/value pairs seperated by a specified delimiter. All dictionary based data sources can be considered to be only a single row. That is, the depth of the INode instance that the data is read into is 1. Data sources like the java.util.Properties format are dictionary based formats.

Example:

    // for Properties based data formats...
    IMetaCollection meta = MetaFactory.createMetaCollection();
    DictionaryTransducer transducer = new DictionaryTransducer();
    transducer.setReader( getMyReader() ); // for files or strings or others...
    transducer.setDelimiter( "=" );  // this will parse commas first, then
    meta.setTransducer( transducer );
    try {
      meta.get();
    }
    catch ( TransducerException te ) {
      te.printStackTrace(); // in case something went wrong.
    }
 

See Also:
FileTransducerAdapter, StringTransducerAdapter, URLTransducerAdapter, IMetaCollection, Serialized Form

Field Summary
protected  java.lang.String delimiter
          The delimiter which seperates the name from the value in this DictionaryTransducer instance.
 
Fields inherited from class net.sourceforge.esw.collection.AIOTransducer
reader, writer
 
Fields inherited from class net.sourceforge.esw.collection.ATransducer
contextFactory
 
Constructor Summary
DictionaryTransducer()
          Creates a new DictionaryTransducer instance.
DictionaryTransducer(java.lang.String aDelimiter)
          Creates a new DictionaryTransducer instance with the specified delimiter.
 
Method Summary
protected  void checkMetaCollectionNotNull(IMetaCollection aCollection)
          If the specified IMetaCollection instance is null, throws a TransducerException stating so.
protected  void checkParameters()
          If the required parameters are null or empty, throws a TransducerException stating that the parameter cannot be null or empty.
 void get(IMetaCollection aCollection)
          Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.
 java.lang.String getDelimiter()
          Returns the delimiter for this DictionaryTransducer instance.
 void put(IMetaCollection aCollection)
          Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
 void setDelimiter(java.lang.String aDelimiter)
          Sets the delimiter for this DictionaryTransducer 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.IIOTransducer
getReader, getWriter, setReader, setWriter
 
Methods inherited from interface net.sourceforge.esw.collection.ITransducer
getContextFactory, setContextFactory
 

Field Detail

delimiter

protected java.lang.String delimiter
The delimiter which seperates the name from the value in this DictionaryTransducer instance.
Constructor Detail

DictionaryTransducer

public DictionaryTransducer()
Creates a new DictionaryTransducer instance.

DictionaryTransducer

public DictionaryTransducer(java.lang.String aDelimiter)
Creates a new DictionaryTransducer instance with the specified delimiter.
Parameters:
aDelimiter - the delimiter for this DictionaryTransducer instance that seperates the name from the value.
Method Detail

setDelimiter

public void setDelimiter(java.lang.String aDelimiter)
Sets the delimiter for this DictionaryTransducer instance.
Parameters:
aDelimiter - the delimiter for this DictionaryTransducer instance that seperates the name from the value.

getDelimiter

public java.lang.String getDelimiter()
Returns the delimiter for this DictionaryTransducer instance.

put

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

get

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

checkMetaCollectionNotNull

protected void checkMetaCollectionNotNull(IMetaCollection aCollection)
                                   throws TransducerException
If the specified IMetaCollection instance is null, throws a TransducerException stating so. Otherwise, returns normally.
Parameters:
aCollection - the IMetaCollection instance to check if null.
Throws:
TransducerException - if the specified IMetaCollection instance is null.

checkParameters

protected void checkParameters()
                        throws TransducerException
If the required parameters are null or empty, throws a TransducerException stating that the parameter cannot be null or empty. Otherwise, returns normally.
Throws:
TransducerException - if the required parameters are null or empty.


Copyright 2002 Free Software Foundation. All Rights Reserved.