1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.action; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.HashSet; |
22 | |
import java.util.Set; |
23 | |
|
24 | |
import javax.xml.bind.annotation.XmlAccessType; |
25 | |
import javax.xml.bind.annotation.XmlAccessorType; |
26 | |
import javax.xml.bind.annotation.XmlAnyElement; |
27 | |
import javax.xml.bind.annotation.XmlElement; |
28 | |
import javax.xml.bind.annotation.XmlRootElement; |
29 | |
import javax.xml.bind.annotation.XmlType; |
30 | |
|
31 | |
import org.kuali.rice.core.api.CoreConstants; |
32 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
33 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
34 | |
import org.w3c.dom.Element; |
35 | |
|
36 | |
@XmlRootElement(name = ValidActions.Constants.ROOT_ELEMENT_NAME) |
37 | |
@XmlAccessorType(XmlAccessType.NONE) |
38 | |
@XmlType(name = ValidActions.Constants.TYPE_NAME, propOrder = { |
39 | |
ValidActions.Elements.VALID_ACTION_CODES, |
40 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
41 | |
}) |
42 | 0 | public final class ValidActions extends AbstractDataTransferObject { |
43 | |
|
44 | |
private static final long serialVersionUID = 8074175291030982905L; |
45 | |
|
46 | |
@XmlElement(name = Elements.VALID_ACTION_CODE, required = false) |
47 | |
private final Set<String> validActionCodes; |
48 | |
|
49 | 0 | @SuppressWarnings("unused") |
50 | |
@XmlAnyElement |
51 | |
private final Collection<Element> _futureElements = null; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | 0 | private ValidActions() { |
57 | 0 | this.validActionCodes = null; |
58 | 0 | } |
59 | |
|
60 | 0 | private ValidActions(Builder builder) { |
61 | 0 | Set<ActionType> validActions = builder.getValidActions(); |
62 | 0 | Set<String> validActionCodes = new HashSet<String>(); |
63 | 0 | for (ActionType actionType : validActions) { |
64 | 0 | validActionCodes.add(actionType.getCode()); |
65 | |
} |
66 | 0 | this.validActionCodes = validActionCodes; |
67 | 0 | } |
68 | |
|
69 | |
public Set<ActionType> getValidActions() { |
70 | 0 | if (validActionCodes == null) { |
71 | 0 | return Collections.emptySet(); |
72 | |
} |
73 | 0 | Set<ActionType> validActions = new HashSet<ActionType>(); |
74 | 0 | for (String validActionCode : validActionCodes) { |
75 | |
|
76 | 0 | ActionType actionType = ActionType.fromCode(validActionCode, true); |
77 | 0 | if (actionType != null) { |
78 | 0 | validActions.add(actionType); |
79 | |
} |
80 | 0 | } |
81 | 0 | return Collections.unmodifiableSet(validActions); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | 0 | public final static class Builder implements Serializable, ModelBuilder { |
88 | |
|
89 | |
private static final long serialVersionUID = -3227993220281961077L; |
90 | |
|
91 | |
private Set<ActionType> validActions; |
92 | |
|
93 | 0 | private Builder() { |
94 | 0 | setValidActions(new HashSet<ActionType>()); |
95 | 0 | } |
96 | |
|
97 | |
public static Builder create() { |
98 | 0 | return new Builder(); |
99 | |
} |
100 | |
|
101 | |
public ValidActions build() { |
102 | 0 | return new ValidActions(this); |
103 | |
} |
104 | |
|
105 | |
public Set<ActionType> getValidActions() { |
106 | 0 | return this.validActions; |
107 | |
} |
108 | |
|
109 | |
public void setValidActions(Set<ActionType> validActions) { |
110 | 0 | if (validActions == null) { |
111 | 0 | throw new IllegalArgumentException("validActions was null"); |
112 | |
} |
113 | 0 | this.validActions = new HashSet<ActionType>(validActions); |
114 | 0 | } |
115 | |
|
116 | |
public void addValidAction(ActionType validAction) { |
117 | 0 | if (validAction == null) { |
118 | 0 | throw new IllegalArgumentException("validAction was null"); |
119 | |
} |
120 | 0 | validActions.add(validAction); |
121 | 0 | } |
122 | |
|
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | 0 | static class Constants { |
129 | |
final static String ROOT_ELEMENT_NAME = "validActions"; |
130 | |
final static String TYPE_NAME = "ValidActionsType"; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | 0 | static class Elements { |
138 | |
final static String VALID_ACTION_CODES = "validActionCodes"; |
139 | |
final static String VALID_ACTION_CODE = "validActionCode"; |
140 | |
} |
141 | |
|
142 | |
} |
143 | |
|