public abstract class ResourceConverter extends Object
The supportsType method defines what types a ResourceConverter supports. By default it returns true for classes that are equal to the constructor's type argument. The parseType methods converts a string the ResourceConverter's supported type, and the toString does the inverse, it converts a supported type to a String. Concrete ResourceConverter subclasses must override parseType() and, in most cases, the toString method as well.
This class maintains a registry of ResourceConverters. The forType method returns the first ResourceConverter that supports a particular type, new ResourceConverters can be added with register(). A small set of generic ResourceConverters are registered by default. They support the following types:
The Boolean ResourceConverter returns true for "true", "on", "yes", false otherwise. The other primitive type ResourceConverters rely on the corresponding static parseType method, e.g. Integer.parseInt(). The MessageFormat ResourceConverter just creates MessageFormat object with the string as its constructor argument. The URL/URI converters just apply the corresponding constructor to the resource string.
ResourceMap
Modifier and Type | Class and Description |
---|---|
static class |
ResourceConverter.ResourceConverterException |
Modifier | Constructor and Description |
---|---|
protected |
ResourceConverter(Class type) |
Modifier and Type | Method and Description |
---|---|
static ResourceConverter |
forType(Class type)
Returns
ResourceConverter for the specified type |
abstract Object |
parseString(String s,
ResourceMap r)
Convert string to object
|
static void |
register(ResourceConverter resourceConverter)
Registers a
ResourceConverter |
boolean |
supportsType(Class testType)
Checks whether
testType can be converted with this converter. |
String |
toString(Object obj)
Null safe toString operation.
|
protected final Class type
protected ResourceConverter(Class type)
public abstract Object parseString(String s, ResourceMap r) throws ResourceConverter.ResourceConverterException
s
- the string to be parsedr
- the ResourceMap
ResourceConverter.ResourceConverterException
public String toString(Object obj)
obj
- the object to be converted to Stringpublic boolean supportsType(Class testType)
testType
can be converted with this converter.testType
- true
if testType
can be converted with this converter.public static void register(ResourceConverter resourceConverter)
ResourceConverter
resourceConverter
- the resource converter to be registeredpublic static ResourceConverter forType(Class type)
ResourceConverter
for the specified typetype
- the type converter must be found fornull
if no converter is found for the type
Copyright © 2009–2016. All rights reserved.