net.sf.fikin.pojostate.decorate
Class AbstractDecorator

java.lang.Object
  extended by net.sf.fikin.pojostate.decorate.AbstractDecorator
All Implemented Interfaces:
Decorator
Direct Known Subclasses:
DynamicDecorator, SnapshotDecorator

public abstract class AbstractDecorator
extends java.lang.Object
implements Decorator

Abstract implementation of object decoration

Provides with basic skeleton for common methods, subclasses are expected to implement the actual decoration logic only.

It maintains a cached StatePrototype list for already parsed classes. POJOs from same class would result in reusing the existing ClassMeta data. It is backed by WeakHashMap.

Users have to set Selector objects to be used.

Users have to implement factory method for instantiation of particular State objects. created on Jul 18, 2005

Since:
Version:
$Revision: 1.2 $
Author:
fiykov

Constructor Summary
AbstractDecorator()
           
 
Method Summary
protected  void cacheState(java.lang.String key, StatePrototype meta)
          store the given StatePrototype in the cache
protected  StatePrototype createState(java.lang.Class clazz, java.util.Locale locale, java.lang.ClassLoader loader)
          Inspect the class structure for suitable methods.
 State decorate(java.lang.Object object)
          decorate the object using English locale and Thread's context class loader
 State decorate(java.lang.Object object, java.util.Locale locale)
          decorate the object using given locale settings and thread's context class loader
 State decorate(java.lang.Object object, java.util.Locale locale, java.lang.ClassLoader loader)
          decorate the object using given locale and class loader
protected  State decorateObject(java.lang.Object object, java.util.Locale locale, java.lang.ClassLoader loader)
          decorate an object It does maintain a cache of StatePrototype objects, which are created per unique combination of Class, Locale and Loader.
protected  State decorateObject(StatePrototype stateMeta, java.lang.Object object)
          clone stateMeta and assign to it the object
protected  StatePrototype getCachedState(java.lang.String cacheKey)
          look in cached StatePrototypes for already created definition with given key
protected  java.lang.String getCacheKey(java.lang.Class clazz, java.util.Locale locale, java.lang.ClassLoader loader)
          create string key uniquely identifying given Class, Locale and ClassLoader
 Selector getSelector()
          get assigned Method's selector
 StateFormat getStateFormat()
          get State's formatting object This object will be used by all created by this decorator States as their formatter.
protected abstract  StatePrototype newState()
          instantiate new class metadata object
 void setSelector(Selector selector)
          assign the methods selector to be used for identifying POJO methods subject to observation
 void setStateFormat(StateFormat format)
          set the State formatter This object is shared by all States created by this decorator as their formatting object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDecorator

public AbstractDecorator()
Method Detail

getStateFormat

public StateFormat getStateFormat()
Description copied from interface: Decorator
get State's formatting object

This object will be used by all created by this decorator States as their formatter.

Specified by:
getStateFormat in interface Decorator
Returns:
Returns State formatter.

setStateFormat

public void setStateFormat(StateFormat format)
Description copied from interface: Decorator
set the State formatter

This object is shared by all States created by this decorator as their formatting object.

Specified by:
setStateFormat in interface Decorator
Parameters:
format - is the State formatter to be used

getSelector

public Selector getSelector()
Description copied from interface: Decorator
get assigned Method's selector

Specified by:
getSelector in interface Decorator
Returns:
returns the selector.

setSelector

public void setSelector(Selector selector)
assign the methods selector to be used for identifying POJO methods subject to observation

Specified by:
setSelector in interface Decorator
Parameters:
selector -

decorate

public State decorate(java.lang.Object object)
               throws DecorationException
decorate the object using English locale and Thread's context class loader

Specified by:
decorate in interface Decorator
Parameters:
object - to be decorated
Returns:
decorated object
Throws:
DecorationException - is case of internal error while decorating

decorate

public State decorate(java.lang.Object object,
                      java.util.Locale locale)
               throws DecorationException
decorate the object using given locale settings and thread's context class loader

Specified by:
decorate in interface Decorator
Parameters:
object - to be decorated
locale - to be used
Returns:
decorated object
Throws:
DecorationException - is case of internal error while decorating

decorate

public State decorate(java.lang.Object object,
                      java.util.Locale locale,
                      java.lang.ClassLoader loader)
               throws DecorationException
decorate the object using given locale and class loader

Specified by:
decorate in interface Decorator
Parameters:
object - to be decorated
locale - to be used
loader - to be used
Returns:
decorated object
Throws:
DecorationException - is case of internal error while decorating

decorateObject

protected State decorateObject(java.lang.Object object,
                               java.util.Locale locale,
                               java.lang.ClassLoader loader)
                        throws DecorationException
decorate an object

It does maintain a cache of StatePrototype objects, which are created per unique combination of Class, Locale and Loader.

Parameters:
object -
Returns:
decorated object always, in case object is null it will return an empty State.
Throws:
DecorationException
See Also:

{@link StatePrototype} are cloned into actual {@link State} objects once the selecting of the POJO's methods has been done., decorateObject(StatePrototype, Object)


getCachedState

protected StatePrototype getCachedState(java.lang.String cacheKey)
look in cached StatePrototypes for already created definition with given key

Parameters:
cacheKey -
Returns:
cached class meta or null if no cached instance found

cacheState

protected void cacheState(java.lang.String key,
                          StatePrototype meta)
store the given StatePrototype in the cache

Parameters:
key -
meta - state information to be stored

getCacheKey

protected java.lang.String getCacheKey(java.lang.Class clazz,
                                       java.util.Locale locale,
                                       java.lang.ClassLoader loader)
create string key uniquely identifying given Class, Locale and ClassLoader

Parameters:
clazz -
locale -
loader -
Returns:
the key under which this data will be recognized

createState

protected StatePrototype createState(java.lang.Class clazz,
                                     java.util.Locale locale,
                                     java.lang.ClassLoader loader)
                              throws DecorationException
Inspect the class structure for suitable methods.

Use deep tree traversal of all super classes and interfaces.

Use Selector to determine which methods are to be included in the StatePrototype.

Parameters:
clazz - is POJO's class
locale -
loader -
Returns:
StatePrototype with 0 or more Properties inside
Throws:
DecorationException

decorateObject

protected State decorateObject(StatePrototype stateMeta,
                               java.lang.Object object)
                        throws DecorationException
clone stateMeta and assign to it the object

Parameters:
stateMeta - to be used
object - to be decorated
Returns:
cloned stateMeta object
Throws:
DecorationException

newState

protected abstract StatePrototype newState()
instantiate new class metadata object

Returns:
new StatePrototype object


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.