org.directwebremoting.extend
Interface ConverterManager


public interface ConverterManager

A class to manage the converter types and the instantiated class name matches.

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Method Summary
 void addConverter(java.lang.String match, Converter converter)
          Add a new converter
 void addConverter(java.lang.String match, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> params)
          Add a new converter
 void addConverterType(java.lang.String id, java.lang.String className)
          Add a new converter type
<T> T
convertInbound(java.lang.Class<T> paramType, InboundVariable data, TypeHintContext thc)
          Convert an object from being a string into an object of some type.
<T> T
convertInbound(java.lang.Class<T> paramType, RawData rawData)
          RawData is something of a special case for conversion - it's designed to be converted outside of the normal automatic conversion process when the type can't be known until later.
 OutboundVariable convertOutbound(java.lang.Object data, OutboundContext converted)
          Convert an object into a Javascript representation of the same.
 Converter getConverterByMatchString(java.lang.String match)
          In order to be able to create stub remote objects we need to know what they are so you can lookup match strings and retrieve the converter.
 java.util.Collection<java.lang.String> getConverterMatchStrings()
          In order to be able to create stub remote objects we need to know what they are so you can get a collection of all match strings.
 java.lang.Class<?> getExtraTypeInfo(TypeHintContext thc)
          The extra type information that we have learnt about a method parameter.
 boolean isConvertable(java.lang.Class<?> paramType)
          Check if we can coerce the given type
 void setConverters(java.util.Map<java.lang.String,Converter> converters)
          Sets the converters for this converter manager.
 void setExtraTypeInfo(TypeHintContext thc, java.lang.Class<?> type)
          We don't know enough from a method signature like setUsers(Set s) to be able to cast the inbound data to a set of Users.
 

Method Detail

addConverterType

void addConverterType(java.lang.String id,
                      java.lang.String className)
Add a new converter type

Parameters:
id - The name of the converter type
className - The class to do the conversion

addConverter

void addConverter(java.lang.String match,
                  java.lang.String type,
                  java.util.Map<java.lang.String,java.lang.String> params)
                  throws java.lang.IllegalArgumentException,
                         java.lang.InstantiationException,
                         java.lang.IllegalAccessException
Add a new converter

Parameters:
match - The class name(s) to match
type - The name of the converter type
params - The extra parameters to allow the creator to configure itself
Throws:
java.lang.InstantiationException - If reflection based creation fails
java.lang.IllegalAccessException - If reflection based creation fails
java.lang.IllegalArgumentException - If we have a duplicate name

addConverter

void addConverter(java.lang.String match,
                  Converter converter)
                  throws java.lang.IllegalArgumentException
Add a new converter

Parameters:
match - The class name(s) to match
converter - The converter to add
Throws:
java.lang.IllegalArgumentException - If we have a duplicate name

getConverterMatchStrings

java.util.Collection<java.lang.String> getConverterMatchStrings()
In order to be able to create stub remote objects we need to know what they are so you can get a collection of all match strings.

Returns:
A Collection of all the converter match strings
See Also:
getConverterByMatchString(String)

getConverterByMatchString

Converter getConverterByMatchString(java.lang.String match)
In order to be able to create stub remote objects we need to know what they are so you can lookup match strings and retrieve the converter.

Parameters:
match - The match string to lookup
Returns:
The matching converter
See Also:
getConverterMatchStrings()

isConvertable

boolean isConvertable(java.lang.Class<?> paramType)
Check if we can coerce the given type

Parameters:
paramType - The type to check
Returns:
true iff paramType is convertible

convertInbound

<T> T convertInbound(java.lang.Class<T> paramType,
                     InboundVariable data,
                     TypeHintContext thc)
                 throws ConversionException
Convert an object from being a string into an object of some type. Designed for use with converters that have a working map passed to them

Parameters:
paramType - The type that you want the object to be
data - The string version of the object
Returns:
The convertible object
Throws:
ConversionException - If the conversion failed for some reason

convertInbound

<T> T convertInbound(java.lang.Class<T> paramType,
                     RawData rawData)
                 throws ConversionException
RawData is something of a special case for conversion - it's designed to be converted outside of the normal automatic conversion process when the type can't be known until later. This method helps us with those cases without exposing too much of what RawData holds.

Type Parameters:
T -
Parameters:
paramType - The type we wish to convert to
rawData - The RawData object holding data to be converted
Returns:
The convertible object
Throws:
ConversionException - If the conversion failed for some reason

convertOutbound

OutboundVariable convertOutbound(java.lang.Object data,
                                 OutboundContext converted)
                                 throws ConversionException
Convert an object into a Javascript representation of the same. This method is for use by converters wishing to recurse into some object.

Parameters:
data - The object to convert
converted - The list of converted objects so far
Returns:
A Javascript string version of the object
Throws:
ConversionException - If the conversion failed for some reason

setExtraTypeInfo

void setExtraTypeInfo(TypeHintContext thc,
                      java.lang.Class<?> type)
We don't know enough from a method signature like setUsers(Set s) to be able to cast the inbound data to a set of Users. This method enables us to specify this extra information.

Parameters:
thc - The context to find any extra type information from
type - The type of the specified parameter.

getExtraTypeInfo

java.lang.Class<?> getExtraTypeInfo(TypeHintContext thc)
The extra type information that we have learnt about a method parameter. This method will return null if there is nothing extra to know

Parameters:
thc - The context to find any extra type information from
Returns:
A type to use to fill out the generic type

setConverters

void setConverters(java.util.Map<java.lang.String,Converter> converters)
Sets the converters for this converter manager.

Parameters:
converters - the map of match pattern and their converter instances

Copyright ยจ 2008