org.apache.tapestry.util.io
Class DataSqueezerImpl

java.lang.Object
  extended by org.apache.tapestry.util.io.DataSqueezerImpl
All Implemented Interfaces:
DataSqueezer

public class DataSqueezerImpl
extends Object
implements DataSqueezer

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

Author:
Howard Lewis Ship

Field Summary
protected  SqueezeAdaptor[] _adaptorByPrefix
          An array of adaptors; this is used as a cheap lookup-table when unsqueezing.
protected  org.apache.hivemind.lib.util.StrategyRegistry _adaptors
          AdaptorRegistry cache of adaptors.
protected static int ARRAY_SIZE
           
protected static int FIRST_ADAPTOR_OFFSET
           
protected static String NULL_PREFIX
           
 
Constructor Summary
DataSqueezerImpl()
           
 
Method Summary
 void register(SqueezeAdaptor adaptor)
          Registers the adaptor with one or more single-character prefixes.
 void setSqueezeAdaptors(List adaptors)
           
 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
 

Field Detail

NULL_PREFIX

protected static final String NULL_PREFIX
See Also:
Constant Field Values

ARRAY_SIZE

protected static final int ARRAY_SIZE
See Also:
Constant Field Values

FIRST_ADAPTOR_OFFSET

protected static final int FIRST_ADAPTOR_OFFSET
See Also:
Constant Field Values

_adaptorByPrefix

protected SqueezeAdaptor[] _adaptorByPrefix
An array of adaptors; this is used as a cheap lookup-table when unsqueezing. Each adaptor is identified by a single ASCII character, in the range of 33 ('!') to 122 (the letter 'z'). The offset into this table is the character minus 33.


_adaptors

protected org.apache.hivemind.lib.util.StrategyRegistry _adaptors
AdaptorRegistry cache of adaptors.

Constructor Detail

DataSqueezerImpl

public DataSqueezerImpl()
Method Detail

setSqueezeAdaptors

public void setSqueezeAdaptors(List adaptors)

register

public void register(SqueezeAdaptor adaptor)
Registers the adaptor with one or more single-character prefixes.

Note: This method should be used for testing purposes only! Squeeze adaptors are normally injected by HiveMind.

Parameters:
adaptor - the adaptor which to be registered.

squeeze

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

Specified by:
squeeze in interface DataSqueezer
Parameters:
data - The object to squeeze.
Returns:
The string equivalent of the data in "squeezed" form.

squeeze

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

Specified by:
squeeze in interface DataSqueezer
Parameters:
data - Array of objects to squeeze.
Returns:
Squeezed string array.

unsqueeze

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

Specified by:
unsqueeze in interface DataSqueezer
Parameters:
string - The data to unsqueeze.
Returns:
The object representation of the data - theoretically matching the object passed in via DataSqueezer.squeeze(Object).

unsqueeze

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

If strings is null, returns null.

Specified by:
unsqueeze in interface DataSqueezer
Parameters:
strings - The string data array to unsqueeze.
Returns:
The data in its object form, as was passed in to DataSqueezer.squeeze(Object[]).

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.