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.ExtendedResponseImpl;
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 ExtendedResponseImpl 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_04166, 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     * Gets the OID uniquely identifying this extended response (a.k.a. its
098     * name).
099     * 
100     * @return the OID of the extended response type.
101     */
102    public String getResponseName()
103    {
104        return EXTENSION_OID;
105    }
106
107
108    /**
109     * Sets the OID uniquely identifying this extended response (a.k.a. its
110     * name).
111     * 
112     * @param oid
113     *            the OID of the extended response type.
114     */
115    public void setResponseName( String oid )
116    {
117        throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
118    }
119
120
121    /**
122     * {@inheritDoc}
123     */
124    @Override
125    public int hashCode()
126    {
127        int hash = 37;
128        // Seems simple but look at the equals() method ...
129        hash = hash * 17 + getClass().getName().hashCode();
130
131        return hash;
132    }
133
134
135    /**
136     * {@inheritDoc}
137     */
138    @Override
139    public boolean equals( Object obj )
140    {
141        if ( obj == this )
142        {
143            return true;
144        }
145
146        return ( obj instanceof GracefulShutdownResponseImpl );
147    }
148}