KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.w3c.dom.NodeList JavaDoc;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18
19 /**
20  * DOCUMENT ME!
21  *
22  * @author $author$
23  * @version $Revision: 1.3 $
24  */

25 public class SplitDescriptor extends AbstractDescriptor implements Validatable {
26     //~ Instance fields ////////////////////////////////////////////////////////
27

28     protected List JavaDoc results = new ArrayList JavaDoc();
29
30     //~ Constructors ///////////////////////////////////////////////////////////
31

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

41     public List JavaDoc getResults() {
42         return results;
43     }
44
45     public void validate() throws InvalidWorkflowDescriptorException {
46         ValidationHelper.validate(results);
47     }
48
49     public void writeXML(PrintWriter JavaDoc out, int indent) {
50         XMLUtil.printIndent(out, indent++);
51         out.println("<split id=\"" + getId() + "\">");
52
53         for (int i = 0; i < results.size(); i++) {
54             ResultDescriptor result = (ResultDescriptor) results.get(i);
55             result.writeXML(out, indent);
56         }
57
58         XMLUtil.printIndent(out, --indent);
59         out.println("</split>");
60     }
61
62     private void init(Element JavaDoc split) {
63         try {
64             setId(Integer.parseInt(split.getAttribute("id")));
65         } catch (Exception JavaDoc ex) {
66             throw new IllegalArgumentException JavaDoc("Invalid split id value " + split.getAttribute("id"));
67         }
68
69         List JavaDoc uResults = XMLUtil.getChildElements(split, "unconditional-result");
70
71         for (int i = 0; i < uResults.size(); i++) {
72             Element JavaDoc result = (Element JavaDoc) uResults.get(i);
73             ResultDescriptor resultDescriptor = new ResultDescriptor(result);
74             resultDescriptor.setParent(this);
75             results.add(resultDescriptor);
76         }
77     }
78 }
79
Popular Tags