Implementing the Java class for the advanced design search
After the com.ibm.pdp.maf.rpp.mafAdvancedSearchPattern extension point is instantiated, you must code the Java class that implements its processing. It receives the pattern parameters and applies them to the instances targeted by the pattern. This class contributes to the constitution of the result list.
Procedure
Example
The following example illustrates the implementation of the ProgramByPgmID
class, which lists the Program instances by their COBOL program ID. This class implements a
STRING
pattern.
public class ProgramByPgmID extends MAFAbstractAdvancedSearchPattern {
public boolean accept(Object radicalElement, Map<String, Object> parameters, StringBuilder decoration) {
if (!(radicalElement instanceof Program))
return false;
Program program = (Program) radicalElement;
String expression = (String) parameters.get(IMAFAdvancedSearchPattern._STRING_EXPRESSION);
boolean caseSensitive = (Boolean) parameters.get(IMAFAdvancedSearchPattern._CASE_SENSITIVE);
Pattern pattern = getPattern(expression, caseSensitive);
if (pattern.matcher(program.getProgramId()).matches()) {
decoration.append(program.getProgramId());
return true;
}
return false;
}
}
The following example illustrates the implementation of the
ProgramByMacroCallNumber class, which lists the Program instances according to the
number of their Macro calls. This class implements an INTEGER
pattern.
public ProgramByMacroCallNumber() {
}
public boolean accept(Object radicalElement, Map<String, Object> parameters, StringBuilder decoration) {
if (!(radicalElement instanceof Program))
return false;
int value = (Integer) parameters.get(IMAFAdvancedSearchPattern._INTEGER_VALUE);
String operand = (String) parameters.get(IMAFAdvancedSearchPattern._INTEGER_OPERAND);
Program program = (Program) radicalElement;
int size = program.getCPLines().size();
switch (operand) {
case IMAFAdvancedSearchPattern._LOWER:
return size < value;
case IMAFAdvancedSearchPattern._LOWER_EQUAL:
return size <= value;
case IMAFAdvancedSearchPattern._EQUAL:
return size == value;
case IMAFAdvancedSearchPattern._GREATER_EQUAL:
return size >= value;
case IMAFAdvancedSearchPattern._GREATER:
return size > value;
}
return false;
}
}
The following example illustrates the implementation of the
ProgramNameEqualsPgmID class, which lists the Program instances whose names are
identical to their COBOL program ID. This class implements a BOOLEAN pattern.
public class ProgramNameEqualsPgmID extends MAFAbstractAdvancedSearchPattern {
public boolean accept(Object radicalElement, Map<String, Object> parameters, StringBuilder decoration) {
if (!(radicalElement instanceof Program))
return false;
Program program = (Program) radicalElement;
if (program.getName().equals(program.getProgramId()))
return true;
return false;
}
}
The following example illustrates the implementation of the ProgramMultiCriteria
class, which lists the Program instances according to various criteria. This example includes three
criteria: a string, an integer, and a boolean. The implementation of each parameter is not detailed
because it is too specific. This class implements a COMPOSITE pattern.
public class ProgramMultiCriteria extends MAFAbstractAdvancedSearchPattern {
public ProgramMultiCriteria() {
}
public boolean accept(Object radicalElement, Map<String, Object> parameters, StringBuilder decoration) {
if (!(radicalElement instanceof Program))
return false;
String stringParameter = (String) parameters.get("parameter1");
Integer integerParameter = (Integer) parameters.get("parameter2");
Boolean booleanParameter = (Boolean) parameters.get("parameter3");
Program program = (Program) radicalElement;
// ...
return true;
}
}