001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.dsmlv2.response; 021 022 023import java.util.ArrayList; 024import java.util.List; 025 026import org.apache.directory.api.ldap.model.message.AbstractResponse; 027import org.apache.directory.api.ldap.model.message.MessageTypeEnum; 028 029 030/** 031 * This class represents the DSML Search Response 032 * 033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 034 */ 035public class SearchResponse extends AbstractResponse 036{ 037 /** The List of contained Search Result Entries */ 038 private List<SearchResultEntryDsml> searchResultEntryList = new ArrayList<SearchResultEntryDsml>(); 039 040 /** The List of contained Search Result References */ 041 private List<SearchResultReferenceDsml> searchResultReferenceList = new ArrayList<SearchResultReferenceDsml>(); 042 043 /** The Search Result Done object */ 044 private SearchResultDoneDsml searchResultDone; 045 046 047 /** 048 * Creates a new instance of SearchResponse. 049 */ 050 public SearchResponse() 051 { 052 super( -1, null ); 053 } 054 055 056 /** 057 * Creates a new instance of SearchResponse. 058 * 059 * @param messageId the response eliciting this Request 060 */ 061 public SearchResponse( int messageId ) 062 { 063 super( messageId, null ); 064 } 065 066 067 /** 068 * Adds a Search Result Entry 069 * 070 * @param searchResultEntry 071 * the Search Result Entry to add 072 * @return 073 * true (as per the general contract of the Collection.add method) 074 */ 075 public boolean addSearchResultEntry( SearchResultEntryDsml searchResultEntry ) 076 { 077 return searchResultEntryList.add( searchResultEntry ); 078 } 079 080 081 /** 082 * Removes a Search Result Entry 083 * 084 * @param searchResultEntry 085 * the Search Result Entry to remove 086 * @return 087 * true (as per the general contract of the Collection.remove method) 088 */ 089 public boolean removeSearchResultEntry( SearchResultEntryDsml searchResultEntry ) 090 { 091 return searchResultEntryList.remove( searchResultEntry ); 092 } 093 094 095 /** 096 * Gets the Current Search Result Entry 097 * 098 * @return 099 * the current Searche Result Entry 100 */ 101 public SearchResultEntryDsml getCurrentSearchResultEntry() 102 { 103 if ( searchResultEntryList.size() > 0 ) 104 { 105 return searchResultEntryList.get( searchResultEntryList.size() - 1 ); 106 } 107 else 108 { 109 return null; 110 } 111 } 112 113 114 /** 115 * Gets the Search Result Entry List 116 * 117 * @return 118 * the Search Result Entry List 119 */ 120 public List<SearchResultEntryDsml> getSearchResultEntryList() 121 { 122 return searchResultEntryList; 123 } 124 125 126 /** 127 * Adds a Search Result Reference 128 * 129 * @param searchResultReference 130 * the Search Result Reference to add 131 * @return 132 * true (as per the general contract of the Collection.add method) 133 */ 134 public boolean addSearchResultReference( SearchResultReferenceDsml searchResultReference ) 135 { 136 return searchResultReferenceList.add( searchResultReference ); 137 } 138 139 140 /** 141 * Removes a Search Result Reference 142 * 143 * @param searchResultReference 144 * the Search Result Reference to remove 145 * @return 146 * true (as per the general contract of the Collection.remove method) 147 */ 148 public boolean removeSearchResultReference( SearchResultReferenceDsml searchResultReference ) 149 { 150 return searchResultReferenceList.remove( searchResultReference ); 151 } 152 153 154 /** 155 * Gets the current Search Result Reference 156 * 157 * @return 158 * the current Search Result Reference 159 */ 160 public SearchResultReferenceDsml getCurrentSearchResultReference() 161 { 162 if ( searchResultReferenceList.size() > 0 ) 163 { 164 return searchResultReferenceList.get( searchResultReferenceList.size() - 1 ); 165 } 166 else 167 { 168 return null; 169 } 170 } 171 172 173 /** 174 * Gets the Search Result Reference List 175 * 176 * @return 177 * the Search Result Reference List 178 */ 179 public List<SearchResultReferenceDsml> getSearchResultReferenceList() 180 { 181 return searchResultReferenceList; 182 } 183 184 185 /** 186 * Gets the Search Result Entry 187 * 188 * @return 189 * the Search Result Entry 190 */ 191 public SearchResultDoneDsml getSearchResultDone() 192 { 193 return searchResultDone; 194 } 195 196 197 /** 198 * Sets the Search Result Entry 199 * 200 * @param searchResultDone 201 * the Search Result Entry to set 202 */ 203 public void setSearchResultDone( SearchResultDoneDsml searchResultDone ) 204 { 205 this.searchResultDone = searchResultDone; 206 } 207 208 209 @Override 210 public MessageTypeEnum getType() 211 { 212 return null; 213 } 214}