blob: 2451c570409bbac71c89934f17169809d0061617 [file] [log] [blame]
public class Runner {
/** The root node from where validation should be started */
INode fRoot;
/** The query interface to our model */
IModelQuery fModelQuery;
/** empty list of problems */
IProblem[] fProblems = {};
/**
* Return a brand new shiny instance of a runner. The runner's purpose is to validate
* the nodes in the tree starting at node passed.
*
* @param query the model query
* @param root the root node.
*/
public Runner ( IModelQuery query, INode root) {
fRoot = root ;
fModelQuery = query;
}
/**
* Perform the validation run.
*
* @return list of problems found.
*/
public IProblem[] run () {
// Create a depth first iteration from the root node
ArrayList<INode> iteratorList = new ArrayList<INode>(32);
ArrayList<Validator> validatorList = new ArrayList<Validator>(256);
// start at the root node
iteratorList.add(fRoot);
// 1. Generate the list of validators to call, in order
while (iteratorList.size() > 0) {
INode nextNode = iteratorList.remove(0);
Validator validator = nextNode.nodeValidator();
if (validator != null) {
validatorList.add(validator);
validator.setModelQuery(fModelQuery);
}
// the facaded object will tell us what children to include in the walk
List<INode> children = nextNode.children();
if (children.size() > 0) {
iteratorList.addAll(0, children);
}
}
// Pass 1
for(Validator validator : validatorList) {
validator.validate(Validator.PASS1);
}
ArrayList<IProblem> problems = new ArrayList<IProblem>( 64 );
// Pass 2
// On the validators that have been run, perform the final rule pass.
for(Validator validator : validatorList) {
validator.validate(Validator.PASS2);
for(IProblem problem : validator.getProblems() ) {
problems.add (problem);
}
}
return problems.toArray( fProblems );
}
}