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.message.extended;
021    
022    
023    import org.apache.directory.shared.i18n.I18n;
024    import org.apache.directory.shared.ldap.message.ExtendedResponseImpl;
025    import org.apache.directory.shared.ldap.message.ResultCodeEnum;
026    
027    
028    /**
029     * The response sent back from the server when a {@link GracefulShutdownRequest}
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     * @version $Rev: 912436 $
035     */
036    public class GracefulShutdownResponse extends ExtendedResponseImpl
037    {
038        private static final long serialVersionUID = -3824715470944544189L;
039    
040        public static final String EXTENSION_OID = "1.3.6.1.4.1.18060.0.1.4";
041    
042        private static final byte[] EMPTY_RESPONSE = new byte[0];
043    
044    
045        public GracefulShutdownResponse(int messageId, ResultCodeEnum rcode)
046        {
047            super( messageId, EXTENSION_OID );
048    
049            switch ( rcode )
050            {
051                case SUCCESS :
052                    break;
053                
054                case OPERATIONS_ERROR :
055                    break;
056                
057                case INSUFFICIENT_ACCESS_RIGHTS :
058                    break;
059                
060                default:
061                    throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
062                                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
063            }
064            
065            super.getLdapResult().setMatchedDn( null );
066            super.getLdapResult().setResultCode( rcode );
067        }
068    
069    
070        public GracefulShutdownResponse(int messageId)
071        {
072            super( messageId, EXTENSION_OID );
073            super.getLdapResult().setMatchedDn( null );
074            super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
075        }
076    
077    
078        // ------------------------------------------------------------------------
079        // ExtendedResponse Interface Method Implementations
080        // ------------------------------------------------------------------------
081    
082        /**
083         * Gets the reponse OID specific encoded response values.
084         * 
085         * @return the response specific encoded response values.
086         */
087        public byte[] getResponse()
088        {
089            return EMPTY_RESPONSE;
090        }
091    
092    
093        /**
094         * Sets the reponse OID specific encoded response values.
095         * 
096         * @param value
097         *            the response specific encoded response values.
098         */
099        public void setResponse( byte[] value )
100        {
101            // do nothing here instead
102        }
103    
104    
105        /**
106         * Gets the OID uniquely identifying this extended response (a.k.a. its
107         * name).
108         * 
109         * @return the OID of the extended response type.
110         */
111        public String getResponseName()
112        {
113            return EXTENSION_OID;
114        }
115    
116    
117        /**
118         * Sets the OID uniquely identifying this extended response (a.k.a. its
119         * name).
120         * 
121         * @param oid
122         *            the OID of the extended response type.
123         */
124        public void setResponseName( String oid )
125        {
126            throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
127        }
128    
129    
130        public boolean equals( Object obj )
131        {
132            if ( obj == this )
133            {
134                return true;
135            }
136    
137            if ( obj instanceof GracefulShutdownResponse )
138            {
139                return true;
140            }
141    
142            return false;
143        }
144    }