org.directwebremoting.impl
Class DefaultConverterManager

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

public class DefaultConverterManager
extends java.lang.Object
implements ConverterManager

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

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

Constructor Summary
DefaultConverterManager()
           
 
Method Summary
 void addConverter(java.lang.Class<?> clazz, Converter converter)
          Add a new converter based on a loaded class.
 void addConverter(java.lang.String match, Converter converter)
          Add a new converter based on a match string
 void addConverter(java.lang.String match, java.lang.String type, java.util.Map<java.lang.String,java.lang.String> params)
          Add a new converter based on a match string
 void addConverterType(java.lang.String id, java.lang.String className)
          Add a new converter type
 Property checkOverride(Property property)
          All Propertys can create children to represent sub-types, but the ConverterManager might want to override the options that they provide using types configured by a signatures element.
<T> T
convertInbound(java.lang.Class<T> paramType, InboundVariable data, Property 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.
 java.lang.Class<?> getClientDeclaredType(InboundVariable data)
          Sometimes data from clients contains type information which should take higher priority than the type guessing that we do as part of the method matching.
 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.
 boolean isConvertable(java.lang.Class<?> clazz)
          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 setOverrideProperty(Property original, Property replacement)
          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
equals, 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<java.lang.String,java.lang.String> params)
                  throws java.lang.IllegalArgumentException,
                         java.lang.InstantiationException,
                         java.lang.IllegalAccessException
Description copied from interface: ConverterManager
Add a new converter based on a match string

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 based on a match string

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

addConverter

public void addConverter(java.lang.Class<?> clazz,
                         Converter converter)
Description copied from interface: ConverterManager
Add a new converter based on a loaded class. DWR will not make any decisions based on the class's name, which allows for multiple registrations for the same class name (f ex needed in OSGI).

Specified by:
addConverter in interface ConverterManager
Parameters:
clazz - The class to match
converter - The converter to add

getConverterMatchStrings

public java.util.Collection<java.lang.String> 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<?> clazz)
Description copied from interface: ConverterManager
Check if we can coerce the given type

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

getClientDeclaredType

public java.lang.Class<?> getClientDeclaredType(InboundVariable data)
Description copied from interface: ConverterManager
Sometimes data from clients contains type information which should take higher priority than the type guessing that we do as part of the method matching. This method extracts the client passed type information.

Specified by:
getClientDeclaredType in interface ConverterManager
Parameters:
data - The string version of the object from the client
Returns:
Any type information specified by the client

convertInbound

public <T> T convertInbound(java.lang.Class<T> paramType,
                            InboundVariable data,
                            Property thc)
                 throws ConversionException
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
data - The string version of the object
Returns:
The convertible object
Throws:
ConversionException - If the conversion failed for some reason

convertInbound

public <T> T convertInbound(java.lang.Class<T> paramType,
                            RawData rawData)
                 throws ConversionException
Description copied from interface: ConverterManager
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.

Specified by:
convertInbound in interface ConverterManager
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

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

Specified by:
convertOutbound in interface ConverterManager
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

setOverrideProperty

public void setOverrideProperty(Property original,
                                Property replacement)
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:
setOverrideProperty in interface ConverterManager
Parameters:
original - The original property that might need replacing
replacement - A replacement property that returns the correct type

checkOverride

public Property checkOverride(Property property)
Description copied from interface: ConverterManager
All Propertys can create children to represent sub-types, but the ConverterManager might want to override the options that they provide using types configured by a signatures element.

Specified by:
checkOverride in interface ConverterManager
Parameters:
property - The property to check for overriding
Returns:
The original property unless an override was provided

setConverters

public void setConverters(java.util.Map<java.lang.String,Converter> 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

Copyright 2008