View Javadoc

1   /**
2    * Copyright 2005-2014 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  import java.util.SortedMap;
34  
35  /**
36   * A radio button group control type.
37   */
38  @XmlRootElement(name = RemotableRadioButtonGroup.Constants.ROOT_ELEMENT_NAME)
39  @XmlAccessorType(XmlAccessType.NONE)
40  @XmlType(name = RemotableRadioButtonGroup.Constants.TYPE_NAME, propOrder = {
41          RemotableRadioButtonGroup.Elements.KEY_LABELS,
42  		CoreConstants.CommonElements.FUTURE_ELEMENTS })
43  public final class RemotableRadioButtonGroup extends RemotableAbstractControl implements KeyLabeled {
44  
45      @XmlElement(name = Elements.KEY_LABELS, required = true)
46      @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
47      private final Map<String, String> keyLabels;
48  
49      @SuppressWarnings("unused")
50      @XmlAnyElement
51      private final Collection<Element> _futureElements = null;
52  
53      /**
54       * Should only be invoked by JAXB.
55       */
56      @SuppressWarnings("unused")
57      private RemotableRadioButtonGroup() {
58          keyLabels = null;
59      }
60  
61      private RemotableRadioButtonGroup(Builder b) {
62          keyLabels = b.keyLabels;
63      }
64  
65      @Override
66      public Map<String, String> getKeyLabels() {
67          return keyLabels;
68      }
69  
70      public static final class Builder extends RemotableAbstractControl.Builder implements KeyLabeled {
71          private Map<String, String> keyLabels;
72  
73          private Builder(Map<String, String> keyLabels) {
74              setKeyLabels(keyLabels);
75          }
76  
77          public static Builder create(Map<String, String> keyLabels) {
78              return new Builder(keyLabels);
79          }
80  
81          @Override
82          public Map<String, String> getKeyLabels() {
83              return keyLabels;
84          }
85  
86          public void setKeyLabels(Map<String, String> keyLabels) {
87              if (keyLabels == null || keyLabels.isEmpty()) {
88                  throw new IllegalArgumentException("keyLabels must be non-null & non-empty");
89              }
90              // keep previously SortedMaps (such as by sequence number) sorted. 
91              if (keyLabels instanceof SortedMap) {
92                  this.keyLabels = Collections.unmodifiableSortedMap((SortedMap)keyLabels);
93              } else {
94                  this.keyLabels = Collections.unmodifiableMap(new LinkedHashMap<String, String>(keyLabels));
95              }
96          }
97  
98          @Override
99          public RemotableRadioButtonGroup build() {
100             return new RemotableRadioButtonGroup(this);
101         }
102     }
103 
104     /**
105      * Defines some internal constants used on this class.
106      */
107     static final class Constants {
108         static final String TYPE_NAME = "RadioButtonGroupType";
109         final static String ROOT_ELEMENT_NAME = "radioButtonGroup";
110     }
111 
112     static final class Elements {
113         static final String KEY_LABELS = "keyLabels";
114     }
115 }