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