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