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.AddResponseImpl;
25  import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
26  import org.apache.directory.api.util.Strings;
27  
28  
29  /**
30   * An extended operation intended for notifying clients of upcoming
31   * disconnection for the Add response. 
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public final class AddNoDResponse extends AddResponseImpl
35  {
36      /** The OID of the NotiveOfDisconnect extended operation. */
37      public static final String EXTENSION_OID = NoticeOfDisconnect.EXTENSION_OID;
38  
39      /** The single instance with unavailable result code. */
40      public static final AddNoDResponse UNAVAILABLE = new AddNoDResponse( ResultCodeEnum.UNAVAILABLE );
41  
42      /** The single instance with protocolError result code. */
43      public static final AddNoDResponse PROTOCOLERROR = new AddNoDResponse( ResultCodeEnum.PROTOCOL_ERROR );
44  
45      /** The single instance with strongAuthRequired result code. */
46      public static final AddNoDResponse STRONGAUTHREQUIRED = new AddNoDResponse(
47          ResultCodeEnum.STRONG_AUTH_REQUIRED );
48  
49  
50      /**
51       * Creates a new instance of NoticeOfDisconnect.
52       */
53      private AddNoDResponse( ResultCodeEnum rcode )
54      {
55          super();
56  
57          switch ( rcode )
58          {
59              case UNAVAILABLE:
60                  break;
61  
62              case PROTOCOL_ERROR:
63                  break;
64  
65              case STRONG_AUTH_REQUIRED:
66                  break;
67  
68              default:
69                  throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.UNAVAILABLE,
70                      ResultCodeEnum.PROTOCOL_ERROR, ResultCodeEnum.STRONG_AUTH_REQUIRED ) );
71          }
72  
73          super.getLdapResult().setDiagnosticMessage( rcode.toString() + ": The server will disconnect!" );
74          super.getLdapResult().setMatchedDn( null );
75          super.getLdapResult().setResultCode( rcode );
76      }
77  
78  
79      // ------------------------------------------------------------------------
80      // ExtendedResponse Interface Method Implementations
81      // ------------------------------------------------------------------------
82      /**
83       * Gets the reponse OID specific encoded response values.
84       * 
85       * @return the response specific encoded response values.
86       */
87      public byte[] getResponse()
88      {
89          return Strings.EMPTY_BYTES;
90      }
91  
92  
93      /**
94       * Gets the OID uniquely identifying this extended response (a.k.a. its
95       * name).
96       * 
97       * @return the OID of the extended response type.
98       */
99      public String getResponseName()
100     {
101         return EXTENSION_OID;
102     }
103 }