1 5 package com.opensymphony.workflow.loader; 6 7 import com.opensymphony.workflow.InvalidWorkflowDescriptorException; 8 9 import org.w3c.dom.Element ; 10 11 import java.io.PrintWriter ; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 17 21 public class ConditionalResultDescriptor extends ResultDescriptor { 22 24 protected List conditions = new ArrayList (); 25 26 28 public ConditionalResultDescriptor() { 29 } 30 31 public ConditionalResultDescriptor(Element conditionalResult) { 32 init(conditionalResult); 33 } 34 35 37 public List getConditions() { 38 return conditions; 39 } 40 41 public void validate() throws InvalidWorkflowDescriptorException { 42 super.validate(); 43 44 if (conditions.size() == 0) { 45 throw new InvalidWorkflowDescriptorException("Conditional result from " + ((ActionDescriptor) getParent()).getName() + " to " + getDestination() + " must have at least one condition"); 46 } 47 48 ValidationHelper.validate(conditions); 49 } 50 51 public void writeXML(PrintWriter out, int indent) { 52 XMLUtil.printIndent(out, indent++); 53 54 StringBuffer buf = new StringBuffer (); 55 buf.append("<result"); 56 57 if (hasId()) { 58 buf.append(" id=\"").append(getId()).append("\""); 59 } 60 61 buf.append(" old-status=\"").append(oldStatus).append("\""); 62 63 if (join != 0) { 64 buf.append(" join=\"").append(join).append("\""); 65 } else if (split != 0) { 66 buf.append(" split=\"").append(split).append("\""); 67 } else { 68 buf.append(" status=\"").append(status).append("\""); 69 buf.append(" step=\"").append(step).append("\""); 70 71 if ((owner != null) && (owner.length() > 0)) { 72 buf.append(" owner=\"").append(owner).append("\""); 73 } 74 } 75 76 buf.append(">"); 77 out.println(buf); 78 79 for (int i = 0; i < conditions.size(); i++) { 80 ConditionsDescriptor condition = (ConditionsDescriptor) conditions.get(i); 81 condition.writeXML(out, indent); 82 } 83 84 if (validators.size() > 0) { 85 XMLUtil.printIndent(out, indent++); 86 out.println("<validators>"); 87 88 for (int i = 0; i < validators.size(); i++) { 89 ValidatorDescriptor validator = (ValidatorDescriptor) validators.get(i); 90 validator.writeXML(out, indent); 91 } 92 93 XMLUtil.printIndent(out, --indent); 94 out.println("</validators>"); 95 } 96 97 printPreFunctions(out, indent); 98 printPostFunctions(out, indent); 99 XMLUtil.printIndent(out, --indent); 100 out.println("</result>"); 101 } 102 103 protected void init(Element conditionalResult) { 104 super.init(conditionalResult); 105 106 List conditionNodes = XMLUtil.getChildElements(conditionalResult, "conditions"); 107 108 int length = conditionNodes.size(); 109 110 for (int i = 0; i < length; i++) { 111 Element condition = (Element ) conditionNodes.get(i); 112 ConditionsDescriptor conditionDescriptor = new ConditionsDescriptor(condition); 113 conditionDescriptor.setParent(this); 114 this.conditions.add(conditionDescriptor); 115 } 116 } 117 118 private String getDestination() { 119 if (join != 0) { 120 return "join #" + join; 121 } else if (split != 0) { 122 return "split #" + split; 123 } else { 124 return "step #" + step; 125 } 126 } 127 } 128 | Popular Tags |