org.xwiki.properties.converter
Class AbstractCollectionConverter

java.lang.Object
  extended by org.xwiki.properties.converter.AbstractConverter
      extended by org.xwiki.properties.converter.AbstractCollectionConverter
All Implemented Interfaces:
Converter
Direct Known Subclasses:
ListConverter, SetConverter

public abstract class AbstractCollectionConverter
extends AbstractConverter

Base class for all Collection converters.

Since:
3.0M1
Version:
$Id$

Field Summary
protected static char QUOTECHAR
          Quote char.
protected static String QUOTESTRING
          Quote string.
 
Constructor Summary
AbstractCollectionConverter()
           
 
Method Summary
protected  String convertToString(Object value)
          Convert the input object into a String.
protected
<T> T
convertToType(Type targetType, Object value)
          Convert the input object into an output object of the specified type.
protected  StreamTokenizer createStreamTokenizer(String value)
          Create and initializer a StreamTokenizer to parse the value.
 ConverterManager getConverterManager()
           
 char getDelimiter()
           
protected  Collection newCollection()
           
protected  Collection parseElements(String value, Type genericType)
           Parse an incoming String of the form similar to an array initializer in the Java language into a List individual Strings for each element, according to the following rules.
 void setAllowedChars(char[] allowedChars)
          Set the allowed characters to be used for parsing a delimited String.
 void setDelimiter(char delimiter)
          Set the delimiter to be used for parsing a delimited String.
 
Methods inherited from class org.xwiki.properties.converter.AbstractConverter
convert, convertToType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUOTECHAR

protected static final char QUOTECHAR
Quote char.

See Also:
Constant Field Values

QUOTESTRING

protected static final String QUOTESTRING
Quote string.

See Also:
Constant Field Values
Constructor Detail

AbstractCollectionConverter

public AbstractCollectionConverter()
Method Detail

getConverterManager

public ConverterManager getConverterManager()
Returns:
the converter manager.

setDelimiter

public void setDelimiter(char delimiter)
Set the delimiter to be used for parsing a delimited String.

Parameters:
delimiter - The delimiter [default ',']

getDelimiter

public char getDelimiter()
Returns:
the delimiter

setAllowedChars

public void setAllowedChars(char[] allowedChars)
Set the allowed characters to be used for parsing a delimited String.

Parameters:
allowedChars - Characters which are to be considered as part of the tokens when parsing a delimited String [default is '.' and '-']

convertToType

protected <T> T convertToType(Type targetType,
                              Object value)
Description copied from class: AbstractConverter
Convert the input object into an output object of the specified type.

Typical implementations will provide a minimum of String --> type conversion.

Overrides:
convertToType in class AbstractConverter
Type Parameters:
T - the type in which the provided value has o be converted
Parameters:
targetType - Data type to which this value should be converted.
value - The input value to be converted.
Returns:
The converted value.

parseElements

protected Collection parseElements(String value,
                                   Type genericType)

Parse an incoming String of the form similar to an array initializer in the Java language into a List individual Strings for each element, according to the following rules.

Parameters:
value - String value to be parsed
genericType - the generic type
Returns:
List of parsed elements.
Throws:
ConversionException - if the syntax of value is not syntactically valid
NullPointerException - if value is null

newCollection

protected Collection newCollection()
Returns:
the modifiable Collection to fill

createStreamTokenizer

protected StreamTokenizer createStreamTokenizer(String value)
Create and initializer a StreamTokenizer to parse the value.

Parameters:
value - the string to parse
Returns:
the StreamTokenizer used to parse the string

convertToString

protected String convertToString(Object value)
Convert the input object into a String.

N.B.This implementation simply uses the value's toString() method and should be overriden if a more sophisticated mechanism for conversion to a String is required.

Overrides:
convertToString in class AbstractConverter
Parameters:
value - The input value to be converted.
Returns:
the converted String value.
See Also:
AbstractConverter.convertToString(java.lang.Object)


Copyright © 2004-2011 XWiki. All Rights Reserved.