uk.ltd.getahead.dwr.convert
Class BeanConverter

java.lang.Object
  extended byuk.ltd.getahead.dwr.compat.BaseV10Converter
      extended byuk.ltd.getahead.dwr.convert.BeanConverter
All Implemented Interfaces:
Converter
Direct Known Subclasses:
HibernateBeanConverter

public class BeanConverter
extends BaseV10Converter
implements Converter

Convert a Javascript associative array into a JavaBean

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

Constructor Summary
BeanConverter()
           
 
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.
 java.lang.String convertOutbound(java.lang.Object data, java.lang.String varname, OutboundContext outctx)
          Return a javascript string that defines the variable named varName to have the contents of the converted object data.
 ConverterManager getConverterManager()
          Accessor for the current ConverterManager
 java.lang.Class getInstanceType()
           
 boolean isAvailable(java.lang.Object data, java.lang.String property)
          Some child converters (like Hibernate at least) need to check that a property should be marshalled.
 void setConverterManager(ConverterManager newConfig)
          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)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanConverter

public BeanConverter()
Method Detail

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()
Returns:
Returns the instanceType.

setInstanceType

public void setInstanceType(java.lang.Class instanceType)
Parameters:
instanceType - The instanceType to set.

setConverterManager

public void setConverterManager(ConverterManager newConfig)
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
Parameters:
newConfig - The confiuration object

getConverterManager

public ConverterManager getConverterManager()
Accessor for the current ConverterManager

Returns:
the current ConverterManager

convertInbound

public java.lang.Object convertInbound(java.lang.Class paramType,
                                       InboundVariable iv,
                                       InboundContext inctx)
                                throws ConversionException
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:
ConversionException - If the conversion failed for some reason

convertOutbound

public java.lang.String convertOutbound(java.lang.Object data,
                                        java.lang.String varname,
                                        OutboundContext outctx)
                                 throws ConversionException
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() any 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
varname - The variable to define
outctx - Objects already converted and the results
Returns:
The string that defines the given variable
Throws:
ConversionException - If the conversion failed for some reason

isAvailable

public boolean isAvailable(java.lang.Object data,
                           java.lang.String property)
Some child converters (like Hibernate at least) need to check that a property should be marshalled. This allows them to veto a marshal

Parameters:
data - The object to check on
property - The property of the data object
Returns:
true if we should continue and marshall it.

Copyright ? 2005