org.apache.tapestry.util.io
Class DataSqueezer

java.lang.Object
  extended by org.apache.tapestry.util.io.DataSqueezer

public class DataSqueezer
extends Object

A class used to convert arbitrary objects to Strings and back. This has particular uses involving HTTP URLs and Cookies.

Version:
$Id: DataSqueezer.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Howard Lewis Ship

Constructor Summary
DataSqueezer(IResourceResolver resolver)
          Creates a new squeezer with the default set of adaptors.
DataSqueezer(IResourceResolver resolver, ISqueezeAdaptor[] adaptors)
          Creates a new data squeezer, which will have the default set of adaptors, and may add additional adaptors.
 
Method Summary
 IResourceResolver getResolver()
          Returns the resource resolver used with this squeezer.
 boolean isPrefixRegistered(char prefix)
          Checks to see if a given prefix character has a registered adaptor.
 void register(String prefix, Class dataClass, ISqueezeAdaptor adaptor)
          Registers the adaptor with one or more single-character prefixes.
 String squeeze(Object data)
          Squeezes the data object into a String by locating an appropriate adaptor that can perform the conversion.
 String[] squeeze(Object[] data)
          A convience; invokes squeeze(Object) for each element in the data array.
 String toString()
           
 Object unsqueeze(String string)
          Unsqueezes the string.
 Object[] unsqueeze(String[] strings)
          Convienience method for unsqueezing many strings (back into objects).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataSqueezer

public DataSqueezer(IResourceResolver resolver)
Creates a new squeezer with the default set of adaptors.


DataSqueezer

public DataSqueezer(IResourceResolver resolver,
                    ISqueezeAdaptor[] adaptors)
Creates a new data squeezer, which will have the default set of adaptors, and may add additional adaptors.

Parameters:
adaptors - an optional list of adaptors that will be registered to the data squeezer (it may be null or empty)
Method Detail

register

public void register(String prefix,
                     Class dataClass,
                     ISqueezeAdaptor adaptor)
Registers the adaptor with one or more single-character prefixes.

Parameters:
prefix - one or more characters, each of which will be a prefix for the adaptor.
dataClass - the class (or interface) which can be encoded by the adaptor.
adaptor - the adaptor which to be registered.

squeeze

public String squeeze(Object data)
               throws IOException
Squeezes the data object into a String by locating an appropriate adaptor that can perform the conversion. data may be null.

Throws:
IOException

squeeze

public String[] squeeze(Object[] data)
                 throws IOException
A convience; invokes squeeze(Object) for each element in the data array. If data is null, returns null.

Throws:
IOException

unsqueeze

public Object unsqueeze(String string)
                 throws IOException
Unsqueezes the string. Note that in a special case, where the first character of the string is not a recognized prefix, it is assumed that the string is simply a string, and return with no change.

Throws:
IOException

unsqueeze

public Object[] unsqueeze(String[] strings)
                   throws IOException
Convienience method for unsqueezing many strings (back into objects).

If strings is null, returns null.

Throws:
IOException

isPrefixRegistered

public boolean isPrefixRegistered(char prefix)
Checks to see if a given prefix character has a registered adaptor. This is used by the String adaptor to determine whether it needs to put a prefix on its String.


toString

public String toString()
Overrides:
toString in class Object

getResolver

public IResourceResolver getResolver()
Returns the resource resolver used with this squeezer.

Since:
2.2