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 22 public class RestrictionDescriptor extends AbstractDescriptor implements Validatable { 23 25 protected List conditions = new ArrayList (); 26 27 29 public RestrictionDescriptor() { 30 } 31 32 public RestrictionDescriptor(Element restriction) { 33 init(restriction); 34 } 35 36 38 public List getConditions() { 39 return conditions; 40 } 41 42 public void validate() throws InvalidWorkflowDescriptorException { 43 ValidationHelper.validate(conditions); 44 } 45 46 public void writeXML(PrintWriter out, int indent) { 47 if (conditions.size() == 0) { 48 return; 49 } 50 51 XMLUtil.printIndent(out, indent++); 52 out.println("<restrict-to>"); 53 54 if (conditions.size() > 0) { 55 for (int i = 0; i < conditions.size(); i++) { 56 ConditionsDescriptor condition = (ConditionsDescriptor) conditions.get(i); 57 condition.writeXML(out, indent); 58 } 59 } 60 61 XMLUtil.printIndent(out, --indent); 62 out.println("</restrict-to>"); 63 } 64 65 protected void init(Element restriction) { 66 List conditionNodes = XMLUtil.getChildElements(restriction, "conditions"); 68 int length = conditionNodes.size(); 69 70 for (int i = 0; i < length; i++) { 71 Element condition = (Element ) conditionNodes.get(i); 72 ConditionsDescriptor conditionDescriptor = new ConditionsDescriptor(condition); 73 conditionDescriptor.setParent(this); 74 this.conditions.add(conditionDescriptor); 75 } 76 } 77 } 78 | Popular Tags |