1 5 package com.opensymphony.workflow.loader; 6 7 import com.opensymphony.workflow.InvalidWorkflowDescriptorException; 8 import com.opensymphony.workflow.util.Validatable; 9 10 import org.w3c.dom.Element ; 11 12 import java.io.PrintWriter ; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 18 24 public class JoinDescriptor extends AbstractDescriptor implements Validatable { 25 27 protected List conditions = new ArrayList (); 28 protected ResultDescriptor result; 29 30 32 public JoinDescriptor() { 33 } 34 35 public JoinDescriptor(Element join) { 36 init(join); 37 } 38 39 41 public List getConditions() { 42 return conditions; 43 } 44 45 public void setResult(ResultDescriptor result) { 46 this.result = result; 47 } 48 49 public ResultDescriptor getResult() { 50 return result; 51 } 52 53 public void validate() throws InvalidWorkflowDescriptorException { 54 ValidationHelper.validate(conditions); 55 56 if (result == null) { 57 throw new InvalidWorkflowDescriptorException("Join has no result"); 58 } 59 60 result.validate(); 61 } 62 63 public void writeXML(PrintWriter out, int indent) { 64 XMLUtil.printIndent(out, indent++); 65 out.println("<join id=\"" + getId() + "\">"); 66 67 if (conditions.size() > 0) { 68 for (int i = 0; i < conditions.size(); i++) { 69 ConditionsDescriptor condition = (ConditionsDescriptor) conditions.get(i); 70 condition.writeXML(out, indent); 71 } 72 } 73 74 result.writeXML(out, indent); 75 XMLUtil.printIndent(out, --indent); 76 out.println("</join>"); 77 } 78 79 protected void init(Element join) { 80 try { 81 setId(Integer.parseInt(join.getAttribute("id"))); 82 } catch (Exception ex) { 83 throw new IllegalArgumentException ("Invalid join id value " + join.getAttribute("id")); 84 } 85 86 List conditionNodes = XMLUtil.getChildElements(join, "conditions"); 88 int length = conditionNodes.size(); 89 90 for (int i = 0; i < length; i++) { 91 Element condition = (Element ) conditionNodes.get(i); 92 ConditionsDescriptor conditionDescriptor = new ConditionsDescriptor(condition); 93 conditionDescriptor.setParent(this); 94 this.conditions.add(conditionDescriptor); 95 } 96 97 Element resultElement = XMLUtil.getChildElement(join, "unconditional-result"); 99 result = new ResultDescriptor(resultElement); 100 result.setParent(this); 101 } 102 } 103 | Popular Tags |