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