net.sourceforge.esw.collection
Class StringTransducerAdapter

java.lang.Object
  |
  +--net.sourceforge.esw.collection.ATransducerAdapter
        |
        +--net.sourceforge.esw.collection.StringTransducerAdapter
All Implemented Interfaces:
ITransducer, java.io.Serializable

public class StringTransducerAdapter
extends ATransducerAdapter
implements ITransducer

Performs transduction to or against a String of data.

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 instance and the Writer instance, into this interface.

This implementation of the StringTransducerAdapter delegates all get and put method invocations to the contained IIOTransducer instance. Also, this StringTransducerAdapter instance provides convenience methods to transduce to or against a String of data.

Example:

    IMetaCollection meta = MetaFactory.createMetaCollection();
    IIOTransducer transducer = createIOTransducer() // for whatever
                                                    // IIOTransducer instance
                                                    // you need to use.
    StringTransducerAdapter adapter = new StringTransducerAdapter( getStringData(), // the String data
                                                                   transducer );
    meta.setTransducer( adapter ); // Notice it is the Adapter set on the
                                   // IMetaCollectsion instance!
    try {
      meta.put();
    }
    catch ( TransducerException te ) {
      te.printStackTrace(); // in case something went wrong.
    }
 

See Also:
Serialized Form

Field Summary
protected  java.lang.String myString
          The String of data that is get into the contained IIOTransducer instance.
protected  java.io.StringWriter sWriter
          The StringWriter used to capture data from a put method invocation.
 
Fields inherited from class net.sourceforge.esw.collection.ATransducerAdapter
ioTransducer
 
Constructor Summary
StringTransducerAdapter()
          Creates a new StringTransducerAdapter instance.
StringTransducerAdapter(IIOTransducer aIIOTransducer)
          Creates a new StringTransducerAdapter instance, delegating all get and put method invocations to the specified IIOTransducer instance.
StringTransducerAdapter(java.lang.String aString)
          Creates a new StringTransducerAdapter instance using the specified String as the data for the get method invocation.
StringTransducerAdapter(java.lang.String aString, IIOTransducer aIIOTransducer)
          Creates a new StringTransducerAdapter instance with the specified String, delegating all get and put method invocations to the specified IIOTransducer instance.
 
Method Summary
 void get(IMetaCollection aCollection)
          Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.
 java.lang.String getString()
          Returns the String of data this StringTransducerAdapter instance received from its put method invocation.
 void put(IMetaCollection aCollection)
          Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
 void setString(java.lang.String aString)
          Sets the String of data this StringTransducerAdapter instance uses for its get method invocation.
 
Methods inherited from class net.sourceforge.esw.collection.ATransducerAdapter
getContextFactory, getIOTranducer, setContextFactory, setIOTransducer
 
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

myString

protected java.lang.String myString
The String of data that is get into the contained IIOTransducer instance.

sWriter

protected java.io.StringWriter sWriter
The StringWriter used to capture data from a put method invocation.
Constructor Detail

StringTransducerAdapter

public StringTransducerAdapter()
Creates a new StringTransducerAdapter instance.

StringTransducerAdapter

public StringTransducerAdapter(java.lang.String aString)
Creates a new StringTransducerAdapter instance using the specified String as the data for the get method invocation.
Parameters:
aString - the String for the get method invocation.

StringTransducerAdapter

public StringTransducerAdapter(IIOTransducer aIIOTransducer)
Creates a new StringTransducerAdapter instance, delegating all get and put method invocations to the specified IIOTransducer instance.
Parameters:
aIIOTransducer - the IIOTransducer instance to which to delegate.

StringTransducerAdapter

public StringTransducerAdapter(java.lang.String aString,
                               IIOTransducer aIIOTransducer)
Creates a new StringTransducerAdapter instance with the specified String, delegating all get and put method invocations to the specified IIOTransducer instance.
Parameters:
aString - the String for the get method invocation.
aIIOTransducer - the IIOTransducer instance to which to delegate.
Method Detail

setString

public void setString(java.lang.String aString)
Sets the String of data this StringTransducerAdapter instance uses for its get method invocation.
Parameters:
aString - the String of data for the get method invocation.
See Also:
getString()

getString

public java.lang.String getString()
Returns the String of data this StringTransducerAdapter instance received from its put method invocation.
See Also:
setString( String )

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 creates a Reader instance on the previously specified String and sets the Reader instance on the previously specified IIOTransducer instance, then calls get on the IIOTransducer instance.

Specified by:
get in interface ITransducer
Overrides:
get in class ATransducerAdapter
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.

This implementation creates a StringWriter instance and sets the Writer instance on the previously specified IIOTransducer instance, then calls get on the IIOTransducer instance. After the put returns, call getString to retrieve the String data.

Specified by:
put in interface ITransducer
Overrides:
put in class ATransducerAdapter
Parameters:
aCollection - the IMetaCollection instance from which to take data.
Throws:
TransducerException - if an error occurs during transduction.
See Also:
get( IMetaCollection )


Copyright 2002 Free Software Foundation. All Rights Reserved.