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.shared.ldap.extras.extended;
021
022
023import org.apache.directory.shared.i18n.I18n;
024import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
025import org.apache.directory.shared.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 ExtendedResponseImpl implements GracefulShutdownResponse
036{
037    /** The Constant serialVersionUID. */
038    private static final long serialVersionUID = -3824715470944544189L;
039
040
041    /**
042     * Instantiates a new graceful shutdown response.
043     *
044     * @param messageId the message id
045     * @param rcode the result code
046     */
047    public GracefulShutdownResponseImpl( int messageId, ResultCodeEnum rcode )
048    {
049        super( messageId, EXTENSION_OID );
050
051        switch ( rcode )
052        {
053            case SUCCESS:
054                break;
055
056            case OPERATIONS_ERROR:
057                break;
058
059            case INSUFFICIENT_ACCESS_RIGHTS:
060                break;
061
062            default:
063                throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
064                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
065        }
066
067        super.getLdapResult().setMatchedDn( null );
068        super.getLdapResult().setResultCode( rcode );
069    }
070
071
072    /**
073     * Instantiates a new graceful shutdown response.
074     *
075     * @param messageId the message id
076     */
077    public GracefulShutdownResponseImpl( int messageId )
078    {
079        super( messageId, EXTENSION_OID );
080        super.getLdapResult().setMatchedDn( null );
081        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
082    }
083
084
085    /**
086     * Instantiates a new graceful shutdown response.
087     */
088    public GracefulShutdownResponseImpl()
089    {
090        super( EXTENSION_OID );
091        super.getLdapResult().setMatchedDn( null );
092        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
093    }
094
095
096    // ------------------------------------------------------------------------
097    // ExtendedResponse Interface Method Implementations
098    // ------------------------------------------------------------------------
099
100
101    /**
102     * Gets the OID uniquely identifying this extended response (a.k.a. its
103     * name).
104     * 
105     * @return the OID of the extended response type.
106     */
107    public String getResponseName()
108    {
109        return EXTENSION_OID;
110    }
111
112
113    /**
114     * Sets the OID uniquely identifying this extended response (a.k.a. its
115     * name).
116     * 
117     * @param oid
118     *            the OID of the extended response type.
119     */
120    public void setResponseName( String oid )
121    {
122        throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
123    }
124
125
126    /**
127     * {@inheritDoc}
128     */
129    @Override
130    public int hashCode()
131    {
132        int hash = 37;
133        // Seems simple but look at the equals() method ...
134        hash = hash * 17 + getClass().getName().hashCode();
135
136        return hash;
137    }
138
139
140    /**
141     * {@inheritDoc}
142     */
143    @Override
144    public boolean equals( Object obj )
145    {
146        if ( obj == this )
147        {
148            return true;
149        }
150
151        return ( obj instanceof GracefulShutdownResponseImpl );
152    }
153}