KickJava   Java API By Example, From Geeks To Geeks.

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


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 ValidatorDescriptor extends AbstractDescriptor {
20     //~ Instance fields ////////////////////////////////////////////////////////
21

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

27     public ValidatorDescriptor() {
28     }
29
30     public ValidatorDescriptor(Element JavaDoc validator) {
31         init(validator);
32     }
33
34     //~ Methods ////////////////////////////////////////////////////////////////
35

36     public Map getArgs() {
37         return args;
38     }
39
40     public void setType(String JavaDoc type) {
41         this.type = type;
42     }
43
44     public String JavaDoc getType() {
45         return type;
46     }
47
48     public void writeXML(PrintWriter JavaDoc 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 JavaDoc validator) {
77         type = validator.getAttribute("type");
78
79         try {
80             setId(Integer.parseInt(validator.getAttribute("id")));
81         } catch (NumberFormatException JavaDoc e) {
82         }
83
84         this.args = new HashMap();
85
86         List JavaDoc args = XMLUtil.getChildElements(validator, "arg");
87
88         for (int l = 0; l < args.size(); l++) {
89             Element JavaDoc arg = (Element JavaDoc) args.get(l);
90             this.args.put(arg.getAttribute("name"), XMLUtil.getText(arg));
91         }
92     }
93 }
94
Popular Tags