1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.api.validation;
18
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.kew.api.rule.Rule;
23 import org.kuali.rice.kew.api.rule.RuleContract;
24 import org.kuali.rice.kew.api.rule.RuleDelegation;
25 import org.kuali.rice.kew.api.rule.RuleDelegationContract;
26 import org.w3c.dom.Element;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlAnyElement;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlRootElement;
33 import javax.xml.bind.annotation.XmlType;
34 import java.io.Serializable;
35 import java.util.Collection;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @XmlRootElement(name = RuleValidationContext.Constants.ROOT_ELEMENT_NAME)
51 @XmlAccessorType(XmlAccessType.NONE)
52 @XmlType(name = RuleValidationContext.Constants.TYPE_NAME, propOrder = {
53 RuleValidationContext.Elements.RULE,
54 RuleValidationContext.Elements.RULE_DELEGATION,
55 RuleValidationContext.Elements.RULE_AUTHOR_PRINCIPAL_ID,
56 CoreConstants.CommonElements.FUTURE_ELEMENTS
57 })
58 public class RuleValidationContext
59 extends AbstractDataTransferObject
60 implements RuleValidationContextContract {
61
62 @XmlElement(name = Elements.RULE, required = true)
63 private final Rule rule;
64 @XmlElement(name = Elements.RULE_DELEGATION, required = true)
65 private final RuleDelegation ruleDelegation;
66 @XmlElement(name = Elements.RULE_AUTHOR_PRINCIPAL_ID, required = false)
67 private final String ruleAuthorPrincipalId;
68
69 @SuppressWarnings("unused")
70 @XmlAnyElement
71 private final Collection<Element> _futureElements = null;
72
73
74
75
76 private RuleValidationContext() {
77 this.rule = null;
78 this.ruleDelegation = null;
79 this.ruleAuthorPrincipalId = null;
80 }
81
82 private RuleValidationContext(Builder builder) {
83 this.rule = builder.getRule().build();
84 if (builder.getRuleDelegation() != null) {
85 this.ruleDelegation = builder.getRuleDelegation().build();
86 } else {
87 this.ruleDelegation = null;
88 }
89 this.ruleAuthorPrincipalId = builder.getRuleAuthorPrincipalId();
90 }
91
92
93
94
95 @Override
96 public Rule getRule() {
97 return rule;
98 }
99
100
101
102
103
104 @Override
105 public String getRuleAuthorPrincipalId() {
106 return ruleAuthorPrincipalId;
107 }
108
109
110
111
112
113 @Override
114 public RuleDelegation getRuleDelegation() {
115 return ruleDelegation;
116 }
117
118
119
120
121
122 public final static class Builder
123 implements Serializable, ModelBuilder, RuleValidationContextContract
124 {
125
126 private Rule.Builder rule;
127 private RuleDelegation.Builder ruleDelegation;
128 private String ruleAuthorPrincipalId;
129
130 private Builder() {
131 }
132
133 public static Builder create(RuleContract rule) {
134 if (rule == null) {
135 throw new IllegalArgumentException("contract was null");
136 }
137 Builder builder = new Builder();
138 builder.setRule(Rule.Builder.create(rule));
139 return builder;
140 }
141
142 public static Builder create(RuleValidationContextContract contract) {
143 return Builder.create(contract.getRule(), contract.getRuleDelegation(), contract.getRuleAuthorPrincipalId());
144 }
145
146
147
148
149
150 public static Builder create(RuleContract rule, RuleDelegationContract ruleDelegation, String ruleAuthorPrincipalId) {
151 Builder builder = Builder.create(rule);
152 if (ruleDelegation != null) {
153 builder.setRuleDelegation(RuleDelegation.Builder.create(ruleDelegation));
154 }
155 builder.setRuleAuthorPrincipalId(ruleAuthorPrincipalId);
156 return builder;
157 }
158
159 public RuleValidationContext build() {
160 return new RuleValidationContext(this);
161 }
162
163 @Override
164 public Rule.Builder getRule() {
165 return this.rule;
166 }
167
168 @Override
169 public RuleDelegation.Builder getRuleDelegation() {
170 return this.ruleDelegation;
171 }
172
173 @Override
174 public String getRuleAuthorPrincipalId() {
175 return this.ruleAuthorPrincipalId;
176 }
177
178 public void setRule(Rule.Builder rule) {
179 this.rule = rule;
180 }
181
182 public void setRuleDelegation(RuleDelegation.Builder ruleDelegation) {
183 this.ruleDelegation = ruleDelegation;
184 }
185
186 public void setRuleAuthorPrincipalId(String ruleAuthorPrincipalId) {
187 this.ruleAuthorPrincipalId = ruleAuthorPrincipalId;
188 }
189
190 }
191
192
193
194
195 static class Constants {
196 final static String ROOT_ELEMENT_NAME = "ruleValidationContext";
197 final static String TYPE_NAME = "RuleValidationContextType";
198 }
199
200
201
202
203 static class Elements {
204 final static String RULE = "rule";
205 final static String RULE_DELEGATION = "ruleDelegation";
206 final static String RULE_AUTHOR_PRINCIPAL_ID = "ruleAuthorPrincipalId";
207 }
208 }