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 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 @SuppressWarnings("unused")
44 @XmlAnyElement
45 private final Collection<Element> _futureElements = null;
46
47
48
49
50 @SuppressWarnings("unused")
51 private RemotableSelectGroup() {
52 label = null;
53 keyLabels = null;
54 }
55
56 private RemotableSelectGroup(Builder b) {
57 label = b.label;
58 keyLabels = b.keyLabels;
59 }
60
61 @Override
62 public Map<String, String> getKeyLabels() {
63 return keyLabels;
64 }
65
66 @Override
67 public String getLabel() {
68 return label;
69 }
70
71 @Override
72 public int hashCode() {
73 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
79 }
80
81 @Override
82 public String toString() {
83 return ToStringBuilder.reflectionToString(this);
84 }
85
86 public static final class Builder implements SelectGroup, ModelBuilder {
87 private String label;
88 private Map<String, String> keyLabels;
89
90 private Builder(Map<String, String> keyLabels, String label) {
91 setKeyLabels(keyLabels);
92 setLabel(label);
93 }
94
95 public static Builder create(Map<String, String> keyLabels, String label) {
96 return new Builder(keyLabels, label);
97 }
98
99 @Override
100 public String getLabel() {
101 return label;
102 }
103
104 public void setLabel(String label) {
105 if (StringUtils.isBlank(label)) {
106 throw new IllegalArgumentException("label was blank");
107 }
108
109 this.label = label;
110 }
111
112 @Override
113 public Map<String, String> getKeyLabels() {
114 return keyLabels;
115 }
116
117 public void setKeyLabels(Map<String, String> keyLabels) {
118 if (keyLabels == null || keyLabels.isEmpty()) {
119 throw new IllegalArgumentException("keyLabels must be non-null & non-empty");
120 }
121
122 this.keyLabels = Collections.unmodifiableMap(new HashMap<String, String>(keyLabels));
123 }
124
125 @Override
126 public RemotableSelectGroup build() {
127 return new RemotableSelectGroup(this);
128 }
129 }
130
131
132
133
134 static final class Constants {
135 static final String TYPE_NAME = "SelectGroupType";
136 final static String ROOT_ELEMENT_NAME = "selectGroup";
137 final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
138 }
139
140 static final class Elements {
141 static final String LABEL = "label";
142 static final String KEY_LABELS = "keyLabels";
143 }
144 }