View Javadoc

1   /**
2    * Copyright 2004-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.student.contract.model.test.source;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.List;
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.XmlAttribute;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlElementWrapper;
29  import javax.xml.bind.annotation.XmlType;
30  
31  import org.kuali.student.contract.model.test.source.ModelBuilder;
32  import org.kuali.student.contract.model.test.source.SearchParam;
33  import org.w3c.dom.Element;
34  
35  /**
36   * Search Parameter
37   *
38   * A structure that holds a key value pair to supply a value to a parameter for searching.
39   *
40   * @author nwright
41   */
42  @XmlAccessorType(XmlAccessType.FIELD)
43  @XmlType(name = "SearchParamInfo", propOrder = {"key", "values", "_futureElements"})
44  public class SearchParamInfo implements SearchParam, Serializable {
45  
46      private static final long serialVersionUID = 1L;
47      @XmlAttribute
48      private final String key;
49      @XmlElementWrapper(name="values")
50      @XmlElement(name="value")
51      private final List<String> values;
52      @XmlAnyElement
53      private final List<Element> _futureElements;
54  
55      
56      public SearchParamInfo() {
57          this.key = null;
58          this.values = null;
59          this._futureElements = null;
60      }
61  
62      public SearchParamInfo(SearchParam infc) {
63          this.key = infc.getKey();
64          if (this.values == null) {
65              this.values = null;
66          } else {
67              this.values = new ArrayList(infc.getValues());
68          }
69          this._futureElements = null;
70      }
71  
72      @Override
73      public List<String> getValues() {
74          return values;
75      }
76  
77      @Override
78      public String getKey() {
79          return key;
80      }
81  
82      public static class Builder implements ModelBuilder<SearchParamInfo>, SearchParam {
83  
84          private String key;
85          private List<String> values;
86  
87          public Builder() {}
88          
89          public Builder(SearchParam searchInfo) {
90              this.key = searchInfo.getKey();
91              this.values = searchInfo.getValues();
92          }
93          
94          public SearchParamInfo build () {
95              return new SearchParamInfo (this);
96          }
97          
98          public String getKey() {
99              return key;
100         }
101 
102         public void setKey(String key) {
103             this.key = key;
104         }
105 
106         public List<String> getValues() {
107             return values;
108         }
109 
110         public void setValues(List<String> values) {
111             this.values = values;
112         }
113 
114         /**
115          * Convenience method for setting a single value
116          * Actually stores it as a list with one value.
117          * @param value
118          */
119         public Builder value(String value) {
120             this.values = Arrays.asList(value);
121             return this;
122         }
123     }
124 }