org.hackystat.sensor.xmldata.util
Class StringListCodec

java.lang.Object
  extended by org.hackystat.sensor.xmldata.util.StringListCodec

public class StringListCodec
extends java.lang.Object

Provides an encoder for transforming a List instance containing strings into a single string (suitable for transmission via SOAP) and a decoder for reconstructing the List on the other side. Individual strings must be less than MAX_STRING_LENGTH, and the number of strings in the list must be less than MAX_NUM_STRINGS. Throws an exception if these maxima are exceeded, or if the List to be decoded contains a non-String element, or if the String to be decoded is not correctly formatted for decoding, or if the decoded string is not completely consumed by the decoding process.

Version:
$Id: StringListCodec.java,v 1.1.1.1 2005/10/20 23:56:44 johnson Exp $
Author:
Philip M. Johnson

Field Summary
static int MAX_NUM_STRINGS
          The maximum number of strings that can be encoded.
static int MAX_STRING_LENGTH
          The maximum length of any individual string to be encoded.
 
Constructor Summary
StringListCodec()
           
 
Method Summary
static java.util.List<java.lang.String> decode(java.lang.String encodedString)
          Decodes the passed string, returning a List of strings.
static java.lang.String encode(java.util.List<java.lang.String> stringList)
          Encodes the passed list of strings into a single string and returns it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_STRING_LENGTH

public static final int MAX_STRING_LENGTH
The maximum length of any individual string to be encoded.

See Also:
Constant Field Values

MAX_NUM_STRINGS

public static final int MAX_NUM_STRINGS
The maximum number of strings that can be encoded.

See Also:
Constant Field Values
Constructor Detail

StringListCodec

public StringListCodec()
Method Detail

encode

public static java.lang.String encode(java.util.List<java.lang.String> stringList)
                               throws StringListCodecException
Encodes the passed list of strings into a single string and returns it.

Parameters:
stringList - a List value
Returns:
a String value
Throws:
StringListCodecException - If the list contains a non-String, or if the number of strings in the list exceeds MAX_NUM_STRINGS, or if the length of any individual string exceeds MAX_STRING_LENGTH.

decode

public static java.util.List<java.lang.String> decode(java.lang.String encodedString)
                                               throws StringListCodecException
Decodes the passed string, returning a List of strings.

Parameters:
encodedString - The encoded list of strings.
Returns:
A new list of strings.
Throws:
StringListCodecException - If the passed encodedString is not encoded properly.