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.ldap.model.message.extended;
021
022
023import org.apache.directory.api.i18n.I18n;
024import org.apache.directory.api.ldap.model.message.ModifyResponseImpl;
025import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
026
027
028/**
029 * An extended operation intended for notifying clients of upcoming
030 * disconnection for the Modify response. 
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public final class ModifyNoDResponse extends ModifyResponseImpl
034{
035    /** The OID of the NotiveOfDisconnect extended operation. */
036    public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
037
038    /** The empty response */
039    private static final byte[] EMPTY_RESPONSE = new byte[0];
040
041    /** The single instance with unavailable result code. */
042    public static final ModifyNoDResponse UNAVAILABLE = new ModifyNoDResponse( ResultCodeEnum.UNAVAILABLE );
043
044    /** The single instance with protocolError result code. */
045    public static final ModifyNoDResponse PROTOCOLERROR = new ModifyNoDResponse( ResultCodeEnum.PROTOCOL_ERROR );
046
047    /** The single instance with strongAuthRequired result code. */
048    public static final ModifyNoDResponse STRONGAUTHREQUIRED = new ModifyNoDResponse(
049        ResultCodeEnum.STRONG_AUTH_REQUIRED );
050
051
052    /**
053     * Creates a new instance of NoticeOfDisconnect.
054     */
055    private ModifyNoDResponse( ResultCodeEnum rcode )
056    {
057        super();
058
059        switch ( rcode )
060        {
061            case UNAVAILABLE:
062                break;
063
064            case PROTOCOL_ERROR:
065                break;
066
067            case STRONG_AUTH_REQUIRED:
068                break;
069
070            default:
071                throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.UNAVAILABLE,
072                    ResultCodeEnum.PROTOCOL_ERROR, ResultCodeEnum.STRONG_AUTH_REQUIRED ) );
073        }
074
075        super.getLdapResult().setDiagnosticMessage( rcode.toString() + ": The server will disconnect!" );
076        super.getLdapResult().setMatchedDn( null );
077        super.getLdapResult().setResultCode( rcode );
078    }
079
080
081    // ------------------------------------------------------------------------
082    // ExtendedResponse Interface Method Implementations
083    // ------------------------------------------------------------------------
084    /**
085     * Gets the reponse OID specific encoded response values.
086     * 
087     * @return the response specific encoded response values.
088     */
089    public byte[] getResponse()
090    {
091        return EMPTY_RESPONSE;
092    }
093
094
095    /**
096     * Gets the OID uniquely identifying this extended response (a.k.a. its
097     * name).
098     * 
099     * @return the OID of the extended response type.
100     */
101    public String getResponseName()
102    {
103        return EXTENSION_OID;
104    }
105}