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.extras.extended.certGeneration;
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   * 
30   * The response sent back from the server after the CertGeneration extended operation is performed.
31   *
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class CertGenerationResponseImpl extends ExtendedResponseImpl implements CertGenerationResponse
35  {
36      /**
37       * Create a new CertGenerationResponseImpl instance
38       * 
39       * @param messageId The request's message ID
40       * @param rcode The result code
41       */
42      public CertGenerationResponseImpl( int messageId, ResultCodeEnum rcode )
43      {
44          super( messageId, EXTENSION_OID );
45  
46          switch ( rcode )
47          {
48              case SUCCESS:
49              case OPERATIONS_ERROR:
50              case INSUFFICIENT_ACCESS_RIGHTS:
51                  break;
52  
53              default:
54                  throw new IllegalArgumentException( I18n.err( I18n.ERR_04166, ResultCodeEnum.SUCCESS,
55                      ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
56          }
57  
58          super.getLdapResult().setMatchedDn( null );
59          super.getLdapResult().setResultCode( rcode );
60      }
61  
62  
63      /**
64       * Create a new CertGenerationResponseImpl instance
65       * 
66       * @param messageId The request's message ID
67       */
68      public CertGenerationResponseImpl( int messageId )
69      {
70          super( messageId, EXTENSION_OID );
71          super.getLdapResult().setMatchedDn( null );
72          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
73      }
74  
75  
76      /**
77       * Create a new CertGenerationResponseImpl instance
78       */
79      public CertGenerationResponseImpl()
80      {
81          super( EXTENSION_OID );
82          super.getLdapResult().setMatchedDn( null );
83          super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
84      }
85  
86  
87      /**
88       * Gets the OID uniquely identifying this extended response (a.k.a. its
89       * name).
90       * 
91       * @return the OID of the extended response type.
92       */
93      @Override
94      public String getResponseName()
95      {
96          return EXTENSION_OID;
97      }
98  
99  
100     /**
101      * Sets the OID uniquely identifying this extended response (a.k.a. its
102      * name).
103      * 
104      * @param oid
105      *            the OID of the extended response type.
106      */
107     @Override
108     public void setResponseName( String oid )
109     {
110         throw new UnsupportedOperationException( I18n.err( I18n.ERR_04168, EXTENSION_OID ) );
111     }
112 
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public int hashCode()
119     {
120         int hash = 37;
121         // Seems simple but look at the equals() method ...
122         hash = hash * 17 + getClass().getName().hashCode();
123 
124         return hash;
125     }
126 
127 
128     /**
129      * {@inheritDoc}
130      */
131     @Override
132     public boolean equals( Object obj )
133     {
134         if ( obj == this )
135         {
136             return true;
137         }
138 
139         return obj instanceof CertGenerationResponseImpl;
140     }
141 }