View Javadoc

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