View Javadoc

1   package org.kuali.ole.deliver.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.ModelBuilder;
6   import org.w3c.dom.Element;
7   
8   import javax.xml.bind.annotation.*;
9   import java.util.ArrayList;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.List;
13  
14  /**
15   * Created with IntelliJ IDEA.
16   * User: ?
17   * Date: 6/1/12
18   * Time: 5:18 PM
19   * To change this template use File | Settings | File Templates.
20   */
21  @XmlRootElement(name = OlePatronQueryResults.Constants.ROOT_ELEMENT_NAME)
22  @XmlAccessorType(XmlAccessType.NONE)
23  @XmlType(name = OlePatronQueryResults.Constants.TYPE_NAME, propOrder = {
24          OlePatronQueryResults.Elements.RESULTS,
25          OlePatronQueryResults.Elements.TOTAL_ROW_COUNT,
26          OlePatronQueryResults.Elements.MORE_RESULTS_AVAILALBE,
27          CoreConstants.CommonElements.FUTURE_ELEMENTS})
28  
29  public class OlePatronQueryResults implements QueryResults<OlePatronDefinition> {
30  
31      @XmlElementWrapper(name = Elements.RESULTS, required = false)
32      @XmlElement(name = Elements.RESULT_ELEM, required = false)
33      private final List<OlePatronDefinition> results;
34  
35      @XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false)
36      private final Integer totalRowCount;
37  
38      @XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true)
39      private final boolean moreResultsAvailable;
40  
41      @SuppressWarnings("unused")
42      @XmlAnyElement
43      private final Collection<Element> _futureElements = null;
44  
45      public OlePatronQueryResults() {
46          this.results = null;
47          this.totalRowCount = null;
48          this.moreResultsAvailable = false;
49      }
50  
51      private OlePatronQueryResults(Builder builder) {
52          final List<OlePatronDefinition> temp = new ArrayList<OlePatronDefinition>();
53          for (OlePatronDefinition.Builder b : builder.getResults()) {
54              if (b != null) {
55                  temp.add(b.build());
56              }
57          }
58  
59          this.results = Collections.unmodifiableList(temp);
60          this.totalRowCount = builder.getTotalRowCount();
61          this.moreResultsAvailable = builder.isMoreResultsAvailable();
62      }
63  
64      @Override
65      public List<OlePatronDefinition> getResults() {
66          return results;
67      }
68  
69      @Override
70      public Integer getTotalRowCount() {
71          return totalRowCount;
72      }
73  
74      @Override
75      public boolean isMoreResultsAvailable() {
76          return moreResultsAvailable;
77      }
78  
79      public static class Builder implements ModelBuilder, QueryResults<OlePatronDefinition.Builder> {
80  
81          private List<OlePatronDefinition.Builder> results;
82          private Integer totalRowCount;
83          private boolean moreResultsAvailable;
84  
85          public static Builder create() {
86              return new Builder();
87          }
88  
89          private Builder() {
90              this.results = new ArrayList<OlePatronDefinition.Builder>();
91              this.moreResultsAvailable = false;
92          }
93  
94          @Override
95          public OlePatronQueryResults build() {
96              return new OlePatronQueryResults(this);
97          }
98  
99          @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 }