View Javadoc

1   package org.kuali.ole.patron.api;
2   
3   import org.kuali.rice.core.api.CoreConstants;
4   import org.kuali.rice.core.api.criteria.QueryResults;
5   import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
6   import org.kuali.rice.core.api.mo.ModelBuilder;
7   import org.w3c.dom.Element;
8   
9   import javax.xml.bind.annotation.*;
10  import java.util.ArrayList;
11  import java.util.Collection;
12  import java.util.Collections;
13  import java.util.List;
14  
15  /**
16   * Created with IntelliJ IDEA.
17   * User: ?
18   * Date: 6/1/12
19   * Time: 5:18 PM
20   * To change this template use File | Settings | File Templates.
21   */
22  @XmlRootElement(name = OlePatronQueryResults.Constants.ROOT_ELEMENT_NAME)
23  @XmlAccessorType(XmlAccessType.NONE)
24  @XmlType(name = OlePatronQueryResults.Constants.TYPE_NAME, propOrder = {
25          OlePatronQueryResults.Elements.RESULTS,
26          OlePatronQueryResults.Elements.TOTAL_ROW_COUNT,
27          OlePatronQueryResults.Elements.MORE_RESULTS_AVAILALBE,
28          CoreConstants.CommonElements.FUTURE_ELEMENTS })
29  
30  public class OlePatronQueryResults implements QueryResults<OlePatronDefinition> {
31  
32      @XmlElementWrapper(name = Elements.RESULTS, required = false)
33      @XmlElement(name = Elements.RESULT_ELEM, required = false)
34      private final List<OlePatronDefinition> results;
35  
36      @XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false)
37      private final Integer totalRowCount;
38  
39      @XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true)
40      private final boolean moreResultsAvailable;
41  
42      @SuppressWarnings("unused")
43      @XmlAnyElement
44      private final Collection<Element> _futureElements = null;
45  
46      public OlePatronQueryResults() {
47          this.results = null;
48          this.totalRowCount = null;
49          this.moreResultsAvailable = false;
50      }
51  
52      private OlePatronQueryResults(Builder builder) {
53          final List<OlePatronDefinition> temp = new ArrayList<OlePatronDefinition>();
54          for (OlePatronDefinition.Builder b : builder.getResults()) {
55              if (b != null) {
56                  temp.add(b.build());
57              }
58          }
59  
60          this.results = Collections.unmodifiableList(temp);
61          this.totalRowCount = builder.getTotalRowCount();
62          this.moreResultsAvailable = builder.isMoreResultsAvailable();
63      }
64  
65      @Override
66      public List<OlePatronDefinition> getResults() {
67          return results;
68      }
69  
70      @Override
71      public Integer getTotalRowCount() {
72          return totalRowCount;
73      }
74  
75      @Override
76      public boolean isMoreResultsAvailable() {
77          return moreResultsAvailable;
78      }
79  
80      public static class Builder implements ModelBuilder, QueryResults<OlePatronDefinition.Builder> {
81  
82          private List<OlePatronDefinition.Builder> results;
83          private Integer totalRowCount;
84          private boolean moreResultsAvailable;
85  
86          public static Builder create() {
87              return new Builder();
88          }
89  
90          private Builder() {
91              this.results = new ArrayList<OlePatronDefinition.Builder>();
92              this.moreResultsAvailable = false;
93          }
94  
95          @Override
96          public OlePatronQueryResults build() {
97              return new OlePatronQueryResults(this);
98          }
99  
100         @Override
101         public List<OlePatronDefinition.Builder> getResults() {
102             return Collections.unmodifiableList(this.results);
103         }
104 
105         public void setResults(List<OlePatronDefinition.Builder> results) {
106             this.results = new ArrayList<OlePatronDefinition.Builder>(results);
107         }
108 
109         @Override
110         public Integer getTotalRowCount() {
111             return this.totalRowCount;
112         }
113 
114         public void setTotalRowCount(Integer totalRowCount) {
115             this.totalRowCount = totalRowCount;
116         }
117 
118         @Override
119         public boolean isMoreResultsAvailable() {
120             return this.moreResultsAvailable;
121         }
122 
123         public void setMoreResultsAvailable(boolean moreResultsAvailable) {
124             this.moreResultsAvailable = moreResultsAvailable;
125         }
126 
127     }
128 
129     /**
130      * Defines some internal constants used on this class.
131      */
132     public static class Constants {
133         public final static String ROOT_ELEMENT_NAME = "patronQueryResults";
134         public final static String TYPE_NAME = "patronQueryResultsType";
135     }
136 
137     /**
138      * A private class which exposes constants which define the XML element
139      * names to use when this object is marshaled to XML.
140      */
141     public static class Elements {
142         public final static String RESULTS = "results";
143         public final static String RESULT_ELEM = "patron";
144         public final static String TOTAL_ROW_COUNT = "totalRowCount";
145         public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable";
146     }
147 }