1 5 package com.opensymphony.workflow.loader; 6 7 import org.w3c.dom.Element ; 8 import org.w3c.dom.NodeList ; 9 10 import java.io.PrintWriter ; 11 12 import java.util.*; 13 14 15 19 public class ValidatorDescriptor extends AbstractDescriptor { 20 22 protected Map args = new HashMap(); 23 protected String type; 24 25 27 public ValidatorDescriptor() { 28 } 29 30 public ValidatorDescriptor(Element validator) { 31 init(validator); 32 } 33 34 36 public Map getArgs() { 37 return args; 38 } 39 40 public void setType(String type) { 41 this.type = type; 42 } 43 44 public String getType() { 45 return type; 46 } 47 48 public void writeXML(PrintWriter out, int indent) { 49 XMLUtil.printIndent(out, indent++); 50 out.println("<validator " + (hasId() ? ("id=\"" + getId() + "\" ") : "") + "type=\"" + type + "\">"); 51 52 Iterator iter = args.entrySet().iterator(); 53 54 while (iter.hasNext()) { 55 Map.Entry entry = (Map.Entry) iter.next(); 56 XMLUtil.printIndent(out, indent); 57 out.print("<arg name=\""); 58 out.print(entry.getKey()); 59 out.print("\">"); 60 61 if ("beanshell".equals(type) || "bsf".equals(type)) { 62 out.print("<![CDATA["); 63 out.print(entry.getValue()); 64 out.print("]]>"); 65 } else { 66 out.print(XMLUtil.encode(entry.getValue())); 67 } 68 69 out.println("</arg>"); 70 } 71 72 XMLUtil.printIndent(out, --indent); 73 out.println("</validator>"); 74 } 75 76 protected void init(Element validator) { 77 type = validator.getAttribute("type"); 78 79 try { 80 setId(Integer.parseInt(validator.getAttribute("id"))); 81 } catch (NumberFormatException e) { 82 } 83 84 this.args = new HashMap(); 85 86 List args = XMLUtil.getChildElements(validator, "arg"); 87 88 for (int l = 0; l < args.size(); l++) { 89 Element arg = (Element ) args.get(l); 90 this.args.put(arg.getAttribute("name"), XMLUtil.getText(arg)); 91 } 92 } 93 } 94 | Popular Tags |