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.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
21  import org.w3c.dom.Element;
22  
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30  import java.util.Collection;
31  import java.util.Collections;
32  import java.util.HashMap;
33  import java.util.Map;
34  
35  /**
36   * A quick finder widget that can be used by a TextInput, HiddenInput, Select, or MultiSelect control types.
37   */
38  @XmlRootElement(name = RemotableQuickFinder.Constants.ROOT_ELEMENT_NAME)
39  @XmlAccessorType(XmlAccessType.NONE)
40  @XmlType(name = RemotableQuickFinder.Constants.TYPE_NAME, propOrder = {
41  		RemotableQuickFinder.Elements.BASE_LOOKUP_URL,
42          RemotableQuickFinder.Elements.DATA_OBJECT_CLASS,
43          RemotableQuickFinder.Elements.LOOKUP_PARAMETERS,
44          RemotableQuickFinder.Elements.FIELD_CONVERSIONS,
45  		CoreConstants.CommonElements.FUTURE_ELEMENTS })
46  public final class RemotableQuickFinder extends RemotableAbstractWidget {
47  
48      @XmlElement(name = Elements.BASE_LOOKUP_URL, required = false)
49      private final String baseLookupUrl;
50  
51      @XmlElement(name = Elements.DATA_OBJECT_CLASS, required = true)
52      private final String dataObjectClass;
53  
54      @XmlElement(name = Elements.LOOKUP_PARAMETERS, required = false)
55      @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
56      private final Map<String, String> lookupParameters;
57  
58      @XmlElement(name = Elements.FIELD_CONVERSIONS, required = false)
59      @XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
60      private final Map<String, String> fieldConversions;
61  
62      @SuppressWarnings("unused")
63      @XmlAnyElement
64      private final Collection<Element> _futureElements = null;
65  
66      /**
67       * Should only be invoked by JAXB.
68       */
69      @SuppressWarnings("unused")
70      private RemotableQuickFinder() {
71          baseLookupUrl = null;
72          dataObjectClass = null;
73          lookupParameters = null;
74          fieldConversions = null;
75      }
76  
77      private RemotableQuickFinder(Builder b) {
78          baseLookupUrl = b.baseLookupUrl;
79          dataObjectClass = b.dataObjectClass;
80          lookupParameters = b.lookupParameters;
81          fieldConversions = b.fieldConversions;
82      }
83  
84      public String getBaseLookupUrl() {
85          return baseLookupUrl;
86      }
87  
88      public String getDataObjectClass() {
89          return dataObjectClass;
90      }
91  
92      public Map<String, String> getLookupParameters() {
93          return Collections.unmodifiableMap(lookupParameters);
94      }
95  
96      public Map<String, String> getFieldConversions() {
97          return Collections.unmodifiableMap(fieldConversions);
98      }
99  
100     public static final class Builder extends RemotableAbstractWidget.Builder {
101         private String baseLookupUrl;
102         private String dataObjectClass;
103         private Map<String, String> lookupParameters = Collections.emptyMap();
104         private Map<String, String> fieldConversions = Collections.emptyMap();
105 
106         private Builder(String baseLookupUrl, String dataObjectClass) {
107             setBaseLookupUrl(baseLookupUrl);
108             setDataObjectClass(dataObjectClass);
109         }
110 
111         public static Builder create(String baseLookupUrl, String dataObjectClass) {
112             return new Builder(baseLookupUrl, dataObjectClass);
113         }
114 
115         public String getBaseLookupUrl() {
116             return baseLookupUrl;
117         }
118 
119         public void setBaseLookupUrl(String baseLookupUrl) {
120             /*if (StringUtils.isBlank(baseLookupUrl)) {
121                 throw new IllegalArgumentException("baseLookupUrl is blank");
122             }*/
123 
124             this.baseLookupUrl = baseLookupUrl;
125         }
126 
127         public String getDataObjectClass() {
128             return dataObjectClass;
129         }
130 
131         public void setDataObjectClass(String dataObjectClass) {
132             if (StringUtils.isBlank(dataObjectClass)) {
133                 throw new IllegalArgumentException("dataObjectClass is blank");
134             }
135 
136             this.dataObjectClass = dataObjectClass;
137         }
138 
139         public Map<String, String> getLookupParameters() {
140             return Collections.unmodifiableMap(lookupParameters);
141         }
142 
143         public void setLookupParameters(Map<String, String> lookupParameters) {
144             if (lookupParameters != null) {
145                 this.lookupParameters = new HashMap<String, String>(lookupParameters);
146             }
147         }
148 
149         public Map<String, String> getFieldConversions() {
150             return Collections.unmodifiableMap(fieldConversions);
151         }
152 
153         public void setFieldConversions(Map<String, String> fieldConversions) {
154             if (fieldConversions != null) {
155                 this.fieldConversions = new HashMap<String, String>(fieldConversions);
156             }
157         }
158 
159         @Override
160         public RemotableQuickFinder build() {
161             return new RemotableQuickFinder(this);
162         }
163     }
164 
165     /**
166      * Defines some internal constants used on this class.
167      */
168     static final class Constants {
169         static final String TYPE_NAME = "QuickFinderType";
170         final static String ROOT_ELEMENT_NAME = "quickFinder";
171     }
172 
173     static final class Elements {
174         static final String BASE_LOOKUP_URL = "baseLookupUrl";
175         static final String DATA_OBJECT_CLASS = "dataObjectClass";
176         static final String LOOKUP_PARAMETERS = "lookupParameters";
177         static final String FIELD_CONVERSIONS = "fieldConversions";
178     }
179 }