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 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 @SuppressWarnings("unused")
50 @XmlAnyElement
51 private final Collection<Element> _futureElements = null;
52
53
54
55
56 private ValidActions() {
57 this.validActionCodes = null;
58 }
59
60 private ValidActions(Builder builder) {
61 Set<ActionType> validActions = builder.getValidActions();
62 Set<String> validActionCodes = new HashSet<String>();
63 for (ActionType actionType : validActions) {
64 validActionCodes.add(actionType.getCode());
65 }
66 this.validActionCodes = validActionCodes;
67 }
68
69 public Set<ActionType> getValidActions() {
70 if (validActionCodes == null) {
71 return Collections.emptySet();
72 }
73 Set<ActionType> validActions = new HashSet<ActionType>();
74 for (String validActionCode : validActionCodes) {
75
76 ActionType actionType = ActionType.fromCode(validActionCode, true);
77 if (actionType != null) {
78 validActions.add(actionType);
79 }
80 }
81 return Collections.unmodifiableSet(validActions);
82 }
83
84
85
86
87 public final static class Builder implements Serializable, ModelBuilder {
88
89 private static final long serialVersionUID = -3227993220281961077L;
90
91 private Set<ActionType> validActions;
92
93 private Builder() {
94 setValidActions(new HashSet<ActionType>());
95 }
96
97 public static Builder create() {
98 return new Builder();
99 }
100
101 public ValidActions build() {
102 return new ValidActions(this);
103 }
104
105 public Set<ActionType> getValidActions() {
106 return this.validActions;
107 }
108
109 public void setValidActions(Set<ActionType> validActions) {
110 if (validActions == null) {
111 throw new IllegalArgumentException("validActions was null");
112 }
113 this.validActions = new HashSet<ActionType>(validActions);
114 }
115
116 public void addValidAction(ActionType validAction) {
117 if (validAction == null) {
118 throw new IllegalArgumentException("validAction was null");
119 }
120 validActions.add(validAction);
121 }
122
123 }
124
125
126
127
128 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 static class Elements {
138 final static String VALID_ACTION_CODES = "validActionCodes";
139 final static String VALID_ACTION_CODE = "validActionCode";
140 }
141
142 }
143