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 */ 020 021 package org.apache.directory.shared.dsmlv2.reponse; 022 023 024 import java.nio.ByteBuffer; 025 import java.util.ArrayList; 026 import java.util.List; 027 028 import org.apache.directory.shared.asn1.codec.EncoderException; 029 import org.apache.directory.shared.ldap.codec.LdapResponseCodec; 030 import org.apache.directory.shared.ldap.codec.MessageTypeEnum; 031 import org.apache.directory.shared.ldap.codec.search.SearchResultDoneCodec; 032 import org.apache.directory.shared.ldap.codec.search.SearchResultEntryCodec; 033 import org.apache.directory.shared.ldap.codec.search.SearchResultReferenceCodec; 034 035 036 /** 037 * This class represents the DSML Search Response 038 * 039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 040 * @version $Rev$, $Date$ 041 */ 042 public class SearchResponse extends LdapResponseCodec 043 { 044 /** The List of contained Search Result Entries */ 045 private List<SearchResultEntryCodec> searchResultEntryList; 046 047 /** The List of contained Search Result References */ 048 private List<SearchResultReferenceCodec> searchResultReferenceList; 049 050 /** The Search Result Done object */ 051 private SearchResultDoneCodec searchResultDone; 052 053 054 /** 055 * Creates a new instance of SearchResponse. 056 */ 057 public SearchResponse() 058 { 059 searchResultEntryList = new ArrayList<SearchResultEntryCodec>(); 060 searchResultReferenceList = new ArrayList<SearchResultReferenceCodec>(); 061 } 062 063 064 /** 065 * Adds a Search Result Entry 066 * 067 * @param searchResultEntry 068 * the Search Result Entry to add 069 * @return 070 * true (as per the general contract of the Collection.add method) 071 */ 072 public boolean addSearchResultEntry( SearchResultEntryCodec searchResultEntry ) 073 { 074 return searchResultEntryList.add( searchResultEntry ); 075 } 076 077 078 /** 079 * Gets the Current Search Result Entry 080 * 081 * @return 082 * the current Searche Result Entry 083 */ 084 public SearchResultEntryCodec getCurrentSearchResultEntry() 085 { 086 if ( searchResultEntryList.size() > 0 ) 087 { 088 return searchResultEntryList.get( searchResultEntryList.size() - 1 ); 089 } 090 else 091 { 092 return null; 093 } 094 } 095 096 097 /** 098 * Gets the Search Result Entry List 099 * 100 * @return 101 * the Search Result Entry List 102 */ 103 public List<SearchResultEntryCodec> getSearchResultEntryList() 104 { 105 return searchResultEntryList; 106 } 107 108 109 /** 110 * Adds a Search Result Reference 111 * 112 * @param searchResultReference 113 * the Search Result Reference to add 114 * @return 115 * true (as per the general contract of the Collection.add method) 116 */ 117 public boolean addSearchResultReference( SearchResultReferenceCodec searchResultReference ) 118 { 119 return searchResultReferenceList.add( searchResultReference ); 120 } 121 122 123 /** 124 * Gets the current Search Result Reference 125 * 126 * @return 127 * the current Search Result Reference 128 */ 129 public SearchResultReferenceCodec getCurrentSearchResultReference() 130 { 131 if ( searchResultReferenceList.size() > 0 ) 132 { 133 return searchResultReferenceList.get( searchResultReferenceList.size() - 1 ); 134 } 135 else 136 { 137 return null; 138 } 139 } 140 141 142 /** 143 * Gets the Search Result Reference List 144 * 145 * @return 146 * the Search Result Reference List 147 */ 148 public List<SearchResultReferenceCodec> getSearchResultReferenceList() 149 { 150 return searchResultReferenceList; 151 } 152 153 154 /** 155 * Gets the Search Result Entry 156 * 157 * @return 158 * the Search Result Entry 159 */ 160 public SearchResultDoneCodec getSearchResultDone() 161 { 162 return searchResultDone; 163 } 164 165 166 /** 167 * Sets the Search Result Entry 168 * 169 * @param searchResultDone 170 * the Search Result Entry to set 171 */ 172 public void setSearchResultDone( SearchResultDoneCodec searchResultDone ) 173 { 174 this.searchResultDone = searchResultDone; 175 } 176 177 178 @Override 179 protected int computeLengthProtocolOp() 180 { 181 return 0; 182 } 183 184 185 @Override 186 protected void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException 187 { 188 } 189 190 191 @Override 192 public MessageTypeEnum getMessageType() 193 { 194 return null; 195 } 196 197 198 @Override 199 public String getMessageTypeName() 200 { 201 return null; 202 } 203 }