net.sf.fikin.pojostate
Interface Decorator

All Known Implementing Classes:
AbstractDecorator, DynamicDecorator, SnapshotDecorator

public interface Decorator

Decorator

Decorates an object (POJO) with State.

Actual decoration means that the POJO will be wrapped by a new State object, which provides convenient methods for visualization its state.

Selecting the methods (from the list of all class methods) is responsibility of Selector interface.

Decorators are locale specific i.e. one can have differently behaving State objects for different locales.

Decorators are responsible to decide upon the actual type of State being created. Different State objects behave differently and are better suited for different usage scenarios. For example, rarely changing POJOs with frequent reads are suited best by snapshot type of State object, while very dynamic POJOs might be better served by dynamic type of State object.

Typically decorators are immutable i.e. once internal properties has been set once can't change them later on. This is defined so in order to allow for State object to have a safe reference to some of the settings which instantiated them.

Decorators are reusable, one can use one and same decorator to decorate similarly many POJOs.

Example: create :

      import net.sf.fikin.pojostate.*;
      import net.sf.fikin.pojostate.decorate.*;
      import net.sf.fikin.pojostate.select.*;
      import net.sf.fikin.pojostate.format.*;
      
      Decorator decorator = new SnapshotDecorator();
      
      // initialize decorator's internal state
      decorator.setSelector( new BeanSelector() );
      decorator.setFormat( new PropertiesTableFormat() );

      // decode "this"
      State state = decorator.decorate( this );
      System.out.println( state.toString() );
      
      state.sort( State.SORT_BY_VALUE, State.SORT_DESC );
      System.out.println( state.toString() );
 
created on Jul 15, 2005

Since:
Version:
$Revision: 1.4 $
Author:
fiykov

Method Summary
 State decorate(java.lang.Object object)
          decorate the object with default locale
 State decorate(java.lang.Object object, java.util.Locale locale)
          decorate the object suiting given locale settings use it when you're having external resource file containing methods (and their descriptions and/or formatting rules) which has been localized resource file loading happens with Thread's context class loader
 State decorate(java.lang.Object object, java.util.Locale locale, java.lang.ClassLoader loader)
          decorate the object suiting given locale settings and using given class loader use it when you're having external resource file containing methods (and their descriptions and/or formatting rules) which has been localized
 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.
 void setSelector(Selector selector)
          set the Methods selector Selectors are used to identifying which POJO methods will be visible by the State and which not.
 void setStateFormat(StateFormat stateFormatter)
          set the State formatter This object is shared by all States created by this decorator as their formatting object.
 

Method Detail

setSelector

void setSelector(Selector selector)
set the Methods selector

Selectors are used to identifying which POJO methods will be visible by the State and which not.

Parameters:
selector - object to be used

getSelector

Selector getSelector()
get assigned Method's selector

Returns:
selector object or null if not set yet

setStateFormat

void setStateFormat(StateFormat stateFormatter)
set the State formatter

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

Parameters:
stateFormatter -

getStateFormat

StateFormat getStateFormat()
get State's formatting object

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

Returns:
the formatter used by all created by this decorator States. It is null if not set yet.

decorate

State decorate(java.lang.Object object)
               throws DecorationException
decorate the object with default locale

Parameters:
object - to be decorated, null value will result in returning an empty State
Returns:
a State object
Throws:
DecorationException - in case of internal error while decorating

decorate

State decorate(java.lang.Object object,
               java.util.Locale locale)
               throws DecorationException
decorate the object suiting given locale settings

use it when you're having external resource file containing methods (and their descriptions and/or formatting rules) which has been localized

resource file loading happens with Thread's context class loader

Parameters:
object - to be decorated
locale - to be used, if null default locale will be used
Returns:
a State object
Throws:
DecorationException - in case of internal error while decorating

decorate

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

use it when you're having external resource file containing methods (and their descriptions and/or formatting rules) which has been localized

Parameters:
object - to be decorated
locale - to be used, if null default will be used
loader - to be used to load the resource file, if null default will be used
Returns:
a State object
Throws:
DecorationException - in case of internal error while decorating


Copyright © 2005 Nikolay Fiykov. All Rights Reserved.