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.extras.extended.gracefulShutdown;
021
022
023import org.apache.directory.api.i18n.I18n;
024import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse;
025import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
026
027
028/**
029 * The response sent back from the server when a {@link GracefulShutdownRequestImpl}
030 * extended operation is sent. Delivery of this response may block until all
031 * connected clients are sent a GracefulDisconnect unsolicited notification.
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public class GracefulShutdownResponseImpl extends AbstractExtendedResponse implements GracefulShutdownResponse
036{
037    /**
038     * Instantiates a new graceful shutdown response.
039     *
040     * @param messageId the message id
041     * @param rcode the result code
042     */
043    public GracefulShutdownResponseImpl( int messageId, ResultCodeEnum rcode )
044    {
045        super( messageId, EXTENSION_OID );
046
047        switch ( rcode )
048        {
049            case SUCCESS:
050                break;
051
052            case OPERATIONS_ERROR:
053                break;
054
055            case INSUFFICIENT_ACCESS_RIGHTS:
056                break;
057
058            default:
059                throw new IllegalArgumentException( I18n.err( I18n.ERR_13503_RESULT_CODE_SHOULD_BE_IN, ResultCodeEnum.SUCCESS,
060                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
061        }
062
063        super.getLdapResult().setMatchedDn( null );
064        super.getLdapResult().setResultCode( rcode );
065    }
066
067
068    /**
069     * Instantiates a new graceful shutdown response.
070     *
071     * @param messageId the message id
072     */
073    public GracefulShutdownResponseImpl( int messageId )
074    {
075        super( messageId, EXTENSION_OID );
076        super.getLdapResult().setMatchedDn( null );
077        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
078    }
079
080
081    /**
082     * Instantiates a new graceful shutdown response.
083     */
084    public GracefulShutdownResponseImpl()
085    {
086        super( EXTENSION_OID );
087        super.getLdapResult().setMatchedDn( null );
088        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
089    }
090
091
092    // ------------------------------------------------------------------------
093    // ExtendedResponse Interface Method Implementations
094    // ------------------------------------------------------------------------
095
096
097    /**
098     * Sets the OID uniquely identifying this extended response (a.k.a. its
099     * name).
100     * 
101     * @param oid the OID of the extended response type.
102     */
103    @Override
104    public void setResponseName( String oid )
105    {
106        throw new UnsupportedOperationException( I18n.err( I18n.ERR_13504_FIX_OID, EXTENSION_OID ) );
107    }
108
109
110    /**
111     * {@inheritDoc}
112     */
113    @Override
114    public int hashCode()
115    {
116        int hash = 37;
117        // Seems simple but look at the equals() method ...
118        hash = hash * 17 + getClass().getName().hashCode();
119
120        return hash;
121    }
122
123
124    /**
125     * {@inheritDoc}
126     */
127    @Override
128    public boolean equals( Object obj )
129    {
130        if ( obj == this )
131        {
132            return true;
133        }
134
135        return obj instanceof GracefulShutdownResponseImpl;
136    }
137}