org.directwebremoting.convert
Class BasicObjectConverter

java.lang.Object
  extended by org.directwebremoting.convert.BaseV20Converter
      extended by org.directwebremoting.convert.BasicObjectConverter
All Implemented Interfaces:
Converter, NamedConverter
Direct Known Subclasses:
BeanConverter, ObjectConverter

public abstract class BasicObjectConverter
extends BaseV20Converter
implements NamedConverter

BasicObjectConverter is a parent to BeanConverter and ObjectConverter an provides support for include and exclude lists, and instanceTypes.

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

Field Summary
protected  ConverterManager converterManager
          To forward marshalling requests
protected  java.util.List exclusions
          The list of excluded properties
protected  java.util.List inclusions
          The list of included properties
protected  java.lang.Class instanceType
          A type that allows us to fulfill an interface or subtype requirement
protected  java.lang.String javascript
          The javascript class name for the converted objects
 
Constructor Summary
BasicObjectConverter()
           
 
Method Summary
 java.lang.Object convertInbound(java.lang.Class paramType, InboundVariable iv, InboundContext inctx)
          Attempt to coerce the data from a string to an Object.
 OutboundVariable convertOutbound(java.lang.Object data, OutboundContext outctx)
          Return a javascript string that defines the variable named varName to have the contents of the converted object data.
protected abstract  TypeHintContext createTypeHintContext(InboundContext inctx, Property property)
          convertInbound(Class, InboundVariable, InboundContext) needs to create a TypeHintContext for the Property it is converting so that the type guessing system can do its work.
protected  java.util.Map extractInboundTokens(java.lang.Class paramType, java.lang.String value)
          Loop over all the inputs and extract a Map of key:value pairs
 ConverterManager getConverterManager()
          Accessor for the current ConverterManager
 java.lang.Class getInstanceType()
           
 java.lang.String getJavascript()
          Accessor for the javascript class name for the converted objects.
protected  boolean isAllowedByIncludeExcludeRules(java.lang.String property)
          Check with the access rules to see if we are allowed to convert a property
 void setConverterManager(ConverterManager converterManager)
          If we are a compound converter that farms out part of the conversion to other converters then you farm the conversion out via a configuration.
 void setExclude(java.lang.String excludes)
          Set a list of properties excluded from conversion
 void setImplementation(java.lang.String name)
           
 void setInclude(java.lang.String includes)
          Set a list of properties included from conversion
 void setInstanceType(java.lang.Class instanceType)
           
 void setJavascript(java.lang.String javascript)
          Accessor for the javascript class name for the converted objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.directwebremoting.extend.NamedConverter
getPropertyMapFromClass, getPropertyMapFromObject
 

Field Detail

javascript

protected java.lang.String javascript
The javascript class name for the converted objects


exclusions

protected java.util.List exclusions
The list of excluded properties


inclusions

protected java.util.List inclusions
The list of included properties


instanceType

protected java.lang.Class instanceType
A type that allows us to fulfill an interface or subtype requirement


converterManager

protected ConverterManager converterManager
To forward marshalling requests

Constructor Detail

BasicObjectConverter

public BasicObjectConverter()
Method Detail

convertInbound

public java.lang.Object convertInbound(java.lang.Class paramType,
                                       InboundVariable iv,
                                       InboundContext inctx)
                                throws MarshallException
Description copied from interface: Converter
Attempt to coerce the data from a string to an Object. If anything goes wrong with inbound conversion then we generally throw an exception because we are converting data from the untrusted internet so we take the assumption that anything wrong is someone hacking.

Specified by:
convertInbound in interface Converter
Parameters:
paramType - The type to convert to
iv - The data to convert
inctx - The map of data that we are working on
Returns:
The convered data, or null if the conversion was not possible
Throws:
MarshallException - If the conversion failed for some reason

createTypeHintContext

protected abstract TypeHintContext createTypeHintContext(InboundContext inctx,
                                                         Property property)
convertInbound(Class, InboundVariable, InboundContext) needs to create a TypeHintContext for the Property it is converting so that the type guessing system can do its work.

The method of generating a TypeHintContext is different for the BeanConverter and the ObjectConverter.

Parameters:
inctx - The parent context
property - The property being converted
Returns:
The new TypeHintContext

convertOutbound

public OutboundVariable convertOutbound(java.lang.Object data,
                                        OutboundContext outctx)
                                 throws MarshallException
Description copied from interface: Converter
Return a javascript string that defines the variable named varName to have the contents of the converted object data.

In contrast to convertInbound() failures in converting data on the way out should not stop processing, and we should carry on if we can. Failures are probably down to some misconfiguration so as much information about the error as can be safely generated to console logs is good. In other words if you need to loop in outbound conversion then it might be a good idea to catch issues inside the loop, log, and carry on.

Specified by:
convertOutbound in interface Converter
Parameters:
data - The data to convert
outctx - A collection of objects already converted and the results
Returns:
The OutboundVariable that represents the data to convert
Throws:
MarshallException - If the conversion failed for some reason

setExclude

public void setExclude(java.lang.String excludes)
Set a list of properties excluded from conversion

Parameters:
excludes - The space or comma separated list of properties to exclude

setInclude

public void setInclude(java.lang.String includes)
Set a list of properties included from conversion

Parameters:
includes - The space or comma separated list of properties to exclude

setImplementation

public void setImplementation(java.lang.String name)
                       throws java.lang.ClassNotFoundException
Parameters:
name - The class name to use as an implementation of the converted bean
Throws:
java.lang.ClassNotFoundException - If the given class can not be found

getInstanceType

public java.lang.Class getInstanceType()
Specified by:
getInstanceType in interface NamedConverter
Returns:
Returns the instanceType.

setInstanceType

public void setInstanceType(java.lang.Class instanceType)
Specified by:
setInstanceType in interface NamedConverter
Parameters:
instanceType - The instanceType to set.

setConverterManager

public void setConverterManager(ConverterManager converterManager)
Description copied from interface: Converter
If we are a compound converter that farms out part of the conversion to other converters then you farm the conversion out via a configuration.

Specified by:
setConverterManager in interface Converter
Overrides:
setConverterManager in class BaseV20Converter
Parameters:
converterManager - The confiuration object

getConverterManager

public ConverterManager getConverterManager()
Accessor for the current ConverterManager

Returns:
the current ConverterManager

isAllowedByIncludeExcludeRules

protected boolean isAllowedByIncludeExcludeRules(java.lang.String property)
Check with the access rules to see if we are allowed to convert a property

Parameters:
property - The property to test
Returns:
true if the property may be marshalled

extractInboundTokens

protected java.util.Map extractInboundTokens(java.lang.Class paramType,
                                             java.lang.String value)
                                      throws MarshallException
Loop over all the inputs and extract a Map of key:value pairs

Parameters:
paramType - The type we are converting to
value - The input string
Returns:
A Map of the tokens in the string
Throws:
MarshallException - If the marshalling fails

getJavascript

public java.lang.String getJavascript()
Description copied from interface: NamedConverter
Accessor for the javascript class name for the converted objects.

Specified by:
getJavascript in interface NamedConverter
Returns:
The Javascript name

setJavascript

public void setJavascript(java.lang.String javascript)
Description copied from interface: NamedConverter
Accessor for the javascript class name for the converted objects.

Specified by:
setJavascript in interface NamedConverter
Parameters:
javascript - The Javascript name