1 | |
package org.kuali.rice.kew.api.document; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
|
6 | |
import javax.xml.bind.annotation.XmlAccessType; |
7 | |
import javax.xml.bind.annotation.XmlAccessorType; |
8 | |
import javax.xml.bind.annotation.XmlAnyElement; |
9 | |
import javax.xml.bind.annotation.XmlElement; |
10 | |
import javax.xml.bind.annotation.XmlRootElement; |
11 | |
import javax.xml.bind.annotation.XmlType; |
12 | |
|
13 | |
import org.apache.commons.lang.StringUtils; |
14 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
15 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
16 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
17 | |
import org.kuali.rice.core.api.CoreConstants; |
18 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
19 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
20 | |
import org.w3c.dom.Element; |
21 | |
|
22 | |
@XmlRootElement(name = DocumentVariable.Constants.ROOT_ELEMENT_NAME) |
23 | |
@XmlAccessorType(XmlAccessType.NONE) |
24 | |
@XmlType(name = DocumentVariable.Constants.TYPE_NAME, propOrder = { |
25 | |
DocumentVariable.Elements.NAME, |
26 | |
DocumentVariable.Elements.VALUE, |
27 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
28 | |
}) |
29 | 0 | public final class DocumentVariable implements ModelObjectComplete, DocumentVariableContract { |
30 | |
|
31 | |
private static final long serialVersionUID = -7875688623286970510L; |
32 | |
|
33 | |
@XmlElement(name = Elements.NAME, required = true) |
34 | |
private final String name; |
35 | |
|
36 | |
@XmlElement(name = Elements.VALUE, required = true) |
37 | |
private final String value; |
38 | |
|
39 | 0 | @SuppressWarnings("unused") |
40 | |
@XmlAnyElement |
41 | |
private final Collection<Element> _futureElements = null; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | private DocumentVariable() { |
47 | 0 | this.name = null; |
48 | 0 | this.value = null; |
49 | 0 | } |
50 | |
|
51 | 0 | private DocumentVariable(Builder builder) { |
52 | 0 | this.name = builder.getName(); |
53 | 0 | this.value = builder.getValue(); |
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
public String getName() { |
58 | 0 | return this.name; |
59 | |
} |
60 | |
|
61 | |
@Override |
62 | |
public String getValue() { |
63 | 0 | return this.value; |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
public int hashCode() { |
68 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public boolean equals(Object object) { |
73 | 0 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
public String toString() { |
78 | 0 | return ToStringBuilder.reflectionToString(this); |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | 0 | public final static class Builder implements Serializable, ModelBuilder, DocumentVariableContract { |
86 | |
|
87 | |
private static final long serialVersionUID = -2064548119902762503L; |
88 | |
|
89 | |
private String name; |
90 | |
private String value; |
91 | |
|
92 | 0 | private Builder(String name, String value) { |
93 | 0 | setName(name); |
94 | 0 | setValue(value); |
95 | 0 | } |
96 | |
|
97 | |
public static Builder create(String name, String value) { |
98 | 0 | return new Builder(name, value); |
99 | |
} |
100 | |
|
101 | |
public static Builder create(DocumentVariableContract contract) { |
102 | 0 | if (contract == null) { |
103 | 0 | throw new IllegalArgumentException("contract was null"); |
104 | |
} |
105 | 0 | return create(contract.getName(), contract.getValue()); |
106 | |
} |
107 | |
|
108 | |
public DocumentVariable build() { |
109 | 0 | return new DocumentVariable(this); |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public String getName() { |
114 | 0 | return this.name; |
115 | |
} |
116 | |
|
117 | |
@Override |
118 | |
public String getValue() { |
119 | 0 | return this.value; |
120 | |
} |
121 | |
|
122 | |
public void setName(String name) { |
123 | 0 | if (StringUtils.isBlank(name)) { |
124 | 0 | throw new IllegalArgumentException("name was null or blank"); |
125 | |
} |
126 | 0 | this.name = name; |
127 | 0 | } |
128 | |
|
129 | |
public void setValue(String value) { |
130 | 0 | if (value == null) { |
131 | 0 | value = ""; |
132 | |
} |
133 | 0 | this.value = value; |
134 | 0 | } |
135 | |
|
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | 0 | static class Constants { |
144 | |
|
145 | |
final static String ROOT_ELEMENT_NAME = "documentVariable"; |
146 | |
final static String TYPE_NAME = "DocumentVariableType"; |
147 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
148 | |
|
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | 0 | static class Elements { |
157 | |
|
158 | |
final static String NAME = "name"; |
159 | |
final static String VALUE = "value"; |
160 | |
|
161 | |
} |
162 | |
|
163 | |
} |
164 | |
|