Defining update methods

A pattern can contain multiple parameters where the argument for one parameter, the supplier parameter, is used to calculate the values for dependent (client) parameters. When the user specifies a valid argument for a supplier parameter, the update methods are called to recompute the dependent client parameters.

About this task

You add a dependency relationship by using the New Pattern wizard when adding a new pattern or by using the Properties view from the Pattern Authoring view. When added, the code for update hot spot methods is added to the pattern implementation code. The three types of update methods are generated only for the client parameter. Update methods are invoked for the following activities: addition of a supplier argument, removal of a supplier argument, and no change to the supplier argument when the pattern is reapplied.

Using update methods, you can suppress total or partial expansion of the client parameter until the required values are specified in the supplier parameters. The AbstractPatternDependency class (com.ibm.xtools.patterns.framework) contains the update methods. This class represents a dependency between two pattern parameters, the dependent pattern parameter dependent on the dependency parameter. It observes the dependency parameter and notifies the dependent parameter under the various state-triggered update methods.

A pattern parameter dependency is typically associated with a pattern parameter by instantiating a dependency within the constructor of a pattern parameter. Dependencies are stored and managed within the abstract pattern parameter class. This class needs to be subclassed by a concrete dependency implementation that can then override the defined hot spot methods to alter the dependency runtime behavior. By default, the hot spot methods can be found by examining which methods are not marked final. In this class, the hot spot methods are primarily the variants of the overloaded update method.

To add code to the update methods:

Procedure

  1. In the Pattern Authoring view, double-click the client parameter to locate the parameter's code in the Java editor.
  2. Scroll down past the dependency class and its constructor to locate the update methods.
  3. Replace the TODO comments in the update methods with the code that performs the required behaviors to address addition, removal, and maintenance of an argument in the pattern instance.
  4. Remove the @generated tag from any method that you modify to prohibit the pattern authoring tool from regenerating and removing your code.

Results

Note: You can use CTRL-O in the editor for an outline view that provides quick access to nested classes and methods.

The following code shows examples of update methods:

The expansion update method code for adding an argument.

The expansion update method code for removing an argument.

The expansion update method code for maintaining an argument value during reapply.


Feedback