View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.api.uif;
17  
18  import org.kuali.rice.core.api.CoreConstants;
19  import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
20  import org.w3c.dom.Element;
21  
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  import javax.xml.bind.annotation.XmlAnyElement;
25  import javax.xml.bind.annotation.XmlElement;
26  import javax.xml.bind.annotation.XmlRootElement;
27  import javax.xml.bind.annotation.XmlType;
28  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
29  import java.util.Collection;
30  import java.util.Collections;
31  import java.util.LinkedHashMap;
32  import java.util.Map;
33  
34  /**
35   * A radio button group control type.
36   */
37  @XmlRootElement(name = RemotableCheckboxGroup.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = RemotableCheckboxGroup.Constants.TYPE_NAME, propOrder = {
40  		RemotableCheckboxGroup.Elements.KEY_LABELS,
41  		CoreConstants.CommonElements.FUTURE_ELEMENTS })
42  public final class RemotableCheckboxGroup extends RemotableAbstractControl implements KeyLabeled {
43  
44      @XmlElement(name = Elements.KEY_LABELS, required = true)
45      @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
46      private final Map<String, String> keyLabels;
47  
48      @SuppressWarnings("unused")
49      @XmlAnyElement
50      private final Collection<Element> _futureElements = null;
51  
52      /**
53       * Should only be invoked by JAXB.
54       */
55      @SuppressWarnings("unused")
56      private RemotableCheckboxGroup() {
57          keyLabels = null;
58      }
59  
60      private RemotableCheckboxGroup(Builder b) {
61          keyLabels = b.keyLabels;
62      }
63  
64      @Override
65      public Map<String, String> getKeyLabels() {
66          return keyLabels;
67      }
68  
69      public static final class Builder extends RemotableAbstractControl.Builder implements KeyLabeled {
70          private Map<String, String> keyLabels;
71  
72          private Builder(Map<String, String> keyLabels) {
73              setKeyLabels(keyLabels);
74          }
75  
76          public static Builder create(Map<String, String> keyLabels) {
77              return new Builder(keyLabels);
78          }
79  
80          @Override
81          public Map<String, String> getKeyLabels() {
82              return keyLabels;
83          }
84  
85          public void setKeyLabels(Map<String, String> keyLabels) {
86              if (keyLabels == null || keyLabels.isEmpty()) {
87                  throw new IllegalArgumentException("keyLabels must be non-null & non-empty");
88              }
89  
90              this.keyLabels = Collections.unmodifiableMap(new LinkedHashMap<String, String>(keyLabels));
91          }
92  
93          @Override
94          public RemotableCheckboxGroup build() {
95              return new RemotableCheckboxGroup(this);
96          }
97      }
98  
99      /**
100      * Defines some internal constants used on this class.
101      */
102     static final class Constants {
103         static final String TYPE_NAME = "CheckboxGroupType";
104         final static String ROOT_ELEMENT_NAME = "checkboxGroup";
105     }
106 
107     static final class Elements {
108         static final String KEY_LABELS = "keyLabels";
109     }
110 }