001/**
002 * Copyright 2005-2014 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.kim.api.role;
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;
022import org.kuali.rice.kim.api.common.delegate.DelegateMember;
023import org.w3c.dom.Element;
024
025import javax.xml.bind.annotation.XmlAccessType;
026import javax.xml.bind.annotation.XmlAccessorType;
027import javax.xml.bind.annotation.XmlAnyElement;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlElementWrapper;
030import javax.xml.bind.annotation.XmlRootElement;
031import javax.xml.bind.annotation.XmlType;
032import java.util.ArrayList;
033import java.util.Collection;
034import java.util.Collections;
035import java.util.List;
036
037/**
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 */
040@XmlRootElement(name = DelegateMemberQueryResults.Constants.ROOT_ELEMENT_NAME)
041@XmlAccessorType(XmlAccessType.NONE)
042@XmlType(name = DelegateMemberQueryResults.Constants.TYPE_NAME, propOrder = {
043                DelegateMemberQueryResults.Elements.RESULTS,
044                DelegateMemberQueryResults.Elements.TOTAL_ROW_COUNT,
045                DelegateMemberQueryResults.Elements.MORE_RESULTS_AVAILALBE,
046                CoreConstants.CommonElements.FUTURE_ELEMENTS })
047public class DelegateMemberQueryResults extends AbstractDataTransferObject implements QueryResults<DelegateMember> {
048
049        @XmlElementWrapper(name = Elements.RESULTS, required = false)
050        @XmlElement(name = Elements.RESULT_ELEM, required = false)
051        private final List<DelegateMember> results;
052
053        @XmlElement(name = Elements.TOTAL_ROW_COUNT, required = false)
054        private final Integer totalRowCount;
055
056        @XmlElement(name = Elements.MORE_RESULTS_AVAILALBE, required = true)
057        private final boolean moreResultsAvailable;
058
059        @SuppressWarnings("unused")
060    @XmlAnyElement
061    private final Collection<Element> _futureElements = null;
062
063        private DelegateMemberQueryResults() {
064                this.results = null;
065                this.totalRowCount = null;
066                this.moreResultsAvailable = false;
067        }
068
069        private DelegateMemberQueryResults(Builder builder) {
070                final List<DelegateMember> temp = new ArrayList<DelegateMember>();
071        for (DelegateMember.Builder b : builder.getResults()) {
072            if (b != null) {
073                temp.add(b.build());
074            }
075        }
076
077        this.results = Collections.unmodifiableList(temp);
078                this.totalRowCount = builder.getTotalRowCount();
079                this.moreResultsAvailable = builder.isMoreResultsAvailable();
080        }
081
082        @Override
083        public List<DelegateMember> getResults() {
084                return results;
085        }
086        
087        @Override
088        public Integer getTotalRowCount() {
089                return totalRowCount;
090        }
091
092        @Override
093        public boolean isMoreResultsAvailable() {
094                return moreResultsAvailable;
095        }
096
097        public static class Builder implements ModelBuilder, QueryResults<DelegateMember.Builder> {
098
099                private List<DelegateMember.Builder> results;
100                private Integer totalRowCount;
101                private boolean moreResultsAvailable;
102
103        public static Builder create() {
104            return new Builder();
105        }
106
107                private Builder() {
108                        this.results = new ArrayList<DelegateMember.Builder>();
109                        this.moreResultsAvailable = false;
110                }
111
112        @Override
113                public DelegateMemberQueryResults build() {
114                        return new DelegateMemberQueryResults(this);
115                }
116
117        @Override
118                public List<DelegateMember.Builder> getResults() {
119                        return Collections.unmodifiableList(this.results);
120                }
121
122                public void setResults(List<DelegateMember.Builder> results) {
123                        this.results = new ArrayList<DelegateMember.Builder>(results);
124                }
125
126        @Override
127                public Integer getTotalRowCount() {
128                        return this.totalRowCount;
129                }
130
131                public void setTotalRowCount(Integer totalRowCount) {
132                        this.totalRowCount = totalRowCount;
133                }
134
135        @Override
136                public boolean isMoreResultsAvailable() {
137                        return this.moreResultsAvailable;
138                }
139
140                public void setMoreResultsAvailable(boolean moreResultsAvailable) {
141                        this.moreResultsAvailable = moreResultsAvailable;
142                }
143                
144        }
145        
146        /**
147         * Defines some internal constants used on this class.
148         */
149        public static class Constants {
150                public final static String ROOT_ELEMENT_NAME = "delegateMemberQueryResults";
151                public final static String TYPE_NAME = "DelegateMemberQueryResultsType";
152        }
153
154        /**
155         * A private class which exposes constants which define the XML element
156         * names to use when this object is marshaled to XML.
157         */
158        public static class Elements {
159                public final static String RESULTS = "results";
160                public final static String RESULT_ELEM = "delegateMember";
161                public final static String TOTAL_ROW_COUNT = "totalRowCount";
162                public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable";
163        }
164        
165}