net.sf.fikin.pojostate.select
Class NEFormatterSelector

java.lang.Object
  extended by net.sf.fikin.pojostate.select.AbstractSelector
      extended by net.sf.fikin.pojostate.select.BeanMethodsSelector
          extended by net.sf.fikin.pojostate.select.NEFormatterSelector
All Implemented Interfaces:
Selector

public class NEFormatterSelector
extends BeanMethodsSelector

Name Enahanced Formatter Selector

Based on BeanMethodsSelector with extended formatting support based on Method name's suffixes.

It scans Method.getName() and based on predefined set of "suffixes" it will decide what is the appropriate formatting object.

Suffixes and formatting rules are to be defined as Properties in the format: "suffix=class;format mask"

This is convenient when all methods are uniformly named according some rule which does allow one to determine what is the meaning of their returned values.

For example, the following properties file:

 Date=java.text.SimpleDateFormat;dd MMM yyyy HH:mm
 Ms=java.text.DurationFormat
 Ch=java.text.ChoiceFormat;-1#negative|0#positive
 
will be interpreted as following: created on Mar 1, 2007

Since:
Version:
$Revision: 1.3 $
Author:
fiykov

Nested Class Summary
 class NEFormatterSelector.NEFMethodMeta
          Overwrites default DefaultMethodMeta.getFormat() with custom based formatters based on Method-name suffixes table.
 
Constructor Summary
NEFormatterSelector()
           
 
Method Summary
 void loadSuffixes(java.io.InputStream suffixes)
          load the given input stream into the suffixes table old suffixes are replaced
protected  MethodMeta newMethodMeta(java.lang.Class clazz, java.lang.reflect.Method method, java.util.Locale locale, java.lang.ClassLoader loader)
          instantiate new NEFormatterSelector.NEFMethodMeta object
protected  java.text.Format resolveFormat(java.lang.reflect.Method method, java.util.Locale locale, java.lang.ClassLoader loader)
          resolve the formatter based on "suffixes" defined in properties file.
 void setSuffixes(java.util.Properties suffixes)
          assign list of suffixes and formatting rules
 
Methods inherited from class net.sf.fikin.pojostate.select.BeanMethodsSelector
getFilteroutObject, isApplicable, setFilteroutObject
 
Methods inherited from class net.sf.fikin.pojostate.select.AbstractSelector
getMethodMeta
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NEFormatterSelector

public NEFormatterSelector()
Method Detail

setSuffixes

public void setSuffixes(java.util.Properties suffixes)
assign list of suffixes and formatting rules

Parameters:
suffixes -

loadSuffixes

public void loadSuffixes(java.io.InputStream suffixes)
                  throws java.io.IOException
load the given input stream into the suffixes table

old suffixes are replaced

Parameters:
suffixes -
Throws:
java.io.IOException

newMethodMeta

protected MethodMeta newMethodMeta(java.lang.Class clazz,
                                   java.lang.reflect.Method method,
                                   java.util.Locale locale,
                                   java.lang.ClassLoader loader)
                            throws DecorationException
instantiate new NEFormatterSelector.NEFMethodMeta object

Overrides:
newMethodMeta in class BeanMethodsSelector
Parameters:
clazz - is POJO's class
method - to be included
locale - to be used when creating the metadata
loader - is the classloader to be used to load any resource file (if required)
Returns:
valid NEFormatterSelector.NEFMethodMeta object
Throws:
DecorationException - in case of internal error

resolveFormat

protected java.text.Format resolveFormat(java.lang.reflect.Method method,
                                         java.util.Locale locale,
                                         java.lang.ClassLoader loader)
resolve the formatter based on "suffixes" defined in properties file.

if no suitable formatter is found it will return null.

Parameters:
method - is method being created meta for
locale - to be used when creating the metadata
loader - is the classloader to be used to load any resource file (if required)
Returns:
new Format instance or null


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.