1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.validation; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.kuali.rice.core.api.CoreConstants; |
20 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
22 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
23 | |
import org.kuali.rice.kew.api.rule.RuleContract; |
24 | |
import org.kuali.rice.kew.api.rule.RuleDelegationContract; |
25 | |
import org.kuali.rice.kew.api.rule.RuleResponsibility; |
26 | |
import org.kuali.rice.kew.api.rule.RuleResponsibilityContract; |
27 | |
import org.w3c.dom.Element; |
28 | |
|
29 | |
import javax.xml.bind.annotation.XmlAccessType; |
30 | |
import javax.xml.bind.annotation.XmlAccessorType; |
31 | |
import javax.xml.bind.annotation.XmlAnyElement; |
32 | |
import javax.xml.bind.annotation.XmlElement; |
33 | |
import javax.xml.bind.annotation.XmlRootElement; |
34 | |
import javax.xml.bind.annotation.XmlType; |
35 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
36 | |
import java.io.Serializable; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Collection; |
39 | |
import java.util.Collections; |
40 | |
import java.util.HashMap; |
41 | |
import java.util.List; |
42 | |
import java.util.Map; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@XmlRootElement(name = ValidationResults.Constants.ROOT_ELEMENT_NAME) |
50 | |
@XmlAccessorType(XmlAccessType.NONE) |
51 | |
@XmlType(name = ValidationResults.Constants.TYPE_NAME, propOrder = { |
52 | |
ValidationResults.Elements.ERRORS, |
53 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
54 | |
}) |
55 | 0 | public class ValidationResults |
56 | |
extends AbstractDataTransferObject |
57 | |
implements ValidationResultsContract { |
58 | |
|
59 | |
public static final String GLOBAL = "org.kuali.rice.kew.api.validation.ValidationResults.GLOBAL"; |
60 | |
|
61 | |
@XmlElement(name = Elements.ERRORS, required = false) |
62 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
63 | |
private final Map<String, String> errors; |
64 | |
|
65 | 0 | @SuppressWarnings("unused") |
66 | |
@XmlAnyElement |
67 | |
private final Collection<Element> _futureElements = null; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | 0 | private ValidationResults() { |
73 | 0 | this.errors = Collections.emptyMap(); |
74 | 0 | } |
75 | |
|
76 | 0 | private ValidationResults(Builder builder) { |
77 | 0 | this.errors = Collections.unmodifiableMap(builder.getErrors()); |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
public Map<String, String> getErrors() { |
82 | 0 | return errors; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | public final static class Builder |
90 | |
implements Serializable, ModelBuilder, ValidationResultsContract |
91 | |
{ |
92 | |
|
93 | 0 | private Map<String, String> errors = new HashMap<String, String>(); |
94 | |
|
95 | 0 | private Builder() { |
96 | 0 | } |
97 | |
|
98 | |
public static Builder create() { |
99 | 0 | return new Builder(); |
100 | |
} |
101 | |
|
102 | |
public static Builder create(ValidationResultsContract contract) { |
103 | 0 | if (contract == null) { |
104 | 0 | throw new IllegalArgumentException("contract was null"); |
105 | |
} |
106 | 0 | Builder builder = create(); |
107 | 0 | if (contract.getErrors() != null) { |
108 | 0 | builder.setErrors(contract.getErrors()); |
109 | |
} |
110 | 0 | return builder; |
111 | |
} |
112 | |
|
113 | |
public ValidationResults build() { |
114 | 0 | return new ValidationResults(this); |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public Map<String, String> getErrors() { |
119 | 0 | return Collections.unmodifiableMap(this.errors); |
120 | |
} |
121 | |
|
122 | |
public void setErrors(Map<String, String> errors) { |
123 | 0 | this.errors = new HashMap<String, String>(errors); |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public void addError(String errorMessage) { |
131 | 0 | addError(GLOBAL, errorMessage); |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public void addError(String fieldName, String errorMessage) { |
139 | 0 | errors.put(fieldName, errorMessage); |
140 | 0 | } |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | 0 | static class Constants { |
147 | |
final static String ROOT_ELEMENT_NAME = "validationResults"; |
148 | |
final static String TYPE_NAME = "ValidationResultsType"; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | 0 | static class Elements { |
154 | |
final static String ERRORS = "errors"; |
155 | |
} |
156 | |
} |