001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krms.api.repository.reference;
017
018import org.kuali.rice.core.api.CoreConstants;
019import org.kuali.rice.core.api.criteria.QueryResults;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022
023import javax.xml.bind.Element;
024import javax.xml.bind.annotation.XmlAccessType;
025import javax.xml.bind.annotation.XmlAccessorType;
026import javax.xml.bind.annotation.XmlAnyElement;
027import javax.xml.bind.annotation.XmlElement;
028import javax.xml.bind.annotation.XmlElementWrapper;
029import javax.xml.bind.annotation.XmlRootElement;
030import javax.xml.bind.annotation.XmlType;
031import java.util.ArrayList;
032import java.util.Collection;
033import java.util.Collections;
034import java.util.List;
035
036/**
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039@XmlRootElement(name = ReferenceObjectBindingQueryResults.Constants.ROOT_ELEMENT_NAME)
040@XmlAccessorType(XmlAccessType.NONE)
041@XmlType(name = ReferenceObjectBindingQueryResults.Constants.TYPE_NAME, propOrder = {
042        ReferenceObjectBindingQueryResults.Elements.RESULTS,
043        ReferenceObjectBindingQueryResults.Elements.TOTAL_ROW_COUNT,
044        ReferenceObjectBindingQueryResults.Elements.MORE_RESULTS_AVAILALBE,
045        CoreConstants.CommonElements.FUTURE_ELEMENTS })
046public class ReferenceObjectBindingQueryResults extends AbstractDataTransferObject implements QueryResults<ReferenceObjectBinding> {
047
048    @XmlElementWrapper(name = Elements.RESULTS, required = false)
049    @XmlElement(name = Elements.RESULT_ELEM, required = false)
050    private final List<ReferenceObjectBinding> 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 ReferenceObjectBindingQueryResults() {
063        this.results = null;
064        this.totalRowCount = null;
065        this.moreResultsAvailable = false;
066    }
067
068    private ReferenceObjectBindingQueryResults(Builder builder) {
069        final List<ReferenceObjectBinding> temp = new ArrayList<ReferenceObjectBinding>();
070        for (ReferenceObjectBinding.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<ReferenceObjectBinding> 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<ReferenceObjectBinding.Builder> {
097
098        private List<ReferenceObjectBinding.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<ReferenceObjectBinding.Builder>();
108            this.moreResultsAvailable = false;
109        }
110
111        @Override
112        public ReferenceObjectBindingQueryResults build() {
113            return new ReferenceObjectBindingQueryResults(this);
114        }
115
116        @Override
117        public List<ReferenceObjectBinding.Builder> getResults() {
118            return Collections.unmodifiableList(this.results);
119        }
120
121        public void setResults(List<ReferenceObjectBinding.Builder> results) {
122            this.results = new ArrayList<ReferenceObjectBinding.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 = "ReferenceObjectBindingQueryResults";
150        public final static String TYPE_NAME = "ReferenceObjectBindingQueryResultsType";
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 = "ReferenceObjectBinding";
160        public final static String TOTAL_ROW_COUNT = "totalRowCount";
161        public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable";
162    }
163
164}