01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.loader;
06:
07: import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
08: import com.opensymphony.workflow.util.Validatable;
09:
10: import org.w3c.dom.Element;
11:
12: import java.io.PrintWriter;
13:
14: import java.util.ArrayList;
15: import java.util.List;
16:
17: /**
18: * DOCUMENT ME!
19: *
20: * @author $author$
21: */
22: public class SplitDescriptor extends AbstractDescriptor implements
23: Validatable {
24: //~ Instance fields ////////////////////////////////////////////////////////
25:
26: protected List results = new ArrayList();
27:
28: //~ Constructors ///////////////////////////////////////////////////////////
29:
30: /**
31: * @deprecated use {@link DescriptorFactory} instead
32: */
33: SplitDescriptor() {
34: }
35:
36: /**
37: * @deprecated use {@link DescriptorFactory} instead
38: */
39: SplitDescriptor(Element split) {
40: init(split);
41: }
42:
43: //~ Methods ////////////////////////////////////////////////////////////////
44:
45: public List getResults() {
46: return results;
47: }
48:
49: public void validate() throws InvalidWorkflowDescriptorException {
50: ValidationHelper.validate(results);
51: }
52:
53: public void writeXML(PrintWriter out, int indent) {
54: XMLUtil.printIndent(out, indent++);
55: out.println("<split id=\"" + getId() + "\">");
56:
57: for (int i = 0; i < results.size(); i++) {
58: ResultDescriptor result = (ResultDescriptor) results.get(i);
59: result.writeXML(out, indent);
60: }
61:
62: XMLUtil.printIndent(out, --indent);
63: out.println("</split>");
64: }
65:
66: private void init(Element split) {
67: try {
68: setId(Integer.parseInt(split.getAttribute("id")));
69: } catch (Exception ex) {
70: throw new IllegalArgumentException(
71: "Invalid split id value "
72: + split.getAttribute("id"));
73: }
74:
75: List uResults = XMLUtil.getChildElements(split,
76: "unconditional-result");
77:
78: for (int i = 0; i < uResults.size(); i++) {
79: Element result = (Element) uResults.get(i);
80: ResultDescriptor resultDescriptor = new ResultDescriptor(
81: result);
82: resultDescriptor.setParent(this);
83: results.add(resultDescriptor);
84: }
85: }
86: }
|