1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.api.rule;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20 import java.util.Map;
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAnyElement;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlType;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28
29 import org.apache.commons.lang.ObjectUtils;
30 import org.kuali.rice.core.api.CoreConstants;
31 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
32 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
33 import org.kuali.rice.core.api.mo.ModelBuilder;
34 import org.kuali.rice.core.api.util.collect.CollectionUtils;
35 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
36 import org.w3c.dom.Element;
37
38 @XmlRootElement(name = RuleExtension.Constants.ROOT_ELEMENT_NAME)
39 @XmlAccessorType(XmlAccessType.NONE)
40 @XmlType(name = RuleExtension.Constants.TYPE_NAME, propOrder = {
41 RuleExtension.Elements.RULE_TEMPLATE_ATTRIBUTE,
42 RuleExtension.Elements.EXTENSION_VALUES_MAP,
43 CoreConstants.CommonElements.VERSION_NUMBER,
44 CoreConstants.CommonElements.FUTURE_ELEMENTS
45 })
46 public final class RuleExtension
47 extends AbstractDataTransferObject
48 implements RuleExtensionContract
49 {
50
51 @XmlElement(name = Elements.RULE_TEMPLATE_ATTRIBUTE, required = true)
52 private final RuleTemplateAttribute ruleTemplateAttribute;
53 @XmlElement(name = Elements.EXTENSION_VALUES_MAP, required = false)
54 @XmlJavaTypeAdapter(MapStringStringAdapter.class)
55 private final Map<String, String> extensionValuesMap;
56 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
57 private final Long versionNumber;
58 @SuppressWarnings("unused")
59 @XmlAnyElement
60 private final Collection<Element> _futureElements = null;
61
62
63
64
65
66 private RuleExtension() {
67 this.ruleTemplateAttribute = null;
68 this.extensionValuesMap = null;
69 this.versionNumber = null;
70 }
71
72 private RuleExtension(Builder builder) {
73 this.ruleTemplateAttribute = builder.getRuleTemplateAttribute().build();
74 this.extensionValuesMap = builder.getExtensionValuesMap();
75 this.versionNumber = builder.getVersionNumber();
76 }
77
78 @Override
79 public RuleTemplateAttributeContract getRuleTemplateAttribute() {
80 return this.ruleTemplateAttribute;
81 }
82
83 @Override
84 public Map<String, String> getExtensionValuesMap() {
85 return this.extensionValuesMap;
86 }
87
88 @Override
89 public Long getVersionNumber() {
90 return this.versionNumber;
91 }
92
93
94
95
96
97
98 public final static class Builder
99 implements Serializable, ModelBuilder, RuleExtensionContract
100 {
101
102 private RuleTemplateAttribute.Builder ruleTemplateAttribute;
103 private Map<String, String> extensionValuesMap;
104 private Long versionNumber;
105
106 private Builder(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
107 setRuleTemplateAttribute(ruleTemplateAttribute);
108 }
109
110 public static Builder create(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
111 return new Builder(ruleTemplateAttribute);
112 }
113
114 public static Builder create(RuleExtensionContract contract) {
115 if (contract == null) {
116 throw new IllegalArgumentException("contract was null");
117 }
118
119 Builder builder = create(RuleTemplateAttribute.Builder.create(contract.getRuleTemplateAttribute()));
120 builder.setExtensionValuesMap(contract.getExtensionValuesMap());
121 builder.setVersionNumber(contract.getVersionNumber());
122 return builder;
123 }
124
125 public RuleExtension build() {
126 return new RuleExtension(this);
127 }
128
129 @Override
130 public RuleTemplateAttribute.Builder getRuleTemplateAttribute() {
131 return this.ruleTemplateAttribute;
132 }
133
134 @Override
135 public Map<String, String> getExtensionValuesMap() {
136 return this.extensionValuesMap;
137 }
138
139 @Override
140 public Long getVersionNumber() {
141 return this.versionNumber;
142 }
143
144 public void setRuleTemplateAttribute(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
145 if (ruleTemplateAttribute == null) {
146 throw new RiceIllegalArgumentException("ruleTemplateAttribute was null");
147 }
148 this.ruleTemplateAttribute = ruleTemplateAttribute;
149 }
150
151 public void setExtensionValuesMap(Map<String, String> extensionValuesMap) {
152 this.extensionValuesMap = extensionValuesMap;
153 }
154
155 public void setVersionNumber(Long versionNumber) {
156 this.versionNumber = versionNumber;
157 }
158
159 }
160
161 public boolean equals(Object o) {
162 if (o == null) return false;
163 if (!(o instanceof RuleExtension)) return false;
164 RuleExtension pred = (RuleExtension) o;
165 return ObjectUtils.equals(ruleTemplateAttribute, pred.getRuleTemplateAttribute()) &&
166 CollectionUtils.collectionsEquivalent(extensionValuesMap.entrySet(), pred.getExtensionValuesMap().entrySet());
167 }
168
169
170
171
172
173 static class Constants {
174
175 final static String ROOT_ELEMENT_NAME = "ruleExtension";
176 final static String TYPE_NAME = "RuleExtensionType";
177
178 }
179
180
181
182
183
184
185 static class Elements {
186
187 final static String RULE_TEMPLATE_ATTRIBUTE = "ruleTemplateAttribute";
188 final static String EXTENSION_VALUES_MAP = "extensionValuesMap";
189
190 }
191
192 }