1 | |
package org.kuali.rice.core.api.uif; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
5 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
6 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
7 | |
import org.kuali.rice.core.api.CoreConstants; |
8 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
9 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
10 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
11 | |
import org.w3c.dom.Element; |
12 | |
|
13 | |
import javax.xml.bind.annotation.XmlAccessType; |
14 | |
import javax.xml.bind.annotation.XmlAccessorType; |
15 | |
import javax.xml.bind.annotation.XmlAnyElement; |
16 | |
import javax.xml.bind.annotation.XmlElement; |
17 | |
import javax.xml.bind.annotation.XmlRootElement; |
18 | |
import javax.xml.bind.annotation.XmlType; |
19 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
20 | |
import java.util.Collection; |
21 | |
import java.util.Collections; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
@XmlRootElement(name = RemotableSelectGroup.Constants.ROOT_ELEMENT_NAME) |
29 | |
@XmlAccessorType(XmlAccessType.NONE) |
30 | |
@XmlType(name = RemotableSelectGroup.Constants.TYPE_NAME, propOrder = { |
31 | |
RemotableSelectGroup.Elements.KEY_LABELS, |
32 | |
RemotableSelectGroup.Elements.LABEL, |
33 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS }) |
34 | 4 | public final class RemotableSelectGroup implements SelectGroup, ModelObjectComplete { |
35 | |
|
36 | |
@XmlElement(name = Elements.KEY_LABELS, required = true) |
37 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
38 | |
private final Map<String, String> keyLabels; |
39 | |
|
40 | |
@XmlElement(name = Elements.LABEL, required = false) |
41 | |
private final String label; |
42 | |
|
43 | 10 | @SuppressWarnings("unused") |
44 | |
@XmlAnyElement |
45 | |
private final Collection<Element> _futureElements = null; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@SuppressWarnings("unused") |
51 | 6 | private RemotableSelectGroup() { |
52 | 6 | label = null; |
53 | 6 | keyLabels = null; |
54 | 6 | } |
55 | |
|
56 | 4 | private RemotableSelectGroup(Builder b) { |
57 | 4 | label = b.label; |
58 | 4 | keyLabels = b.keyLabels; |
59 | 4 | } |
60 | |
|
61 | |
@Override |
62 | |
public Map<String, String> getKeyLabels() { |
63 | 0 | return keyLabels; |
64 | |
} |
65 | |
|
66 | |
@Override |
67 | |
public String getLabel() { |
68 | 0 | return label; |
69 | |
} |
70 | |
|
71 | |
@Override |
72 | |
public int hashCode() { |
73 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
public boolean equals(Object obj) { |
78 | 6 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public String toString() { |
83 | 0 | return ToStringBuilder.reflectionToString(this); |
84 | |
} |
85 | |
|
86 | 10 | public static final class Builder implements SelectGroup, ModelBuilder { |
87 | |
private String label; |
88 | |
private Map<String, String> keyLabels; |
89 | |
|
90 | 9 | private Builder(Map<String, String> keyLabels, String label) { |
91 | 9 | setKeyLabels(keyLabels); |
92 | 7 | setLabel(label); |
93 | 5 | } |
94 | |
|
95 | |
public static Builder create(Map<String, String> keyLabels, String label) { |
96 | 9 | return new Builder(keyLabels, label); |
97 | |
} |
98 | |
|
99 | |
@Override |
100 | |
public String getLabel() { |
101 | 0 | return label; |
102 | |
} |
103 | |
|
104 | |
public void setLabel(String label) { |
105 | 8 | if (StringUtils.isBlank(label)) { |
106 | 3 | throw new IllegalArgumentException("label was blank"); |
107 | |
} |
108 | |
|
109 | 5 | this.label = label; |
110 | 5 | } |
111 | |
|
112 | |
@Override |
113 | |
public Map<String, String> getKeyLabels() { |
114 | 0 | return keyLabels; |
115 | |
} |
116 | |
|
117 | |
public void setKeyLabels(Map<String, String> keyLabels) { |
118 | 9 | if (keyLabels == null || keyLabels.isEmpty()) { |
119 | 2 | throw new IllegalArgumentException("keyLabels must be non-null & non-empty"); |
120 | |
} |
121 | |
|
122 | 7 | this.keyLabels = Collections.unmodifiableMap(new HashMap<String, String>(keyLabels)); |
123 | 7 | } |
124 | |
|
125 | |
@Override |
126 | |
public RemotableSelectGroup build() { |
127 | 4 | return new RemotableSelectGroup(this); |
128 | |
} |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | 0 | static final class Constants { |
135 | |
static final String TYPE_NAME = "SelectGroupType"; |
136 | |
final static String ROOT_ELEMENT_NAME = "selectGroup"; |
137 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
138 | |
} |
139 | |
|
140 | 0 | static final class Elements { |
141 | |
static final String LABEL = "label"; |
142 | |
static final String KEY_LABELS = "keyLabels"; |
143 | |
} |
144 | |
} |