001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.location.api.campus;
017    
018    import org.kuali.rice.core.api.CoreConstants;
019    import org.kuali.rice.core.api.criteria.QueryResults;
020    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021    import org.kuali.rice.core.api.mo.ModelBuilder;
022    import org.w3c.dom.Element;
023    
024    import javax.xml.bind.annotation.XmlAccessType;
025    import javax.xml.bind.annotation.XmlAccessorType;
026    import javax.xml.bind.annotation.XmlAnyElement;
027    import javax.xml.bind.annotation.XmlElement;
028    import javax.xml.bind.annotation.XmlElementWrapper;
029    import javax.xml.bind.annotation.XmlRootElement;
030    import javax.xml.bind.annotation.XmlType;
031    import java.util.ArrayList;
032    import java.util.Collection;
033    import java.util.Collections;
034    import java.util.List;
035    
036    /**
037     * @author Kuali Rice Team (rice.collab@kuali.org)
038     */
039    @XmlRootElement(name = CampusQueryResults.Constants.ROOT_ELEMENT_NAME)
040    @XmlAccessorType(XmlAccessType.NONE)
041    @XmlType(name = CampusQueryResults.Constants.TYPE_NAME, propOrder = {
042                    CampusQueryResults.Elements.RESULTS,
043                    CampusQueryResults.Elements.TOTAL_ROW_COUNT,
044                    CampusQueryResults.Elements.MORE_RESULTS_AVAILALBE,
045                    CoreConstants.CommonElements.FUTURE_ELEMENTS })
046    public class CampusQueryResults extends AbstractDataTransferObject implements QueryResults<Campus> {
047    
048            @XmlElementWrapper(name = Elements.RESULTS, required = false)
049            @XmlElement(name = Elements.RESULT_ELEM, required = false)
050            private final List<Campus> results;
051    
052            @XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false)
053            private final Integer totalRowCount;
054    
055            @XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true)
056            private final boolean moreResultsAvailable;
057    
058            @SuppressWarnings("unused")
059        @XmlAnyElement
060        private final Collection<Element> _futureElements = null;
061    
062            private CampusQueryResults() {
063                    this.results = null;
064                    this.totalRowCount = null;
065                    this.moreResultsAvailable = false;
066            }
067    
068            private CampusQueryResults(Builder builder) {
069                    final List<Campus> temp = new ArrayList<Campus>();
070            for (Campus.Builder b : builder.getResults()) {
071                if (b != null) {
072                    temp.add(b.build());
073                }
074            }
075    
076            this.results = Collections.unmodifiableList(temp);
077                    this.totalRowCount = builder.getTotalRowCount();
078                    this.moreResultsAvailable = builder.isMoreResultsAvailable();
079            }
080    
081            @Override
082            public List<Campus> getResults() {
083                    return results;
084            }
085            
086            @Override
087            public Integer getTotalRowCount() {
088                    return totalRowCount;
089            }
090    
091            @Override
092            public boolean isMoreResultsAvailable() {
093                    return moreResultsAvailable;
094            }
095    
096            public static class Builder implements ModelBuilder, QueryResults<Campus.Builder> {
097    
098                    private List<Campus.Builder> results;
099                    private Integer totalRowCount;
100                    private boolean moreResultsAvailable;
101    
102            public static Builder create() {
103                return new Builder();
104            }
105    
106                    private Builder() {
107                            this.results = new ArrayList<Campus.Builder>();
108                            this.moreResultsAvailable = false;
109                    }
110    
111            @Override
112                    public CampusQueryResults build() {
113                            return new CampusQueryResults(this);
114                    }
115    
116            @Override
117                    public List<Campus.Builder> getResults() {
118                            return Collections.unmodifiableList(this.results);
119                    }
120    
121                    public void setResults(List<Campus.Builder> results) {
122                            this.results = new ArrayList<Campus.Builder>(results);
123                    }
124    
125            @Override
126                    public Integer getTotalRowCount() {
127                            return this.totalRowCount;
128                    }
129    
130                    public void setTotalRowCount(Integer totalRowCount) {
131                            this.totalRowCount = totalRowCount;
132                    }
133    
134            @Override
135                    public boolean isMoreResultsAvailable() {
136                            return this.moreResultsAvailable;
137                    }
138    
139                    public void setMoreResultsAvailable(boolean moreResultsAvailable) {
140                            this.moreResultsAvailable = moreResultsAvailable;
141                    }
142                    
143            }
144            
145            /**
146             * Defines some internal constants used on this class.
147             */
148            public static class Constants {
149                    public final static String ROOT_ELEMENT_NAME = "CampusQueryResults";
150                    public final static String TYPE_NAME = "CampusQueryResultsType";
151            }
152    
153            /**
154             * A private class which exposes constants which define the XML element
155             * names to use when this object is marshaled to XML.
156             */
157            public static class Elements {
158                    public final static String RESULTS = "results";
159                    public final static String RESULT_ELEM = "Campus";
160                    public final static String TOTAL_ROW_COUNT = "totalRowCount";
161                    public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable";
162            }
163            
164    }