Defining expansion methods

When you add a parameter to a pattern in the Pattern Authoring view, a parameter class with two expansion methods is added to the pattern implementation model.

About this task

Expansion methods and the optional update methods are known as hot spots. You add Java code to the hot spots to dictate the pattern behavior when an argument value is added to or removed from a parameter.

To add extension code:

Procedure

  1. In the Pattern Authoring view, double-click the parameter to locate the parameter code in the Java editor.
  2. Replace the TODO comments in both methods with the code that performs the required behavior when an argument is added to or removed from the parameter in the pattern instance.
  3. Remove the @generated tag from any method that you modify to prohibit the pattern authoring tool from regenerating and removing your code.

Results

The following code shows examples of expansion methods:

The expansion method code for adding an argument.

The expansion method code for removing an argument.

To assist you with your code design, refer to the com.ibm.xtools.patterns.framework package's AbstractPatternParameter class. The AbstractPatternParameter class is the common implementation for a pattern parameter and is used indirectly through another subclass that further specializes this class. The abstract pattern parameter is the primary abstraction at runtime forming the backbone for an extension to take place through parameters, parameter dependencies and delegates. There are hot spots that can be overridden within this class. Most pattern implementations will implement some or most of these hot spots by overriding the hot spots methods. The most frequently implemented hot spots would be the expand and isValid methods. The hot spots methods are available for resolving alternatively specified parameter values and determining validity of these alternatively specified parameter values.

The PatternParameterValue class encapsulates all the information needed to qualify a value to the proper pattern parameter and pattern instance, plus provides nested subclasses that provide state-specific behavior corresponding to the state of the pattern parameter value. For example, when an expand method is called, the specific behavior provided by the pattern author is added to the expand method with the signature referencing the direct type of the pattern parameter value state, such as PatternParameterValue.ADDED, PatternParameterValue.REMOVED, PatternParameterValue.REPLACED, PatternParameterValue.MAINTAINED, PatternParameterValue.PROPOSED or PatternParameterValue.UNRESOLVED.


Feedback