001 /** 002 * Copyright 2005-2012 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.kim.api.identity.name; 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 = EntityNameQueryResults.Constants.ROOT_ELEMENT_NAME) 040 @XmlAccessorType(XmlAccessType.NONE) 041 @XmlType(name = EntityNameQueryResults.Constants.TYPE_NAME, propOrder = { 042 EntityNameQueryResults.Elements.RESULTS, 043 EntityNameQueryResults.Elements.TOTAL_ROW_COUNT, 044 EntityNameQueryResults.Elements.MORE_RESULTS_AVAILALBE, 045 CoreConstants.CommonElements.FUTURE_ELEMENTS }) 046 public class EntityNameQueryResults extends AbstractDataTransferObject implements QueryResults<EntityName> { 047 048 @XmlElementWrapper(name = Elements.RESULTS, required = false) 049 @XmlElement(name = Elements.RESULT_ELEM, required = false) 050 private final List<EntityName> 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 EntityNameQueryResults() { 063 this.results = null; 064 this.totalRowCount = null; 065 this.moreResultsAvailable = false; 066 } 067 068 private EntityNameQueryResults(Builder builder) { 069 final List<EntityName> temp = new ArrayList<EntityName>(); 070 for (EntityName.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<EntityName> 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<EntityName.Builder> { 097 098 private List<EntityName.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<EntityName.Builder>(); 108 this.moreResultsAvailable = false; 109 } 110 111 @Override 112 public EntityNameQueryResults build() { 113 return new EntityNameQueryResults(this); 114 } 115 116 @Override 117 public List<EntityName.Builder> getResults() { 118 return Collections.unmodifiableList(this.results); 119 } 120 121 public void setResults(List<EntityName.Builder> results) { 122 this.results = new ArrayList<EntityName.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 = "entityNameQueryResults"; 150 public final static String TYPE_NAME = "entityNameQueryResultsType"; 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 = "entityName"; 160 public final static String TOTAL_ROW_COUNT = "totalRowCount"; 161 public final static String MORE_RESULTS_AVAILALBE = "moreResultsAvailable"; 162 } 163 164 }