1 | |
package org.kuali.rice.krms.api.repository.term; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
|
5 | |
import javax.xml.bind.annotation.XmlAccessType; |
6 | |
import javax.xml.bind.annotation.XmlAccessorType; |
7 | |
import javax.xml.bind.annotation.XmlElement; |
8 | |
import javax.xml.bind.annotation.XmlRootElement; |
9 | |
import javax.xml.bind.annotation.XmlType; |
10 | |
|
11 | |
import org.apache.commons.lang.StringUtils; |
12 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
13 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
14 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
15 | |
import org.kuali.rice.core.api.CoreConstants; |
16 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
17 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
18 | |
import org.kuali.rice.krms.api.repository.BaseAttribute; |
19 | |
import org.kuali.rice.krms.api.repository.BuilderUtils; |
20 | |
import org.kuali.rice.krms.api.repository.BaseAttribute.Builder; |
21 | |
import org.kuali.rice.krms.api.repository.BaseAttribute.Elements; |
22 | |
import org.kuali.rice.krms.api.repository.BuilderUtils.Transformer; |
23 | |
import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
@XmlRootElement(name = TermResolverAttribute.Constants.ROOT_ELEMENT_NAME) |
32 | |
@XmlAccessorType(XmlAccessType.NONE) |
33 | |
@XmlType(name = TermResolverAttribute.Constants.TYPE_NAME, propOrder = { |
34 | |
TermResolverAttribute.Elements.ID, |
35 | |
TermResolverAttribute.Elements.TERM_RESOLVER_ID, |
36 | |
TermResolverAttribute.Elements.ATTR_DEFN_ID, |
37 | |
TermResolverAttribute.Elements.VALUE, |
38 | |
TermResolverAttribute.Elements.ATTR_DEFN, |
39 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
40 | |
}) |
41 | 1 | public final class TermResolverAttribute extends BaseAttribute implements TermResolverAttributeContract, ModelObjectComplete { |
42 | |
private static final long serialVersionUID = -6126133049308968098L; |
43 | |
|
44 | |
@XmlElement(name = Elements.TERM_RESOLVER_ID, required=true) |
45 | |
private final String termResolverId; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private TermResolverAttribute() { |
51 | 2 | super(); |
52 | 2 | this.termResolverId = null; |
53 | 2 | } |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
private TermResolverAttribute(Builder builder) { |
62 | 1 | super(builder); |
63 | 1 | this.termResolverId = builder.getTermResolverId(); |
64 | 1 | } |
65 | |
|
66 | |
@Override |
67 | |
public String getTermResolverId() { |
68 | 0 | return this.termResolverId; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 1 | public static class Builder extends BaseAttribute.Builder implements TermResolverAttributeContract, ModelBuilder, Serializable { |
75 | |
private static final long serialVersionUID = 5799994031051731535L; |
76 | |
|
77 | |
private String termResolverId; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public static final Transformer<TermResolverAttributeContract, TermResolverAttribute.Builder> |
83 | 1 | toBuilder = new Transformer<TermResolverAttributeContract, TermResolverAttribute.Builder>() { |
84 | |
public org.kuali.rice.krms.api.repository.term.TermResolverAttribute.Builder transform( |
85 | |
TermResolverAttributeContract input) { |
86 | 0 | return TermResolverAttribute.Builder.create(input); |
87 | |
} |
88 | |
}; |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
private Builder(String id, String termResolverId, String attributeDefinitionId, String value) { |
94 | 1 | super(id, attributeDefinitionId, value); |
95 | 1 | setTermResolverId(termResolverId); |
96 | 1 | } |
97 | |
|
98 | |
public Builder attributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition){ |
99 | 0 | setAttributeDefinition(attributeDefinition); |
100 | 0 | return this; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public static Builder create(String id, String termResolverId, String attributeDefinitionId, String value) { |
114 | 1 | return new Builder(id, termResolverId, attributeDefinitionId, value); |
115 | |
} |
116 | |
|
117 | |
public static Builder create(TermResolverAttributeContract contract){ |
118 | 0 | if (contract == null) { |
119 | 0 | throw new IllegalArgumentException("contract is null"); |
120 | |
} |
121 | 0 | Builder builder = new Builder(contract.getId(), |
122 | |
contract.getTermResolverId(), |
123 | |
contract.getAttributeDefinitionId(), |
124 | |
contract.getValue()).attributeDefinition(KrmsAttributeDefinition.Builder |
125 | |
.create(contract.getAttributeDefinition())); |
126 | 0 | return builder; |
127 | |
} |
128 | |
|
129 | |
public void setTermResolverId(String termResolverId) { |
130 | 1 | if (StringUtils.isBlank(termResolverId)) { |
131 | 0 | throw new IllegalArgumentException("termResolverId is blank"); |
132 | |
} |
133 | 1 | this.termResolverId = termResolverId; |
134 | 1 | } |
135 | |
|
136 | |
@Override |
137 | |
public String getTermResolverId() { |
138 | 1 | return termResolverId; |
139 | |
} |
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
@Override |
147 | |
public TermResolverAttribute build() { |
148 | 1 | return new TermResolverAttribute(this); |
149 | |
} |
150 | |
|
151 | |
} |
152 | |
|
153 | |
@Override |
154 | |
public int hashCode() { |
155 | 4 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
156 | |
} |
157 | |
|
158 | |
@Override |
159 | |
public boolean equals(Object obj) { |
160 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
161 | |
} |
162 | |
|
163 | |
@Override |
164 | |
public String toString() { |
165 | 0 | return ToStringBuilder.reflectionToString(this); |
166 | |
} |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | 0 | static class Constants { |
172 | |
final static String ROOT_ELEMENT_NAME = "TermResolverAttribute"; |
173 | |
final static String TYPE_NAME = "TermResolverAttributeType"; |
174 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | 0 | public static class Elements extends BaseAttribute.Elements { |
182 | |
final static String TERM_RESOLVER_ID = "termResolverId"; |
183 | |
} |
184 | |
} |