001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow.loader;
006:
007: import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
008: import com.opensymphony.workflow.util.Validatable;
009:
010: import org.w3c.dom.Element;
011:
012: import java.io.PrintWriter;
013:
014: import java.util.ArrayList;
015: import java.util.List;
016:
017: /**
018: * DOCUMENT ME!
019: */
020: public class JoinDescriptor extends AbstractDescriptor implements
021: Validatable {
022: //~ Instance fields ////////////////////////////////////////////////////////
023:
024: protected List conditions = new ArrayList();
025: protected ResultDescriptor result;
026:
027: //~ Constructors ///////////////////////////////////////////////////////////
028:
029: /**
030: * @deprecated use {@link DescriptorFactory} instead
031: */
032: JoinDescriptor() {
033: }
034:
035: /**
036: * @deprecated use {@link DescriptorFactory} instead
037: */
038: JoinDescriptor(Element join) {
039: init(join);
040: }
041:
042: //~ Methods ////////////////////////////////////////////////////////////////
043:
044: public List getConditions() {
045: return conditions;
046: }
047:
048: public void setResult(ResultDescriptor result) {
049: this .result = result;
050: }
051:
052: public ResultDescriptor getResult() {
053: return result;
054: }
055:
056: public void validate() throws InvalidWorkflowDescriptorException {
057: ValidationHelper.validate(conditions);
058:
059: if (result == null) {
060: throw new InvalidWorkflowDescriptorException(
061: "Join has no result");
062: }
063:
064: result.validate();
065: }
066:
067: public void writeXML(PrintWriter out, int indent) {
068: XMLUtil.printIndent(out, indent++);
069: out.println("<join id=\"" + getId() + "\">");
070:
071: if (conditions.size() > 0) {
072: for (int i = 0; i < conditions.size(); i++) {
073: ConditionsDescriptor condition = (ConditionsDescriptor) conditions
074: .get(i);
075: condition.writeXML(out, indent);
076: }
077: }
078:
079: if (result != null) {
080: result.writeXML(out, indent);
081: }
082:
083: XMLUtil.printIndent(out, --indent);
084: out.println("</join>");
085: }
086:
087: protected void init(Element join) {
088: try {
089: setId(Integer.parseInt(join.getAttribute("id")));
090: } catch (Exception ex) {
091: throw new IllegalArgumentException("Invalid join id value "
092: + join.getAttribute("id"));
093: }
094:
095: // get conditions
096: List conditionNodes = XMLUtil.getChildElements(join,
097: "conditions");
098: int length = conditionNodes.size();
099:
100: for (int i = 0; i < length; i++) {
101: Element condition = (Element) conditionNodes.get(i);
102: ConditionsDescriptor conditionDescriptor = DescriptorFactory
103: .getFactory().createConditionsDescriptor(condition);
104: conditionDescriptor.setParent(this );
105: this .conditions.add(conditionDescriptor);
106: }
107:
108: //<unconditional-result status="Underway" owner="test" step="2"/>
109: Element resultElement = XMLUtil.getChildElement(join,
110: "unconditional-result");
111:
112: // [KAP] This allows loading a workflow with Joins without unconditional-results
113: if (resultElement != null) {
114: result = new ResultDescriptor(resultElement);
115: result.setParent(this);
116: }
117: }
118: }
|