001package org.kuali.ole.deliver.api; 002 003import org.kuali.rice.core.api.CoreConstants; 004import org.kuali.rice.core.api.criteria.QueryResults; 005import org.kuali.rice.core.api.mo.ModelBuilder; 006import org.w3c.dom.Element; 007 008import javax.xml.bind.annotation.*; 009import java.util.ArrayList; 010import java.util.Collection; 011import java.util.Collections; 012import java.util.List; 013 014/** 015 * Created with IntelliJ IDEA. 016 * User: ? 017 * Date: 6/1/12 018 * Time: 5:18 PM 019 * To change this template use File | Settings | File Templates. 020 */ 021@XmlRootElement(name = OlePatronQueryResults.Constants.ROOT_ELEMENT_NAME) 022@XmlAccessorType(XmlAccessType.NONE) 023@XmlType(name = OlePatronQueryResults.Constants.TYPE_NAME, propOrder = { 024 OlePatronQueryResults.Elements.RESULTS, 025 OlePatronQueryResults.Elements.TOTAL_ROW_COUNT, 026 OlePatronQueryResults.Elements.MORE_RESULTS_AVAILALBE, 027 CoreConstants.CommonElements.FUTURE_ELEMENTS}) 028 029public class OlePatronQueryResults implements QueryResults<OlePatronDefinition> { 030 031 @XmlElementWrapper(name = Elements.RESULTS, required = false) 032 @XmlElement(name = Elements.RESULT_ELEM, required = false) 033 private final List<OlePatronDefinition> results; 034 035 @XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false) 036 private final Integer totalRowCount; 037 038 @XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true) 039 private final boolean moreResultsAvailable; 040 041 @SuppressWarnings("unused") 042 @XmlAnyElement 043 private final Collection<Element> _futureElements = null; 044 045 public OlePatronQueryResults() { 046 this.results = null; 047 this.totalRowCount = null; 048 this.moreResultsAvailable = false; 049 } 050 051 private OlePatronQueryResults(Builder builder) { 052 final List<OlePatronDefinition> temp = new ArrayList<OlePatronDefinition>(); 053 for (OlePatronDefinition.Builder b : builder.getResults()) { 054 if (b != null) { 055 temp.add(b.build()); 056 } 057 } 058 059 this.results = Collections.unmodifiableList(temp); 060 this.totalRowCount = builder.getTotalRowCount(); 061 this.moreResultsAvailable = builder.isMoreResultsAvailable(); 062 } 063 064 @Override 065 public List<OlePatronDefinition> getResults() { 066 return results; 067 } 068 069 @Override 070 public Integer getTotalRowCount() { 071 return totalRowCount; 072 } 073 074 @Override 075 public boolean isMoreResultsAvailable() { 076 return moreResultsAvailable; 077 } 078 079 public static class Builder implements ModelBuilder, QueryResults<OlePatronDefinition.Builder> { 080 081 private List<OlePatronDefinition.Builder> results; 082 private Integer totalRowCount; 083 private boolean moreResultsAvailable; 084 085 public static Builder create() { 086 return new Builder(); 087 } 088 089 private Builder() { 090 this.results = new ArrayList<OlePatronDefinition.Builder>(); 091 this.moreResultsAvailable = false; 092 } 093 094 @Override 095 public OlePatronQueryResults build() { 096 return new OlePatronQueryResults(this); 097 } 098 099 @Override 100 public List<OlePatronDefinition.Builder> getResults() { 101 return Collections.unmodifiableList(this.results); 102 } 103 104 public void setResults(List<OlePatronDefinition.Builder> results) { 105 this.results = new ArrayList<OlePatronDefinition.Builder>(results); 106 } 107 108 @Override 109 public Integer getTotalRowCount() { 110 return this.totalRowCount; 111 } 112 113 public void setTotalRowCount(Integer totalRowCount) { 114 this.totalRowCount = totalRowCount; 115 } 116 117 @Override 118 public boolean isMoreResultsAvailable() { 119 return this.moreResultsAvailable; 120 } 121 122 public void setMoreResultsAvailable(boolean moreResultsAvailable) { 123 this.moreResultsAvailable = moreResultsAvailable; 124 } 125 126 } 127 128 /** 129 * Defines some internal constants used on this class. 130 */ 131 public static class Constants { 132 public final static String ROOT_ELEMENT_NAME = "patronQueryResults"; 133 public final static String TYPE_NAME = "patronQueryResultsType"; 134 } 135 136 /** 137 * A private class which exposes constants which define the XML element 138 * names to use when this object is marshaled to XML. 139 */ 140 public static class Elements { 141 public final static String RESULTS = "results"; 142 public final static String RESULT_ELEM = "patron"; 143 public final static String TOTAL_ROW_COUNT = "totalRowCount"; 144 public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable"; 145 } 146}