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