KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package com.opensymphony.workflow.loader;
6
7 import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
8 import com.opensymphony.workflow.util.Validatable;
9
10 import org.w3c.dom.Element JavaDoc;
11
12 import java.io.PrintWriter JavaDoc;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17
18 /**
19  * DOCUMENT ME!
20  *
21  * @author $author$
22  * @version $Revision: 1.5 $
23  */

24 public class JoinDescriptor extends AbstractDescriptor implements Validatable {
25     //~ Instance fields ////////////////////////////////////////////////////////
26

27     protected List JavaDoc conditions = new ArrayList JavaDoc();
28     protected ResultDescriptor result;
29
30     //~ Constructors ///////////////////////////////////////////////////////////
31

32     public JoinDescriptor() {
33     }
34
35     public JoinDescriptor(Element JavaDoc join) {
36         init(join);
37     }
38
39     //~ Methods ////////////////////////////////////////////////////////////////
40

41     public List JavaDoc getConditions() {
42         return conditions;
43     }
44
45     public void setResult(ResultDescriptor result) {
46         this.result = result;
47     }
48
49     public ResultDescriptor getResult() {
50         return result;
51     }
52
53     public void validate() throws InvalidWorkflowDescriptorException {
54         ValidationHelper.validate(conditions);
55
56         if (result == null) {
57             throw new InvalidWorkflowDescriptorException("Join has no result");
58         }
59
60         result.validate();
61     }
62
63     public void writeXML(PrintWriter JavaDoc out, int indent) {
64         XMLUtil.printIndent(out, indent++);
65         out.println("<join id=\"" + getId() + "\">");
66
67         if (conditions.size() > 0) {
68             for (int i = 0; i < conditions.size(); i++) {
69                 ConditionsDescriptor condition = (ConditionsDescriptor) conditions.get(i);
70                 condition.writeXML(out, indent);
71             }
72         }
73
74         result.writeXML(out, indent);
75         XMLUtil.printIndent(out, --indent);
76         out.println("</join>");
77     }
78
79     protected void init(Element JavaDoc join) {
80         try {
81             setId(Integer.parseInt(join.getAttribute("id")));
82         } catch (Exception JavaDoc ex) {
83             throw new IllegalArgumentException JavaDoc("Invalid join id value " + join.getAttribute("id"));
84         }
85
86         // get conditions
87
List JavaDoc conditionNodes = XMLUtil.getChildElements(join, "conditions");
88         int length = conditionNodes.size();
89
90         for (int i = 0; i < length; i++) {
91             Element JavaDoc condition = (Element JavaDoc) conditionNodes.get(i);
92             ConditionsDescriptor conditionDescriptor = new ConditionsDescriptor(condition);
93             conditionDescriptor.setParent(this);
94             this.conditions.add(conditionDescriptor);
95         }
96
97         //<unconditional-result status="Underway" owner="test" step="2"/>
98
Element JavaDoc resultElement = XMLUtil.getChildElement(join, "unconditional-result");
99         result = new ResultDescriptor(resultElement);
100         result.setParent(this);
101     }
102 }
103
Popular Tags