1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.document; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.List; |
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.XmlElementWrapper; |
29 | |
import javax.xml.bind.annotation.XmlRootElement; |
30 | |
import javax.xml.bind.annotation.XmlType; |
31 | |
|
32 | |
import org.apache.commons.lang.StringUtils; |
33 | |
import org.kuali.rice.core.api.CoreConstants; |
34 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
35 | |
import org.w3c.dom.Element; |
36 | |
|
37 | |
@XmlRootElement(name = WorkflowAttributeDefinition.Constants.ROOT_ELEMENT_NAME) |
38 | |
@XmlAccessorType(XmlAccessType.NONE) |
39 | |
@XmlType(name = WorkflowAttributeDefinition.Constants.TYPE_NAME, propOrder = { |
40 | |
WorkflowAttributeDefinition.Elements.ATTRIBUTE_NAME, |
41 | |
WorkflowAttributeDefinition.Elements.PARAMETERS, |
42 | |
WorkflowAttributeDefinition.Elements.PROPERTY_DEFINITIONS, |
43 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
44 | |
}) |
45 | 0 | public final class WorkflowAttributeDefinition extends AbstractDataTransferObject { |
46 | |
|
47 | |
@XmlElement(name = Elements.ATTRIBUTE_NAME, required = true) |
48 | |
private final String attributeName; |
49 | |
|
50 | |
@XmlElementWrapper(name = Elements.PARAMETERS, required = false) |
51 | |
@XmlElement(name = Elements.PARAMETER, required = false) |
52 | |
private final List<String> parameters; |
53 | |
|
54 | |
@XmlElementWrapper(name = Elements.PROPERTY_DEFINITIONS, required = false) |
55 | |
@XmlElement(name = Elements.PROPERTY_DEFINITION, required = false) |
56 | |
private final List<PropertyDefinition> propertyDefinitions; |
57 | |
|
58 | 0 | @SuppressWarnings("unused") |
59 | |
@XmlAnyElement |
60 | |
private final Collection<Element> _futureElements = null; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | 0 | private WorkflowAttributeDefinition() { |
66 | 0 | this.attributeName = null; |
67 | 0 | this.parameters = null; |
68 | 0 | this.propertyDefinitions = null; |
69 | 0 | } |
70 | |
|
71 | 0 | private WorkflowAttributeDefinition(Builder builder) { |
72 | 0 | this.attributeName = builder.getAttributeName(); |
73 | 0 | if (builder.getParameters() == null) { |
74 | 0 | this.parameters = Collections.emptyList(); |
75 | |
} else { |
76 | 0 | this.parameters = new ArrayList<String>(builder.getParameters()); |
77 | |
} |
78 | 0 | if (builder.getPropertyDefinitions() == null) { |
79 | 0 | this.propertyDefinitions = Collections.emptyList(); |
80 | |
} else { |
81 | 0 | this.propertyDefinitions = new ArrayList<PropertyDefinition>(builder.getPropertyDefinitions()); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public String getAttributeName() { |
86 | 0 | return attributeName; |
87 | |
} |
88 | |
|
89 | |
public List<String> getParameters() { |
90 | 0 | return Collections.unmodifiableList(parameters); |
91 | |
} |
92 | |
|
93 | |
public List<PropertyDefinition> getPropertyDefinitions() { |
94 | 0 | return Collections.unmodifiableList(propertyDefinitions); |
95 | |
} |
96 | |
|
97 | |
public final static class Builder implements Serializable { |
98 | |
|
99 | |
private static final long serialVersionUID = 7549637048594326790L; |
100 | |
|
101 | |
private String attributeName; |
102 | |
private List<String> parameters; |
103 | |
private List<PropertyDefinition> propertyDefinitions; |
104 | |
|
105 | 0 | private Builder(String attributeName) { |
106 | 0 | setAttributeName(attributeName); |
107 | 0 | setParameters(new ArrayList<String>()); |
108 | 0 | setPropertyDefinitions(new ArrayList<PropertyDefinition>()); |
109 | 0 | } |
110 | |
|
111 | 0 | private Builder(WorkflowAttributeDefinition definition) { |
112 | 0 | setAttributeName(definition.getAttributeName()); |
113 | 0 | setParameters(definition.getParameters()); |
114 | 0 | setPropertyDefinitions(definition.getPropertyDefinitions()); |
115 | 0 | } |
116 | |
|
117 | |
public static Builder create(WorkflowAttributeDefinition definition) { |
118 | 0 | if (definition == null) { |
119 | 0 | throw new IllegalArgumentException("definition was null"); |
120 | |
} |
121 | 0 | return new Builder(definition); |
122 | |
} |
123 | |
|
124 | |
public static Builder create(String attributeName) { |
125 | 0 | return new Builder(attributeName); |
126 | |
|
127 | |
} |
128 | |
|
129 | |
public WorkflowAttributeDefinition build() { |
130 | 0 | return new WorkflowAttributeDefinition(this); |
131 | |
} |
132 | |
|
133 | |
public String getAttributeName() { |
134 | 0 | return attributeName; |
135 | |
} |
136 | |
|
137 | |
public List<String> getParameters() { |
138 | 0 | return parameters; |
139 | |
} |
140 | |
|
141 | |
public List<PropertyDefinition> getPropertyDefinitions() { |
142 | 0 | return propertyDefinitions; |
143 | |
} |
144 | |
|
145 | |
public void setAttributeName(String attributeName) { |
146 | 0 | if (StringUtils.isBlank(attributeName)) { |
147 | 0 | throw new IllegalArgumentException("attributeName was null or blank"); |
148 | |
} |
149 | 0 | this.attributeName = attributeName; |
150 | 0 | } |
151 | |
|
152 | |
public void addParameter(String parameter) { |
153 | 0 | parameters.add(parameter); |
154 | 0 | } |
155 | |
|
156 | |
public void removeParameter(String parameter) { |
157 | 0 | parameters.remove(parameter); |
158 | 0 | } |
159 | |
|
160 | |
public void setParameters(List<String> parameters) { |
161 | 0 | this.parameters = new ArrayList<String>(parameters); |
162 | 0 | } |
163 | |
|
164 | |
public void addPropertyDefinition(PropertyDefinition property) { |
165 | 0 | if (property == null) { |
166 | 0 | throw new IllegalArgumentException("Property definition must be non-null."); |
167 | |
} |
168 | 0 | propertyDefinitions.add(property); |
169 | 0 | } |
170 | |
|
171 | |
|
172 | |
public void setPropertyDefinitions(List<PropertyDefinition> propertyDefinitions) { |
173 | 0 | if (propertyDefinitions == null) { |
174 | 0 | throw new IllegalArgumentException("propertyDefinitions must not be null."); |
175 | |
} |
176 | 0 | this.propertyDefinitions = new ArrayList<PropertyDefinition>(propertyDefinitions); |
177 | |
|
178 | 0 | } |
179 | |
|
180 | |
public void addPropertyDefinition(String name, String value) { |
181 | 0 | addPropertyDefinition(PropertyDefinition.create(name, value)); |
182 | 0 | } |
183 | |
|
184 | |
public PropertyDefinition getPropertyDefinition(String name) { |
185 | 0 | if (StringUtils.isBlank(name)) { |
186 | 0 | throw new IllegalArgumentException("name was null or blank"); |
187 | |
} |
188 | 0 | for (PropertyDefinition propertyDefinition : propertyDefinitions) { |
189 | 0 | if (propertyDefinition.equals(name)) { |
190 | 0 | return propertyDefinition; |
191 | |
} |
192 | |
} |
193 | 0 | return null; |
194 | |
} |
195 | |
|
196 | |
|
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | 0 | static class Constants { |
203 | |
final static String ROOT_ELEMENT_NAME = "workflowAttributeDefinition"; |
204 | |
final static String TYPE_NAME = "WorkflowAttributeDefinitionType"; |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | 0 | static class Elements { |
211 | |
final static String ATTRIBUTE_NAME = "attributeName"; |
212 | |
final static String PARAMETERS = "parameters"; |
213 | |
final static String PARAMETER = "parameter"; |
214 | |
final static String PROPERTY_DEFINITIONS = "propertyDefinitions"; |
215 | |
final static String PROPERTY_DEFINITION = "propertyDefinition"; |
216 | |
} |
217 | |
|
218 | |
} |