KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
20  * @version $Revision: 1.5 $
21  */

22 public class RestrictionDescriptor extends AbstractDescriptor implements Validatable {
23     //~ Instance fields ////////////////////////////////////////////////////////
24

25     protected List JavaDoc conditions = new ArrayList JavaDoc();
26
27     //~ Constructors ///////////////////////////////////////////////////////////
28

29     public RestrictionDescriptor() {
30     }
31
32     public RestrictionDescriptor(Element JavaDoc restriction) {
33         init(restriction);
34     }
35
36     //~ Methods ////////////////////////////////////////////////////////////////
37

38     public List JavaDoc getConditions() {
39         return conditions;
40     }
41
42     public void validate() throws InvalidWorkflowDescriptorException {
43         ValidationHelper.validate(conditions);
44     }
45
46     public void writeXML(PrintWriter JavaDoc out, int indent) {
47         if (conditions.size() == 0) {
48             return;
49         }
50
51         XMLUtil.printIndent(out, indent++);
52         out.println("<restrict-to>");
53
54         if (conditions.size() > 0) {
55             for (int i = 0; i < conditions.size(); i++) {
56                 ConditionsDescriptor condition = (ConditionsDescriptor) conditions.get(i);
57                 condition.writeXML(out, indent);
58             }
59         }
60
61         XMLUtil.printIndent(out, --indent);
62         out.println("</restrict-to>");
63     }
64
65     protected void init(Element JavaDoc restriction) {
66         // set up condition - OPTIONAL
67
List JavaDoc conditionNodes = XMLUtil.getChildElements(restriction, "conditions");
68         int length = conditionNodes.size();
69
70         for (int i = 0; i < length; i++) {
71             Element JavaDoc condition = (Element JavaDoc) conditionNodes.get(i);
72             ConditionsDescriptor conditionDescriptor = new ConditionsDescriptor(condition);
73             conditionDescriptor.setParent(this);
74             this.conditions.add(conditionDescriptor);
75         }
76     }
77 }
78
Popular Tags