com.primix.tapestry.util.io
Class DataSqueezer

java.lang.Object
  |
  +--com.primix.tapestry.util.io.DataSqueezer

public class DataSqueezer
extends java.lang.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,v 1.4 2001/05/02 14:15:17 hship Exp $
Author:
Howard Ship

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

Constructor Detail

DataSqueezer

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

DataSqueezer

public DataSqueezer(ISqueezeAdaptor[] adaptors)
Creates a new data squeezer, which may 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(java.lang.String prefix,
                     java.lang.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 java.lang.String squeeze(java.lang.Object data)
                         throws java.io.IOException
Squeezes the data object into a String by locating an appropriate adaptor that can perform the conversion. data may be null.

squeeze

public java.lang.String[] squeeze(java.lang.Object[] data)
                           throws java.io.IOException
A convience; invokes squeeze(Object) for each element in the data array.

unsqueeze

public java.lang.Object unsqueeze(java.lang.String string)
                           throws java.io.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.

unsqueeze

public java.lang.Object[] unsqueeze(java.lang.String[] strings)
                             throws java.io.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 java.lang.String toString()
Overrides:
toString in class java.lang.Object