1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.launcher.types;
19
20 import java.util.ArrayList;
21 import java.util.Stack;
22 import org.apache.commons.launcher.Launcher;
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.types.DataType;
25 import org.apache.tools.ant.types.Reference;
26
27
28
29
30
31
32
33 public class ConditionalVariableSet extends DataType {
34
35
36
37
38
39
40 private ArrayList list = new ArrayList();
41
42
43
44
45
46
47
48
49
50 protected void addConditionalvariable(ConditionalVariable variable) {
51
52 if (isReference())
53 throw noChildrenAllowed();
54 list.add(variable);
55
56 }
57
58
59
60
61
62
63 protected void addConditionalvariableset(ConditionalVariableSet set) {
64
65 if (isReference())
66 throw noChildrenAllowed();
67 list.add(set);
68
69 }
70
71
72
73
74
75
76 public ArrayList getList() {
77
78
79 if (!checked) {
80 Stack stk = new Stack();
81 stk.push(this);
82 dieOnCircularReference(stk, project);
83 }
84
85
86
87 ArrayList mergedList = new ArrayList(list.size());
88 for (int i = 0; i < list.size(); i++) {
89 Object o = list.get(i);
90 ConditionalVariableSet nestedSet = null;
91 if (o instanceof Reference) {
92 o = ((Reference)o).getReferencedObject(project);
93
94 if (!o.getClass().isInstance(this))
95 throw new BuildException(Launcher.getLocalizedString("cannot.reference", this.getClass().getName()));
96 nestedSet = (ConditionalVariableSet)o;
97 } else if (o.getClass().isInstance(this)) {
98 nestedSet = (ConditionalVariableSet)o;
99 } else if (o instanceof ConditionalVariable) {
100 mergedList.add(o);
101 } else {
102 throw new BuildException(Launcher.getLocalizedString("cannot.nest", this.getClass().getName()));
103 }
104 if (nestedSet != null)
105 mergedList.addAll(nestedSet.getList());
106 }
107
108 return mergedList;
109
110 }
111
112
113
114
115
116
117
118
119
120 public void setRefid(Reference r) throws BuildException {
121
122 if (!list.isEmpty())
123 throw tooManyAttributes();
124 list.add(r);
125 super.setRefid(r);
126
127 }
128
129 }