View Javadoc

1   /*
2    * Copyright 2006-2012 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  
17  package org.kuali.rice.location.api.county;
18  
19  import org.kuali.rice.core.api.CoreConstants;
20  import org.kuali.rice.core.api.criteria.QueryResults;
21  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
22  import org.kuali.rice.core.api.mo.ModelBuilder;
23  import org.kuali.rice.location.api.country.Country;
24  import org.w3c.dom.Element;
25  
26  import javax.xml.bind.annotation.XmlAccessType;
27  import javax.xml.bind.annotation.XmlAccessorType;
28  import javax.xml.bind.annotation.XmlAnyElement;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlElementWrapper;
31  import javax.xml.bind.annotation.XmlRootElement;
32  import javax.xml.bind.annotation.XmlType;
33  import java.util.ArrayList;
34  import java.util.Collection;
35  import java.util.Collections;
36  import java.util.List;
37  
38  /**
39   * @author Kuali Rice Team (rice.collab@kuali.org)
40   */
41  @XmlRootElement(name = CountyQueryResults.Constants.ROOT_ELEMENT_NAME)
42  @XmlAccessorType(XmlAccessType.NONE)
43  @XmlType(name = CountyQueryResults.Constants.TYPE_NAME, propOrder = {
44  		CountyQueryResults.Elements.RESULTS,
45  		CountyQueryResults.Elements.TOTAL_ROW_COUNT,
46  		CountyQueryResults.Elements.MORE_RESULTS_AVAILALBE,
47  		CoreConstants.CommonElements.FUTURE_ELEMENTS })
48  public class CountyQueryResults extends AbstractDataTransferObject implements QueryResults<County> {
49  
50  	@XmlElementWrapper(name = Elements.RESULTS, required = false)
51  	@XmlElement(name = Elements.RESULT_ELEM, required = false)
52  	private final List<County> results;
53  
54  	@XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false)
55  	private final Integer totalRowCount;
56  
57  	@XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true)
58  	private final boolean moreResultsAvailable;
59  
60  	@SuppressWarnings("unused")
61      @XmlAnyElement
62      private final Collection<Element> _futureElements = null;
63  
64  	private CountyQueryResults() {
65  		this.results = null;
66  		this.totalRowCount = null;
67  		this.moreResultsAvailable = false;
68  	}
69  
70  	private CountyQueryResults(Builder builder) {
71  		final List<County> temp = new ArrayList<County>();
72          for (County.Builder b : builder.getResults()) {
73              if (b != null) {
74                  temp.add(b.build());
75              }
76          }
77  
78          this.results = Collections.unmodifiableList(temp);
79  		this.totalRowCount = builder.getTotalRowCount();
80  		this.moreResultsAvailable = builder.isMoreResultsAvailable();
81  	}
82  
83  	@Override
84  	public List<County> getResults() {
85  		return results;
86  	}
87  	
88  	@Override
89  	public Integer getTotalRowCount() {
90  		return totalRowCount;
91  	}
92  
93  	@Override
94  	public boolean isMoreResultsAvailable() {
95  		return moreResultsAvailable;
96  	}
97  
98  	public static class Builder implements ModelBuilder, QueryResults<County.Builder> {
99  
100 		private List<County.Builder> results;
101 		private Integer totalRowCount;
102 		private boolean moreResultsAvailable;
103 
104         public static Builder create() {
105             return new Builder();
106         }
107 
108 		private Builder() {
109 			this.results = new ArrayList<County.Builder>();
110 			this.moreResultsAvailable = false;
111 		}
112 
113         @Override
114 		public CountyQueryResults build() {
115 			return new CountyQueryResults(this);
116 		}
117 
118         @Override
119 		public List<County.Builder> getResults() {
120 			return Collections.unmodifiableList(this.results);
121 		}
122 
123 		public void setResults(List<County.Builder> results) {
124 			this.results = new ArrayList<County.Builder>(results);
125 		}
126 
127         @Override
128 		public Integer getTotalRowCount() {
129 			return this.totalRowCount;
130 		}
131 
132 		public void setTotalRowCount(Integer totalRowCount) {
133 			this.totalRowCount = totalRowCount;
134 		}
135 
136         @Override
137 		public boolean isMoreResultsAvailable() {
138 			return this.moreResultsAvailable;
139 		}
140 
141 		public void setMoreResultsAvailable(boolean moreResultsAvailable) {
142 			this.moreResultsAvailable = moreResultsAvailable;
143 		}
144 		
145 	}
146 	
147 	/**
148 	 * Defines some internal constants used on this class.
149 	 */
150 	public static class Constants {
151 		public final static String ROOT_ELEMENT_NAME = "CountyQueryResults";
152 		public final static String TYPE_NAME = "CountyQueryResultsType";
153 	}
154 
155 	/**
156 	 * A private class which exposes constants which define the XML element
157 	 * names to use when this object is marshaled to XML.
158 	 */
159 	public static class Elements {
160 		public final static String RESULTS = "results";
161 		public final static String RESULT_ELEM = "County";
162 		public final static String TOTAL_ROW_COUNT = "totalRowCount";
163 		public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable";
164 	}
165 	
166 }