View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.api.ldap.model.message.extended;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  import org.apache.directory.api.ldap.model.message.ExtendedResponseImpl;
25  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26  
27  
28  /**
29   * An extended operation intended for notifying clients of upcoming
30   * disconnection for the Extended response. 
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class ExtendedNoDResponse extends ExtendedResponseImpl
34  {
35      /** The serial version UID */
36      static final long serialVersionUID = 2L;
37  
38      /** The OID of the NotiveOfDisconnect extended operation. */
39      public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
40  
41      /** The empty response */
42      private static final byte[] EMPTY_RESPONSE = new byte[0];
43  
44      /** The single instance with unavailable result code. */
45      public static final ExtendedNoDResponse UNAVAILABLE = new ExtendedNoDResponse( ResultCodeEnum.UNAVAILABLE );
46  
47      /** The single instance with protocolError result code. */
48      public static final ExtendedNoDResponse PROTOCOLERROR = new ExtendedNoDResponse( ResultCodeEnum.PROTOCOL_ERROR );
49  
50      /** The single instance with strongAuthRequired result code. */
51      public static final ExtendedNoDResponse STRONGAUTHREQUIRED = new ExtendedNoDResponse(
52          ResultCodeEnum.STRONG_AUTH_REQUIRED );
53  
54  
55      /**
56       * Creates a new instance of NoticeOfDisconnect.
57       */
58      private ExtendedNoDResponse( ResultCodeEnum rcode )
59      {
60          super( EXTENSION_OID );
61  
62          switch ( rcode )
63          {
64              case UNAVAILABLE:
65                  break;
66  
67              case PROTOCOL_ERROR:
68                  break;
69  
70              case STRONG_AUTH_REQUIRED:
71                  break;
72  
73              default:
74                  throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.UNAVAILABLE,
75                      ResultCodeEnum.PROTOCOL_ERROR, ResultCodeEnum.STRONG_AUTH_REQUIRED ) );
76          }
77  
78          super.getLdapResult().setDiagnosticMessage( rcode.toString() + ": The server will disconnect!" );
79          super.getLdapResult().setMatchedDn( null );
80          super.getLdapResult().setResultCode( rcode );
81      }
82  
83  
84      // ------------------------------------------------------------------------
85      // ExtendedResponse Interface Method Implementations
86      // ------------------------------------------------------------------------
87      /**
88       * Gets the reponse OID specific encoded response values.
89       * 
90       * @return the response specific encoded response values.
91       */
92      public byte[] getResponse()
93      {
94          return EMPTY_RESPONSE;
95      }
96  
97  
98      /**
99       * Gets the OID uniquely identifying this extended response (a.k.a. its
100      * name).
101      * 
102      * @return the OID of the extended response type.
103      */
104     public String getResponseName()
105     {
106         return EXTENSION_OID;
107     }
108 }