Version 4.5.0

hirondelle.web4j.model
Class ConvertParamImpl

Object
  extended by hirondelle.web4j.model.ConvertParamImpl
All Implemented Interfaces:
ConvertParam

public class ConvertParamImpl
extends Object
implements ConvertParam

Default implementation of ConvertParam.


Constructor Summary
ConvertParamImpl()
           
 
Method Summary
<T> T
convert(String aFilteredInputValue, Class<T> aSupportedTargetClass, Locale aLocale, TimeZone aTimeZone)
          Apply reasonable parsing policies, suitable for most applications.
 String filter(String aRawInputValue)
          Coerce all parameters with no visible content to null.
static String getIgnorableParamValue()
          Return the IgnorableParamValue configured in web.xml.
static void init(ServletConfig aConfig)
          Called by the framework upon startup.
 boolean isSupported(Class<?> aTargetClass)
          Return true only if aTargetClass is supported by this implementation.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConvertParamImpl

public ConvertParamImpl()
Method Detail

init

public static void init(ServletConfig aConfig)
Called by the framework upon startup.


isSupported

public final boolean isSupported(Class<?> aTargetClass)
Return true only if aTargetClass is supported by this implementation.

The following classes are supported by this implementation as building block classes :

You are not obliged to use this class to model Locale and TimeZone. Many will choose to implement them as just another code table instead. In this case, your model object constructors would usually take an Id parameter for these items, and translate them into a Code. See the example apps for a demonstration of this technique.

The TimeZone class is a problem here, since it's abstract. In fact, this demonstrates a defect in the ConvertParam interface itself - it should take objects themselves, instead of classes. That would allow more flexible checks on type as opposed to concrete class. In this implementation, ZoneInfo is hard-coded as the representative of all TimeZone objects. This is poor style, since ZoneInfo is public, but "unpublished" by Sun - they may change to some other class in the future.

String is supported only when explicitly allowed. The AllowStringAsBuildingBlock setting in web.xml controls whether or not this class allows String as a supported class. By default, its value is FALSE, since SafeText is the recommended replacement for String.

Specified by:
isSupported in interface ConvertParam

filter

public String filter(String aRawInputValue)
Coerce all parameters with no visible content to null.

In addition, any raw input value that matches IgnorableParamValue in web.xml is also coerced to null. See web.xml for more information.

Any non-null result is trimmed. This method can be overridden, if desired.

Specified by:
filter in interface ConvertParam
Parameters:
aRawInputValue - the raw, unchanged parameter value, as submitted in the underlying request.

convert

public final <T> T convert(String aFilteredInputValue,
                           Class<T> aSupportedTargetClass,
                           Locale aLocale,
                           TimeZone aTimeZone)
                throws ModelCtorException
Apply reasonable parsing policies, suitable for most applications.

Roughly, the policies are :

Specified by:
convert in interface ConvertParam
Parameters:
aFilteredInputValue - parameter value as returned by ConvertParam.filter(String)
aSupportedTargetClass - supported target building block class in a Model Object constructor
aLocale - Locale returned by the implementation of LocaleSource
aTimeZone - TimeZone returned by the implementation of TimeZoneSource
Throws:
ModelCtorException

getIgnorableParamValue

public static final String getIgnorableParamValue()
Return the IgnorableParamValue configured in web.xml. See web.xml for more information.


Version 4.5.0

Copyright Hirondelle Systems. Published April 17, 2010 - User Guide - All Docs.