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 RegisterDescriptor extends AbstractDescriptor { 20 22 protected Map args = new HashMap(); 23 protected String type; 24 protected String variableName; 25 26 28 public RegisterDescriptor() { 29 } 30 31 public RegisterDescriptor(Element register) { 32 init(register); 33 } 34 35 37 public Map getArgs() { 38 return args; 39 } 40 41 public void setType(String type) { 42 this.type = type; 43 } 44 45 public String getType() { 46 return type; 47 } 48 49 public void setVariableName(String variableName) { 50 this.variableName = variableName; 51 } 52 53 public String getVariableName() { 54 return variableName; 55 } 56 57 public void writeXML(PrintWriter out, int indent) { 58 XMLUtil.printIndent(out, indent++); 59 out.println("<register " + (hasId() ? ("id=\"" + getId() + "\" ") : "") + "type=\"" + type + "\" variable-name=\"" + variableName + "\">"); 60 61 Iterator iter = args.entrySet().iterator(); 62 63 while (iter.hasNext()) { 64 Map.Entry entry = (Map.Entry) iter.next(); 65 XMLUtil.printIndent(out, indent); 66 out.print("<arg name=\""); 67 out.print(entry.getKey()); 68 out.print("\">"); 69 70 if ("beanshell".equals(type) || "bsf".equals(type)) { 71 out.print("<![CDATA["); 72 out.print(entry.getValue()); 73 out.print("]]>"); 74 } else { 75 out.print(XMLUtil.encode(entry.getValue())); 76 } 77 78 out.println("</arg>"); 79 } 80 81 XMLUtil.printIndent(out, --indent); 82 out.println("</register>"); 83 } 84 85 protected void init(Element register) { 86 this.type = register.getAttribute("type"); 87 this.variableName = register.getAttribute("variable-name"); 88 89 try { 90 setId(Integer.parseInt(register.getAttribute("id"))); 91 } catch (NumberFormatException e) { 92 } 93 94 List args = XMLUtil.getChildElements(register, "arg"); 95 96 for (int l = 0; l < args.size(); l++) { 97 Element arg = (Element ) args.get(l); 98 this.args.put(arg.getAttribute("name"), XMLUtil.getText(arg)); 99 } 100 } 101 } 102 | Popular Tags |