net.sf.mmm.util.pojo.path.base
Class AbstractPojoPathFunction<IN,VALUE>

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.pojo.path.base.AbstractPojoPathFunction<IN,VALUE>
Type Parameters:
IN - is the generic input-type.
VALUE - is the generic value-type
All Implemented Interfaces:
PojoPathFunction<IN,VALUE>
Direct Known Subclasses:
AbstractMapPojoPathFunction, PojoPathNamedFunctionToString

public abstract class AbstractPojoPathFunction<IN,VALUE>
extends AbstractLoggableComponent
implements PojoPathFunction<IN,VALUE>

This is the abstract base implementation of the PojoPathFunction interface.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
 
Fields inherited from interface net.sf.mmm.util.pojo.path.api.PojoPathFunction
FUNCTION_NAME_PREFIX
 
Constructor Summary
AbstractPojoPathFunction()
          The constructor.
 
Method Summary
 VALUE create(IN actual, String functionName, PojoPathContext context)
          This method creates an appropriate new value.
 VALUE get(IN actual, String functionName, PojoPathContext context)
          This method gets the value of this function.
protected  String getFunctionDescription(String functionName)
          This method gets a description of this function.
 boolean isDeterministic()
          This method determines if this PojoPathFunction is deterministic.
 VALUE set(IN actual, String functionName, VALUE value, PojoPathContext context)
          This method sets the given value for the given actual Pojo.
 String toString()
          
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.pojo.path.api.PojoPathFunction
getInputClass, getValueClass
 

Constructor Detail

AbstractPojoPathFunction

public AbstractPojoPathFunction()
The constructor.

Method Detail

isDeterministic

public boolean isDeterministic()
This method determines if this PojoPathFunction is deterministic. In this case it has to guarantee that repetitive calls of get with the same (unmodified) actual Pojo will produce the same result.
Typically a PojoPathFunction should be deterministic. However in some cases the calculation of a PojoPathFunction may depend on the current time or a random value and will therefore be indeterministic.
If a PojoPathFunction is indeterministic, the caching will disabled for its result and further traversals.
Of course this method has to be deterministic and should always return the same boolean result for the same instance. This implementation always returns true. Override for indeterministic implementations.

Specified by:
isDeterministic in interface PojoPathFunction<IN,VALUE>
Returns:
true if this function is deterministic, false otherwise.

getFunctionDescription

protected String getFunctionDescription(String functionName)
This method gets a description of this function.

Parameters:
functionName - is the name under which this function was invoked.
Returns:
a string describing this function.

create

public VALUE create(IN actual,
                    String functionName,
                    PojoPathContext context)
This method creates an appropriate new value. It is invoked by PojoPathNavigator. get if the mode is PojoPathMode.CREATE_IF_NULL after get returned null.
A typical implementation may create a new instance of <VALUE> via the pojo-factory. Further in most cases the created value instance will be attached to the given actual Pojo.

Specified by:
create in interface PojoPathFunction<IN,VALUE>
Parameters:
actual - is the actual Pojo where this function is invoked on. Typically the returned value should be retrieved via this object.
functionName - is the name under which this PojoPathFunction was invoked via the PojoPathNavigator excluding the PojoPathFunction.FUNCTION_NAME_PREFIX.
context - is the PojoPathContext providing additional context information. Objects traversed between actual and the returned value should be recognized via the recognizer.
Returns:
the created value. It may be null if creation is NOT possible. However returning null here will cause the PojoPathNavigator to fail with an exception.

get

public VALUE get(IN actual,
                 String functionName,
                 PojoPathContext context)
This method gets the value of this function. It is invoked by PojoPathNavigator. get independent of the PojoPathMode. A regular implementation should only return what is already there. However in specific cases this may NOT (initially) be available from the given Pojo actual and therefore be retrieved from somewhere else (e.g. a database using a primary key given via a property of the given context). Further it can be legal to modify the actual Pojo e.g. by attaching the externally retrieved result.

Specified by:
get in interface PojoPathFunction<IN,VALUE>
Parameters:
actual - is the actual Pojo where this function is invoked on. Typically the returned value should be retrieved via this object.
functionName - is the name under which this PojoPathFunction was invoked via the PojoPathNavigator excluding the PojoPathFunction.FUNCTION_NAME_PREFIX.
context - is the PojoPathContext providing additional context information. Objects traversed between actual and the returned value should be recognized via the recognizer.
Returns:
the value of this function or null if NOT available.

set

public VALUE set(IN actual,
                 String functionName,
                 VALUE value,
                 PojoPathContext context)
This method sets the given value for the given actual Pojo.
After this method has been successfully invoked, the method get should return the same value for identical arguments.

Specified by:
set in interface PojoPathFunction<IN,VALUE>
Parameters:
actual - is the actual Pojo where this function is invoked on. Typically the given value should be set in this object.
functionName - is the name under which this PojoPathFunction was invoked via the PojoPathNavigator excluding the PojoPathFunction.FUNCTION_NAME_PREFIX.
value - is the value to set.
context - is the PojoPathContext providing additional context information. Objects traversed between actual and the returned value should be recognized via the recognizer.
Returns:
the previous value that has been replaced or null.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2001-2010 mmm-Team. All Rights Reserved.