KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > loader > RegisterDescriptor


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.loader;
6
7 import org.w3c.dom.Element JavaDoc;
8 import org.w3c.dom.NodeList JavaDoc;
9
10 import java.io.PrintWriter JavaDoc;
11
12 import java.util.*;
13
14
15 /**
16  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
17  * @version $Revision: 1.4 $
18  */

19 public class RegisterDescriptor extends AbstractDescriptor {
20     //~ Instance fields ////////////////////////////////////////////////////////
21

22     protected Map args = new HashMap();
23     protected String JavaDoc type;
24     protected String JavaDoc variableName;
25
26     //~ Constructors ///////////////////////////////////////////////////////////
27

28     public RegisterDescriptor() {
29     }
30
31     public RegisterDescriptor(Element JavaDoc register) {
32         init(register);
33     }
34
35     //~ Methods ////////////////////////////////////////////////////////////////
36

37     public Map getArgs() {
38         return args;
39     }
40
41     public void setType(String JavaDoc type) {
42         this.type = type;
43     }
44
45     public String JavaDoc getType() {
46         return type;
47     }
48
49     public void setVariableName(String JavaDoc variableName) {
50         this.variableName = variableName;
51     }
52
53     public String JavaDoc getVariableName() {
54         return variableName;
55     }
56
57     public void writeXML(PrintWriter JavaDoc 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 JavaDoc 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 JavaDoc e) {
92         }
93
94         List JavaDoc args = XMLUtil.getChildElements(register, "arg");
95
96         for (int l = 0; l < args.size(); l++) {
97             Element JavaDoc arg = (Element JavaDoc) args.get(l);
98             this.args.put(arg.getAttribute("name"), XMLUtil.getText(arg));
99         }
100     }
101 }
102
Popular Tags