org.directwebremoting.dwrp
Class DefaultConverterManager

java.lang.Object
  extended by org.directwebremoting.dwrp.DefaultConverterManager
All Implemented Interfaces:
ConverterManager

public class DefaultConverterManager
extends java.lang.Object
implements ConverterManager

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

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

Constructor Summary
DefaultConverterManager()
           
 
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 params)
          Add a new converter
 void addConverterType(java.lang.String id, java.lang.String className)
          Add a new converter type
 java.lang.Object convertInbound(java.lang.Class paramType, InboundVariable iv, InboundContext inctx, TypeHintContext incc)
          Convert an object from being a string into an object of some type.
 OutboundVariable convertOutbound(java.lang.Object object, OutboundContext outctx)
          Convert an object into a Javavscript 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 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.
protected  Converter getNamedConverter(java.lang.Class paramType, java.lang.String type)
          When we are using typed Javascript names we sometimes want to get a specially named converter
 boolean isConvertable(java.lang.Class paramType)
          Check if we can coerce the given type
 void setConverters(java.util.Map 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultConverterManager

public DefaultConverterManager()
Method Detail

addConverterType

public void addConverterType(java.lang.String id,
                             java.lang.String className)
Description copied from interface: ConverterManager
Add a new converter type

Specified by:
addConverterType in interface ConverterManager
Parameters:
id - The name of the converter type
className - The class to do the conversion

addConverter

public void addConverter(java.lang.String match,
                         java.lang.String type,
                         java.util.Map params)
                  throws java.lang.IllegalArgumentException,
                         java.lang.InstantiationException,
                         java.lang.IllegalAccessException
Description copied from interface: ConverterManager
Add a new converter

Specified by:
addConverter in interface ConverterManager
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.IllegalArgumentException - If we have a duplicate name
java.lang.InstantiationException - If reflection based creation fails
java.lang.IllegalAccessException - If reflection based creation fails

addConverter

public void addConverter(java.lang.String match,
                         Converter converter)
                  throws java.lang.IllegalArgumentException
Description copied from interface: ConverterManager
Add a new converter

Specified by:
addConverter in interface ConverterManager
Parameters:
match - The class name(s) to match
converter - The converter to add
Throws:
java.lang.IllegalArgumentException - If we have a duplicate name

getConverterMatchStrings

public java.util.Collection getConverterMatchStrings()
Description copied from interface: ConverterManager
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.

Specified by:
getConverterMatchStrings in interface ConverterManager
Returns:
A Collection of all the converter match strings
See Also:
ConverterManager.getConverterByMatchString(String)

getConverterByMatchString

public Converter getConverterByMatchString(java.lang.String match)
Description copied from interface: ConverterManager
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.

Specified by:
getConverterByMatchString in interface ConverterManager
Parameters:
match - The match string to lookup
Returns:
The matching converter
See Also:
ConverterManager.getConverterMatchStrings()

isConvertable

public boolean isConvertable(java.lang.Class paramType)
Description copied from interface: ConverterManager
Check if we can coerce the given type

Specified by:
isConvertable in interface ConverterManager
Parameters:
paramType - The type to check
Returns:
true iff paramType is coercable

convertInbound

public java.lang.Object convertInbound(java.lang.Class paramType,
                                       InboundVariable iv,
                                       InboundContext inctx,
                                       TypeHintContext incc)
                                throws MarshallException
Description copied from interface: ConverterManager
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

Specified by:
convertInbound in interface ConverterManager
Parameters:
paramType - The type that you want the object to be
iv - The string version of the object
inctx - The map of data that we are working on
incc - The context of this type conversion
Returns:
The coerced object or null if the object could not be coerced
Throws:
MarshallException - If the conversion failed for some reason

convertOutbound

public OutboundVariable convertOutbound(java.lang.Object object,
                                        OutboundContext outctx)
                                 throws MarshallException
Description copied from interface: ConverterManager
Convert an object into a Javavscript representation of the same. This method is for use by converters wishing to recurse into some object.

Specified by:
convertOutbound in interface ConverterManager
Parameters:
object - The object to convert
outctx - The list of converted objects so far
Returns:
A Javascript string version of the object
Throws:
MarshallException - If the conversion failed for some reason

setExtraTypeInfo

public void setExtraTypeInfo(TypeHintContext thc,
                             java.lang.Class type)
Description copied from interface: ConverterManager
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.

Specified by:
setExtraTypeInfo in interface ConverterManager
Parameters:
thc - The context to find any extra type information from
type - The type of the specified parameter.

getExtraTypeInfo

public java.lang.Class getExtraTypeInfo(TypeHintContext thc)
Description copied from interface: ConverterManager
The extra type information that we have learnt about a method parameter. This method will return null if there is nothing extra to know

Specified by:
getExtraTypeInfo in interface ConverterManager
Parameters:
thc - The context to find any extra type information from
Returns:
A type to use to fill out the generic type

setConverters

public void setConverters(java.util.Map converters)
Description copied from interface: ConverterManager
Sets the converters for this converter manager.

Specified by:
setConverters in interface ConverterManager
Parameters:
converters - the map of match pattern and their converter instances

getNamedConverter

protected Converter getNamedConverter(java.lang.Class paramType,
                                      java.lang.String type)
                               throws MarshallException
When we are using typed Javascript names we sometimes want to get a specially named converter

Parameters:
paramType - The class that we are converting to
type - The type name as passed in from the client
Returns:
The Converter that matches this request (if any)
Throws:
MarshallException