Interface ValueFunction


public interface ValueFunction
Computes a value when this value is not persisted by EBX® repository.

Definition in the data model

The specific function must be declared under the element xs:annotation/xs:appinfo (see Computed Values):

 <osd:function class="com.foo.MyFunction"/>
 
where com.foo.MyFunction is the fully qualified name of the class implementing this interface. It is also possible to set additional JavaBean properties:
 <osd:function class="com.foo.MyFunction">
          <param1>...</param1>
          <param2>...</param2>
 </osd:function>
 
where param1 and param2 are JavaBean properties of the class specified.

For more information, see the JavaBean specification.

Life cycle

  1. When the data model is loaded:
    1. the class specified is instantiated through its default constructor and the setters of the JavaBean properties are called (in the example above, setParam1(...) and setParam2(...));
    2. the method setup(ValueFunctionContext) is called on the new instance.
  2. During the operational phase: the method getValue(Adaptation) is called each time this is needed (for example when the record is displayed or exported).

Performance warning

See getValue(Adaptation).

  • Method Summary

    Modifier and Type
    Method
    Description
    getValue(Adaptation aDataSetOrRecord)
    Returns the value in the context of the specified record or dataset.
    void
    This method is called when the data model is loaded, for checking that this rule is consistent with the data model that defines it.
  • Method Details

    • getValue

      Object getValue(Adaptation aDataSetOrRecord)
      Returns the value in the context of the specified record or dataset.

      The value returned must conform to the associated data model declaration (that is, the type, cardinality, facets).

      Performance warning

      If the rule is attached to a table with N records, some operations will call this method N times. This is the case for:

      • an external export (but the method ExportSpec.setIncludesComputedValues(boolean) will deactivate the call to the function);
      • a filter, when the filter depends on this node;
      • full dataset validation, when the node is used by some dynamic constraints. It is however possible to avoid this call if the validation is disabled on the associated node by specifying in the data model the attribute osd:disableValidation = "true".

      Thus, for a table with large volumes of records, it may be necessary to optimize the implementation (for example, by caching). See also the performance and tuning chapter.

      Multi-threading

      For a single instance of this interface, this method may be called concurrently by several threads.It is therefore important to ensure that the value resolution is thread-safe. It is recommended to use a stateless implementation and to avoid keeping references to adaptation objects.

      See Also:
    • setup

      void setup(ValueFunctionContext aContext)
      This method is called when the data model is loaded, for checking that this rule is consistent with the data model that defines it.

      Do note that during this step, all models may not be properly loaded. Thus, the repository should not be accessed during this step.