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