001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow.loader;
006:
007: import org.w3c.dom.Element;
008: import org.w3c.dom.NodeList;
009:
010: import java.io.PrintWriter;
011:
012: import java.util.*;
013:
014: /**
015: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
016: */
017: public class RegisterDescriptor extends AbstractDescriptor {
018: //~ Instance fields ////////////////////////////////////////////////////////
019:
020: protected Map args = new HashMap();
021: protected String type;
022: protected String variableName;
023:
024: //~ Constructors ///////////////////////////////////////////////////////////
025:
026: /**
027: * @deprecated use {@link DescriptorFactory} instead
028: */
029: RegisterDescriptor() {
030: }
031:
032: /**
033: * @deprecated use {@link DescriptorFactory} instead
034: */
035: RegisterDescriptor(Element register) {
036: init(register);
037: }
038:
039: //~ Methods ////////////////////////////////////////////////////////////////
040:
041: public Map getArgs() {
042: return args;
043: }
044:
045: public void setType(String type) {
046: this .type = type;
047: }
048:
049: public String getType() {
050: return type;
051: }
052:
053: public void setVariableName(String variableName) {
054: this .variableName = variableName;
055: }
056:
057: public String getVariableName() {
058: return variableName;
059: }
060:
061: public void writeXML(PrintWriter out, int indent) {
062: XMLUtil.printIndent(out, indent++);
063: out.println("<register "
064: + (hasId() ? ("id=\"" + getId() + "\" ") : "")
065: + "type=\"" + type + "\" variable-name=\""
066: + variableName + "\">");
067:
068: Iterator iter = args.entrySet().iterator();
069:
070: while (iter.hasNext()) {
071: Map.Entry entry = (Map.Entry) iter.next();
072: XMLUtil.printIndent(out, indent);
073: out.print("<arg name=\"");
074: out.print(entry.getKey());
075: out.print("\">");
076:
077: if ("beanshell".equals(type) || "bsf".equals(type)) {
078: out.print("<![CDATA[");
079: out.print(entry.getValue());
080: out.print("]]>");
081: } else {
082: out.print(XMLUtil.encode(entry.getValue()));
083: }
084:
085: out.println("</arg>");
086: }
087:
088: XMLUtil.printIndent(out, --indent);
089: out.println("</register>");
090: }
091:
092: protected void init(Element register) {
093: this .type = register.getAttribute("type");
094: this .variableName = register.getAttribute("variable-name");
095:
096: try {
097: setId(Integer.parseInt(register.getAttribute("id")));
098: } catch (NumberFormatException e) {
099: }
100:
101: List args = XMLUtil.getChildElements(register, "arg");
102:
103: for (int l = 0; l < args.size(); l++) {
104: Element arg = (Element) args.get(l);
105: this .args.put(arg.getAttribute("name"), XMLUtil
106: .getText(arg));
107: }
108: }
109: }
|