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 package org.apache.directory.shared.ldap.codec.modify;
021
022
023 import java.nio.BufferOverflowException;
024 import java.nio.ByteBuffer;
025
026 import org.apache.directory.shared.asn1.ber.tlv.TLV;
027 import org.apache.directory.shared.asn1.codec.EncoderException;
028 import org.apache.directory.shared.i18n.I18n;
029 import org.apache.directory.shared.ldap.codec.LdapConstants;
030 import org.apache.directory.shared.ldap.codec.LdapResponseCodec;
031 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
032
033
034 /**
035 * An ModifyResponse Message. Its syntax is :
036 *
037 * ModifyResponse ::= [APPLICATION 7] LDAPResult
038 *
039 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
040 * @version $Rev: 912399 $, $Date: 2010-02-21 22:52:31 +0200 (Sun, 21 Feb 2010) $,
041 */
042 public class ModifyResponseCodec extends LdapResponseCodec
043 {
044 // ~ Constructors
045 // -------------------------------------------------------------------------------
046
047 /**
048 * Creates a new ModifyResponse object.
049 */
050 public ModifyResponseCodec()
051 {
052 super();
053 }
054
055
056 /**
057 * Get the message type
058 *
059 * @return Returns the type.
060 */
061 public MessageTypeEnum getMessageType()
062 {
063 return MessageTypeEnum.MODIFY_RESPONSE;
064 }
065
066
067 /**
068 * {@inheritDoc}
069 */
070 public String getMessageTypeName()
071 {
072 return "MODIFY_RESPONSE";
073 }
074
075
076 /**
077 * Compute the ModifyResponse length
078 *
079 * ModifyResponse :
080 * <pre>
081 * 0x67 L1
082 * |
083 * +--> LdapResult
084 *
085 * L1 = Length(LdapResult)
086 * Length(ModifyResponse) = Length(0x67) + Length(L1) + L1
087 * </pre>
088 */
089 protected int computeLengthProtocolOp()
090 {
091 int ldapResponseLength = super.computeLdapResultLength();
092
093 return 1 + TLV.getNbBytes( ldapResponseLength ) + ldapResponseLength;
094 }
095
096
097 /**
098 * Encode the ModifyResponse message to a PDU.
099 *
100 * @param buffer The buffer where to put the PDU
101 * @return The PDU.
102 */
103 protected void encodeProtocolOp( ByteBuffer buffer ) throws EncoderException
104 {
105 try
106 {
107 // The tag
108 buffer.put( LdapConstants.MODIFY_RESPONSE_TAG );
109 buffer.put( TLV.getBytes( getLdapResponseLength() ) );
110 }
111 catch ( BufferOverflowException boe )
112 {
113 throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
114 }
115
116 // The ldapResult
117 super.encode( buffer );
118 }
119
120
121 /**
122 * Get a String representation of a ModifyResponse
123 *
124 * @return A ModifyResponse String
125 */
126 public String toString()
127 {
128
129 StringBuffer sb = new StringBuffer();
130
131 sb.append( " Modify Response\n" );
132 sb.append( super.toString() );
133
134 return sb.toString();
135 }
136 }