1 5 package com.opensymphony.workflow.loader; 6 7 import com.opensymphony.workflow.InvalidWorkflowDescriptorException; 8 import com.opensymphony.workflow.util.Validatable; 9 import com.opensymphony.workflow.util.XMLizable; 10 11 import org.w3c.dom.Element ; 12 import org.w3c.dom.Node ; 13 import org.w3c.dom.NodeList ; 14 15 import java.io.PrintWriter ; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 21 27 public class ConditionsDescriptor extends AbstractDescriptor implements Validatable { 28 30 private List conditions = new ArrayList (); 31 private String type; 32 33 35 public ConditionsDescriptor() { 36 } 37 38 public ConditionsDescriptor(Element element) { 39 type = element.getAttribute("type"); 40 41 NodeList children = element.getChildNodes(); 42 int size = children.getLength(); 43 44 for (int i = 0; i < size; i++) { 45 Node child = children.item(i); 46 47 if (child instanceof Element ) { 48 if ("condition".equals(child.getNodeName())) { 49 ConditionDescriptor condition = new ConditionDescriptor((Element ) child); 50 conditions.add(condition); 51 } else if ("conditions".equals(child.getNodeName())) { 52 ConditionsDescriptor condition = new ConditionsDescriptor((Element ) child); 53 conditions.add(condition); 54 } 55 } 56 } 57 } 58 59 61 public void setConditions(List conditions) { 62 this.conditions = conditions; 63 } 64 65 public List getConditions() { 66 return conditions; 67 } 68 69 public void setType(String type) { 70 this.type = type; 71 } 72 73 public String getType() { 74 return type; 75 } 76 77 public void validate() throws InvalidWorkflowDescriptorException { 78 ValidationHelper.validate(conditions); 79 80 if ((conditions.size() > 1) && (type == null)) { 81 throw new InvalidWorkflowDescriptorException("Conditions must have AND or OR type specified"); 82 } 83 } 84 85 public void writeXML(PrintWriter out, int indent) { 86 if (conditions.size() > 0) { 87 XMLUtil.printIndent(out, indent++); 88 89 StringBuffer sb = new StringBuffer ("<conditions"); 90 91 if (conditions.size() > 1) { 92 sb.append(" type=\"").append(type).append("\""); 93 } 94 95 sb.append(">"); 96 out.println(sb.toString()); 97 98 for (int i = 0; i < conditions.size(); i++) { 99 XMLizable condition = (XMLizable) conditions.get(i); 100 condition.writeXML(out, indent); 101 } 102 103 XMLUtil.printIndent(out, --indent); 104 out.println("</conditions>"); 105 } 106 } 107 } 108 | Popular Tags |