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.*; 15 16 17 23 public class ConditionDescriptor extends AbstractDescriptor implements Validatable { 24 26 protected Map args = new HashMap(); 27 28 31 protected String name; 32 protected String type; 33 protected boolean negate = false; 34 35 37 public ConditionDescriptor() { 38 } 39 40 public ConditionDescriptor(Element function) { 41 init(function); 42 } 43 44 46 public Map getArgs() { 47 return args; 48 } 49 50 public void setName(String name) { 51 this.name = name; 52 } 53 54 public String getName() { 55 return name; 56 } 57 58 public void setNegate(boolean negate) { 59 this.negate = negate; 60 } 61 62 public boolean isNegate() { 63 return negate; 64 } 65 66 public void setType(String type) { 67 this.type = type; 68 } 69 70 public String getType() { 71 return type; 72 } 73 74 public void validate() throws InvalidWorkflowDescriptorException { 75 } 76 77 public void writeXML(PrintWriter out, int indent) { 78 XMLUtil.printIndent(out, indent++); 79 out.println("<condition " + (hasId() ? ("id=\"" + getId() + "\" ") : "") + (((name != null) && (name.length() > 0)) ? ("name=\"" + getName() + "\" ") : "") + (negate ? ("negate=\"true\" ") : "") + "type=\"" + type + "\">"); 80 81 Iterator iter = args.entrySet().iterator(); 82 83 while (iter.hasNext()) { 84 Map.Entry entry = (Map.Entry) iter.next(); 85 XMLUtil.printIndent(out, indent); 86 out.print("<arg name=\""); 87 out.print(entry.getKey()); 88 out.print("\">"); 89 90 if ("beanshell".equals(type) || "bsf".equals(type)) { 91 out.print("<![CDATA["); 92 out.print(entry.getValue()); 93 out.print("]]>"); 94 } else { 95 out.print(XMLUtil.encode(entry.getValue())); 96 } 97 98 out.println("</arg>"); 99 } 100 101 XMLUtil.printIndent(out, --indent); 102 out.println("</condition>"); 103 } 104 105 protected void init(Element condition) { 106 type = condition.getAttribute("type"); 107 108 try { 109 setId(Integer.parseInt(condition.getAttribute("id"))); 110 } catch (NumberFormatException e) { 111 } 112 113 String n = condition.getAttribute("negate"); 114 115 if ("true".equalsIgnoreCase(n) || "yes".equalsIgnoreCase(n)) { 116 negate = true; 117 } else { 118 negate = false; 119 } 120 121 if (condition.getAttribute("name") != null) { 122 name = condition.getAttribute("name"); 123 } 124 125 List args = XMLUtil.getChildElements(condition, "arg"); 126 127 for (int l = 0; l < args.size(); l++) { 128 Element arg = (Element ) args.get(l); 129 this.args.put(arg.getAttribute("name"), XMLUtil.getText(arg)); 130 } 131 } 132 } 133 | Popular Tags |