/** Initialises the template descriptor and Root Elements. */ private void initialize() { TemplateDescriptor desc = template.getTemplateDescriptor(); Element root = desc.getRootElement(); conditionalProcessGroupList = new ArrayList<ConditionalProcessGroup>(); List<Element> nodeList = TemplateEngine.getChildrenOfElementByTag(root, TemplateDescriptor.IF); for (int j = 0, l = nodeList.size(); j < l; j++) { conditionalProcessGroupList.add( new ConditionalProcessGroup(template, nodeList.get(j), j + 1)); } // Collect all free-hanging processes in one ConditionalProcessGroup object with condition true. nodeList = TemplateEngine.getChildrenOfElementByTag(root, TemplateDescriptor.PROCESS); conditionalProcessGroupList.add( new ConditionalProcessGroup(template, nodeList.toArray(new Element[nodeList.size()]))); }
/** * Constructs a ConditionalProcess element from the supplied conditionElement (<if>) while * building Process objects out of each of the element's <process> children. */ public ConditionalProcessGroup(TemplateCore template, Element conditionElement, int id) { this.id = "Condition " + id; // $NON-NLS-1$ conditionString = conditionElement.getAttribute(ProcessHelper.CONDITION); if (conditionString != null) { if (conditionString.trim().equals("")) { // $NON-NLS-1$ conditionString = null; } else { int op = conditionString.indexOf(ProcessHelper.EQUALS); if (op != -1) { this.operator = Operator.EQUALS; lValue = conditionString.substring(0, op); rValue = conditionString.substring(op + ProcessHelper.EQUALS.length()); } else { op = conditionString.indexOf(ProcessHelper.NOT_EQUALS); if (op != -1) { this.operator = Operator.NOT_EQUALS; lValue = conditionString.substring(0, op); rValue = conditionString.substring(op + ProcessHelper.NOT_EQUALS.length()); } // else an unsupported operation where this condition is ignored. } collectMacros(lValue); collectMacros(rValue); } } createProcessObjects( template, TemplateEngine.getChildrenOfElementByTag(conditionElement, TemplateDescriptor.PROCESS)); }