SMILA (incubation) API documentation

org.eclipse.smila.processing.parameters
Class ParameterAccessor

java.lang.Object
  extended by org.eclipse.smila.processing.parameters.ParameterAccessor
Direct Known Subclasses:
QueryParameterAccessor

public class ParameterAccessor
extends java.lang.Object

Read service runtime parameters from current processed record or pipelet configuration. The accessor can read a parameter either from a record on blackboard (if initialized with a blackboard and a "current record ID" is set), or from pipelet configuration (if set). The idea is that attributes in a special location in the records can override settings from the pipelet configuration. The default location for this is a map in the record attribute "_parameters" (see DEFAULT_PARAMETERS_ATTRIBUTE), but this can be changed using setParameterAttribute(String). As a simple example: Assume this pipelet configuration:

 <proc:configuration>
   <rec:Val key="property">configured</rec:Val>
 </proc:configuration>
 
and a record on the blackboard looking like this:
 <rec:Val key="_recordid">foobar</rec:Val>
 <rec:Map key="_parameters">
   <rec:Val key="property">overridden</rec:Val>
 </rec:Map>
 
Then this code:
   ParameterAccessor parameters = new ParameterAccessor(blackboard, configuration);
   String propertyValue = parameters.getRequiredParameter("property");
 
will set propertyValue to "configured". This code:
   ParameterAccessor parameters = new ParameterAccessor(blackboard, configuration);
   parameters.setCurrentRecord("foobar");
   String propertyValue = parameters.getRequiredParameter("property");
 
will set propertyValue to "overridden".


Field Summary
protected  Blackboard _blackboard
          blackboard service in processing.
protected  AnyMap _config
          pipelet configuration (optional).
protected  java.lang.String _parametersAttribute
          root attribute for parameters in records from blackboard.
protected  java.lang.String _recordId
          ID of currently processed record.
static java.lang.String DEFAULT_PARAMETERS_ATTRIBUTE
          record attribute to check for parameters.
 
Constructor Summary
ParameterAccessor(AnyMap configuration)
          create accessor for given configuration.
ParameterAccessor(Blackboard blackboard)
          create accessor for given blackboard.
ParameterAccessor(Blackboard blackboard, AnyMap configuration)
          create accessor for given blackboard.
ParameterAccessor(Blackboard blackboard, AnyMap configuration, java.lang.String recordId)
          for search pipelets/services: create accessor for given blackboard and request record.
ParameterAccessor(Blackboard blackboard, java.lang.String recordId)
          for search pipelets/services: create accessor for given blackboard and request record.
 
Method Summary
 java.lang.Boolean getBooleanParameter(java.lang.String name, java.lang.Boolean defaultValue)
          type-aware convenience method: convert result of getParameter() to Boolean.
 java.lang.Double getFloatParameter(java.lang.String name, java.lang.Double defaultValue)
          type-aware convenience method: convert result of getParameter() to Double.
 java.lang.Integer getIntParameter(java.lang.String name, java.lang.Integer defaultValue)
          type-aware convenience method: convert result of getParameter() to Integer.
 java.lang.String getParameter(java.lang.String name, java.lang.String defaultValue)
          get named value of parameter annotation, according to precedence rules.
 Any getParameterAny(java.lang.String name)
          get the native any in parameter "name", according to precedence rules.
 java.lang.String getParameterAttribute()
           
 java.util.List<java.lang.String> getParameters(java.lang.String name)
          get anonymous values of first (according to precendence rules) subannotation.
 java.lang.Boolean getRequiredBooleanParameter(java.lang.String name)
          type-aware convenience method: convert result of getRequiredParameter() to Boolean.
 java.lang.Double getRequiredFloatParameter(java.lang.String name)
          type-aware convenience method: convert result of getRequiredParameter() to Double.
 java.lang.Integer getRequiredIntParameter(java.lang.String name)
          type-aware convenience method: convert result of getRequiredParameter() to Integer.
 java.lang.String getRequiredParameter(java.lang.String name)
          get named value of parameter annotation, according to precedence rules.
 java.util.List<java.lang.String> getRequiredParameters(java.lang.String name)
          get anonymous values of first (according to precendence rules) subannotation.
 AnyMap getSubParameter(java.lang.String name)
          access to first subannotation, according to precedence rules.
 java.util.List<AnyMap> getSubParameters(java.lang.String name)
          access to a multiple sub parameters, according to precedence rules.
 ParameterAccessor setCurrentRecord(java.lang.String recordId)
          set the ID of the record to read parameters from.
 void setParameterAttribute(java.lang.String parameterAttribute)
          set root attribute for parameters in records from blackboard.
 ParameterAccessor setPipeletConfiguration(AnyMap config)
          set the configuration of the current pipelet, to read fallback values for missing parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PARAMETERS_ATTRIBUTE

public static final java.lang.String DEFAULT_PARAMETERS_ATTRIBUTE
record attribute to check for parameters.

See Also:
Constant Field Values

_blackboard

protected final Blackboard _blackboard
blackboard service in processing.


_recordId

protected java.lang.String _recordId
ID of currently processed record. (optional).


_config

protected AnyMap _config
pipelet configuration (optional).


_parametersAttribute

protected java.lang.String _parametersAttribute
root attribute for parameters in records from blackboard. Can be null.

Constructor Detail

ParameterAccessor

public ParameterAccessor(AnyMap configuration)
create accessor for given configuration. Accessing records is not possible with this instance.

Parameters:
configuration - pipelet configuration

ParameterAccessor

public ParameterAccessor(Blackboard blackboard)
create accessor for given blackboard.

