| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| */ |
| package org.apache.directory.shared.ldap.codec.search; |
| |
| |
| import java.nio.BufferOverflowException; |
| import java.nio.ByteBuffer; |
| |
| import org.apache.directory.shared.asn1.ber.tlv.TLV; |
| import org.apache.directory.shared.asn1.codec.EncoderException; |
| import org.apache.directory.shared.i18n.I18n; |
| import org.apache.directory.shared.ldap.codec.LdapConstants; |
| import org.apache.directory.shared.ldap.codec.LdapResponseCodec; |
| import org.apache.directory.shared.ldap.codec.MessageTypeEnum; |
| |
| |
| /** |
| * A SearchResultDone Message. Its syntax is : |
| * |
| * SearchResultDone ::= [APPLICATION 5] |
| * |
| * LDAPResult It's a Response, so it inherites from LdapResponse. |
| * |
| * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> |
| */ |
| public class SearchResultDoneCodec extends LdapResponseCodec |
| { |
| // ~ Constructors |
| // ------------------------------------------------------------------------------- |
| |
| /** |
| * Creates a new SearchResultDone object. |
| */ |
| public SearchResultDoneCodec() |
| { |
| super(); |
| } |
| |
| |
| /** |
| * Get the message type |
| * |
| * @return Returns the type. |
| */ |
| public MessageTypeEnum getMessageType() |
| { |
| return MessageTypeEnum.SEARCH_RESULT_DONE; |
| } |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public String getMessageTypeName() |
| { |
| return "SEARCH_RESULT_DONE"; |
| } |
| |
| |
| /** |
| * Compute the SearchResultDone length |
| * |
| * SearchResultDone : |
| * <pre> |
| * 0x65 L1 |
| * | |
| * +--> LdapResult |
| * |
| * L1 = Length(LdapResult) |
| * Length(SearchResultDone) = Length(0x65) + Length(L1) + L1 |
| * </pre> |
| */ |
| protected int computeLengthProtocolOp() |
| { |
| int ldapResponseLength = computeLdapResultLength(); |
| |
| return 1 + TLV.getNbBytes( ldapResponseLength ) + ldapResponseLength; |
| } |
| |
| |
| /** |
| * Encode the SearchResultDone message to a PDU. |
| * |
| * @param buffer The buffer where to put the PDU |
| * @return The PDU. |
| */ |
| protected void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException |
| { |
| try |
| { |
| // The tag |
| buffer.put( LdapConstants.SEARCH_RESULT_DONE_TAG ); |
| buffer.put( TLV.getBytes( getLdapResponseLength() ) ); |
| } |
| catch ( BufferOverflowException boe ) |
| { |
| throw new EncoderException( I18n.err( I18n.ERR_04005 ) ); |
| } |
| |
| // The ldapResult |
| super.encode( buffer ); |
| } |
| |
| |
| /** |
| * Get a String representation of a SearchResultDone |
| * |
| * @return A SearchResultDone String |
| */ |
| public String toString() |
| { |
| |
| StringBuffer sb = new StringBuffer(); |
| |
| sb.append( " Search Result Done\n" ); |
| sb.append( super.toString() ); |
| |
| return sb.toString(); |
| } |
| } |