net.sf.fikin.pojostate.select
Class ResourceBundleSelector

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

public class ResourceBundleSelector
extends AbstractSelector

Resource bundle based methods selector.

It recognizes only those methods which are found in the resource bundle.

If any of the following definitions is present the method is recognized as observable:

If ".name" is not present it will print the method's name.

If ".desc" is not present it will print null for method description.

If ".format" is not present it will use DefaultFormat.

Example:

 ...
 <package.class.method>.name=<UI name>
 <package.class.method>.desc=<UI description>
 <package.class.method>.format=<format class>[:<format pattern>]
 ...
 
created on Mar 1, 2007

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

Constructor Summary
ResourceBundleSelector()
           
 
Method Summary
protected  java.lang.String createMethodKey(java.lang.Class clazz, java.lang.reflect.Method method)
          construct method's base name as it will be used in the resource bundle definitions.
 java.lang.String getBaseName()
           
protected  java.util.WeakHashMap getCachedRB()
           
 MethodsIterator getMethodsIterator()
           
protected  java.lang.String getRBKey(java.util.Locale locale)
          create a string key, uniquely identifying the resource bundle of this locale handle empty locale settings too
protected  boolean isApplicable(java.lang.Class clazz, java.lang.reflect.Method method, java.util.Locale locale, java.lang.ClassLoader loader)
          looks for the bundle with given local and base name then looks for if the method having ".name", ".desc" and ".format" resource definitions.
protected  java.util.ResourceBundle loadRB(java.util.Locale locale, java.lang.ClassLoader loader)
          attempt to load the resource bundle with given base name and locale
protected  java.util.ResourceBundle lookupCachedRB(java.lang.String rbKey)
          lookup the cache for already loaded resource bundle for that locale
protected  MethodMeta newMethodMeta(java.lang.Class clazz, java.lang.reflect.Method method, java.util.Locale locale, java.lang.ClassLoader loader)
          return existing tempObj as it has been already initialized by isApplicable(Class, Method, Locale, ClassLoader).
protected  void putInRBCache(java.lang.String rbkey, java.util.ResourceBundle bundle)
          put in the resource bundle cache given bundle under given key
protected  ExplicitMethodMeta resolveEntry(java.util.ResourceBundle bundle, java.lang.Class clazz, java.lang.reflect.Method method, java.util.Locale locale, java.lang.ClassLoader loader)
           Use the methods iterator to find a matching resource entry for that given method by doing deep class-hierarchy scanning.
 void setBaseName(java.lang.String baseName)
          set associated resource bundle
 void setMethodsIterator(MethodsIterator iterator)
          set method's definitions iterator
 
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

ResourceBundleSelector

public ResourceBundleSelector()
Method Detail

setBaseName

public void setBaseName(java.lang.String baseName)
set associated resource bundle

Parameters:
baseName - of the resource bundle, different locales will be appended to this name.

getBaseName

public java.lang.String getBaseName()
Returns:
the base name of the resource bundle

setMethodsIterator

public void setMethodsIterator(MethodsIterator iterator)
set method's definitions iterator

Parameters:
iterator -

getMethodsIterator

public MethodsIterator getMethodsIterator()
Returns:
method's definitions iterator

getCachedRB

protected java.util.WeakHashMap getCachedRB()
Returns:
the table with already cached resource bundles

isApplicable

protected boolean isApplicable(java.lang.Class clazz,
                               java.lang.reflect.Method method,
                               java.util.Locale locale,
                               java.lang.ClassLoader loader)
looks for the bundle with given local and base name

then looks for if the method having ".name", ".desc" and ".format" resource definitions.

If such found returns true, otherwise false.

Specified by:
isApplicable in class AbstractSelector
Parameters:
clazz - is POJO's class
method - is some of the clazz methods, currently being tested if it is to be observed
locale - to be used when creating the metadata
loader - is the classloader to be used to load any resource file (if required)
Returns:
true in case it is to be observed, otherwise false

newMethodMeta

protected MethodMeta newMethodMeta(java.lang.Class clazz,
                                   java.lang.reflect.Method method,
                                   java.util.Locale locale,
                                   java.lang.ClassLoader loader)
return existing tempObj as it has been already initialized by isApplicable(Class, Method, Locale, ClassLoader).

Specified by:
newMethodMeta in class AbstractSelector
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:
in initialized MethodMeta object

resolveEntry

protected ExplicitMethodMeta resolveEntry(java.util.ResourceBundle bundle,
                                          java.lang.Class clazz,
                                          java.lang.reflect.Method method,
                                          java.util.Locale locale,
                                          java.lang.ClassLoader loader)
                                   throws java.util.MissingResourceException

Use the methods iterator to find a matching resource entry for that given method by doing deep class-hierarchy scanning.

Parameters:
bundle -
clazz -
method -
loader -
Returns:
resource data or null if not found
Throws:
DecorationException - in case of internal error
java.util.MissingResourceException

createMethodKey

protected java.lang.String createMethodKey(java.lang.Class clazz,
                                           java.lang.reflect.Method method)
construct method's base name as it will be used in the resource bundle definitions.

format is like "fqClassName.methodName"

Parameters:
clazz -
method -
Returns:
string representation for a method key

getRBKey

protected java.lang.String getRBKey(java.util.Locale locale)
create a string key, uniquely identifying the resource bundle of this locale

handle empty locale settings too

Parameters:
locale -
Returns:
string representation of a locales key

lookupCachedRB

protected java.util.ResourceBundle lookupCachedRB(java.lang.String rbKey)
lookup the cache for already loaded resource bundle for that locale

Parameters:
rbKey -
Returns:
cached resource bundle or null if cache does nto have such

loadRB

protected java.util.ResourceBundle loadRB(java.util.Locale locale,
                                          java.lang.ClassLoader loader)
attempt to load the resource bundle with given base name and locale

Parameters:
locale -
loader -
Returns:
loaded resource bundle or null if such not found

putInRBCache

protected void putInRBCache(java.lang.String rbkey,
                            java.util.ResourceBundle bundle)
put in the resource bundle cache given bundle under given key

Parameters:
rbkey -
bundle -


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.