Parameters:
blackboard - blackboard instance.

ParameterAccessor

public ParameterAccessor(Blackboard blackboard,
                         AnyMap configuration)
create accessor for given blackboard.

Parameters:
blackboard - blackboard instance.
configuration - pipelet configuration

ParameterAccessor

public ParameterAccessor(Blackboard blackboard,
                         AnyMap configuration,
                         java.lang.String recordId)
for search pipelets/services: create accessor for given blackboard and request record.

Parameters:
blackboard - blackboard instance.
configuration - pipelet configuration
recordId - current query record.

ParameterAccessor

public ParameterAccessor(Blackboard blackboard,
                         java.lang.String recordId)
for search pipelets/services: create accessor for given blackboard and request record.

Parameters:
blackboard - blackboard instance.
recordId - current query record.
Method Detail

setParameterAttribute

public void setParameterAttribute(java.lang.String parameterAttribute)
set root attribute for parameters in records from blackboard. For example, if set to "something", the accessor expects a single map element in attribute "something" and interprets it's sub attributes as parameters. If set to null, the top-level attributes of records are interpreted as parameters.


getParameterAttribute

public java.lang.String getParameterAttribute()
Returns:
root attribute for parameters in records from blackboard. Can be null.

setCurrentRecord

public ParameterAccessor setCurrentRecord(java.lang.String recordId)
set the ID of the record to read parameters from.

Parameters:
recordId - current record to process.
Returns:
"this", make it easier to use this method immediately after constructor.

setPipeletConfiguration

public ParameterAccessor setPipeletConfiguration(AnyMap config)
set the configuration of the current pipelet, to read fallback values for missing parameters.

Parameters:
config - pipelet configuration.
Returns:
"this", make it easier to use this method immediately after constructor

getParameter

public java.lang.String getParameter(java.lang.String name,
                                     java.lang.String defaultValue)
get named value of parameter annotation, according to precedence rules.

Parameters:
name - parameter name
defaultValue - default value.
Returns:
return default value if no matching parameter value can be found

getRequiredParameter

public java.lang.String getRequiredParameter(java.lang.String name)
                                      throws MissingParameterException
get named value of parameter annotation, according to precedence rules.

Parameters:
name - parameter name.
Returns:
parameter value.
Throws:
MissingParameterException - if no matching parameter value can be found.

getParameters

public java.util.List<java.lang.String> getParameters(java.lang.String name)
get anonymous values of first (according to precendence rules) subannotation.

Parameters:
name - parameter name
Returns:
anonymous values of named subannotation, or empty list if no matching parameter value can be found

getRequiredParameters

public java.util.List<java.lang.String> getRequiredParameters(java.lang.String name)
                                                       throws MissingParameterException
get anonymous values of first (according to precendence rules) subannotation.

Parameters:
name - parameter name
Returns:
anonymous values of named subannotation,
Throws:
MissingParameterException - if no matching parameter value can be found.

getIntParameter

public java.lang.Integer getIntParameter(java.lang.String name,
                                         java.lang.Integer defaultValue)
type-aware convenience method: convert result of getParameter() to Integer. Throws NumberFormatException, if parameter value is not in valid integer format.

Parameters:
name - parameter name
defaultValue - default value
Returns:
integer value

getFloatParameter

public java.lang.Double getFloatParameter(java.lang.String name,
                                          java.lang.Double defaultValue)
type-aware convenience method: convert result of getParameter() to Double. Throws NumberFormatException if parameter value is not in valid double format.

Parameters:
name - parameter name
defaultValue - default value
Returns:
double value

getBooleanParameter

public java.lang.Boolean getBooleanParameter(java.lang.String name,
                                             java.lang.Boolean defaultValue)
type-aware convenience method: convert result of getParameter() to Boolean.

Parameters:
name - parameter name
defaultValue - default value
Returns:
double value

getRequiredIntParameter

public java.lang.Integer getRequiredIntParameter(java.lang.String name)
                                          throws MissingParameterException
type-aware convenience method: convert result of getRequiredParameter() to Integer. Throws NumberFormatException, if parameter value is not in valid integer format.

Parameters:
name - parameter name
Returns:
integer value *
Throws:
MissingParameterException - if no matching parameter value can be found.

getRequiredFloatParameter

public java.lang.Double getRequiredFloatParameter(java.lang.String name)
                                           throws MissingParameterException
type-aware convenience method: convert result of getRequiredParameter() to Double. Throws NumberFormatException, if parameter value is not in valid double format.

Parameters:
name - parameter name
Returns:
floating point value *
Throws:
MissingParameterException - if no matching parameter value can be found.

getRequiredBooleanParameter

public java.lang.Boolean getRequiredBooleanParameter(java.lang.String name)
                                              throws MissingParameterException
type-aware convenience method: convert result of getRequiredParameter() to Boolean.

Parameters:
name - parameter name
Returns:
boolean value *
Throws:
MissingParameterException - if no matching parameter value can be found.

getSubParameter

public AnyMap getSubParameter(java.lang.String name)
access to first subannotation, according to precedence rules.

Parameters:
name - annotation name.
Returns:
annotation object.

getSubParameters

public java.util.List<AnyMap> getSubParameters(java.lang.String name)
access to a multiple sub parameters, according to precedence rules. The parameters are not merged from multiple sources

Parameters:
name - annotation name.
Returns:
list of parameters.

getParameterAny

public Any getParameterAny(java.lang.String name)
get the native any in parameter "name", according to precedence rules.

Parameters:
name - parameter name
Returns:
parameter any.

SMILA (incubation) API documentation