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 *    https://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.certGeneration;
021
022
023import org.apache.directory.api.i18n.I18n;
024import org.apache.directory.api.ldap.model.message.AbstractExtendedResponse;
025import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
026
027
028/**
029 * 
030 * The response sent back from the server after the CertGeneration extended operation is performed.
031 *
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class CertGenerationResponseImpl extends AbstractExtendedResponse implements CertGenerationResponse
035{
036    /**
037     * Create a new CertGenerationResponseImpl instance
038     * 
039     * @param messageId The request's message ID
040     * @param rcode The result code
041     */
042    public CertGenerationResponseImpl( int messageId, ResultCodeEnum rcode )
043    {
044        super( messageId, EXTENSION_OID );
045
046        switch ( rcode )
047        {
048            case SUCCESS:
049            case OPERATIONS_ERROR:
050            case INSUFFICIENT_ACCESS_RIGHTS:
051                break;
052
053            default:
054                throw new IllegalArgumentException( I18n.err( I18n.ERR_13503_RESULT_CODE_SHOULD_BE_IN, ResultCodeEnum.SUCCESS,
055                    ResultCodeEnum.OPERATIONS_ERROR, ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS ) );
056        }
057
058        super.getLdapResult().setMatchedDn( null );
059        super.getLdapResult().setResultCode( rcode );
060    }
061
062
063    /**
064     * Create a new CertGenerationResponseImpl instance
065     * 
066     * @param messageId The request's message ID
067     */
068    public CertGenerationResponseImpl( int messageId )
069    {
070        super( messageId, EXTENSION_OID );
071        super.getLdapResult().setMatchedDn( null );
072        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
073    }
074
075
076    /**
077     * Create a new CertGenerationResponseImpl instance
078     */
079    public CertGenerationResponseImpl()
080    {
081        super( EXTENSION_OID );
082        super.getLdapResult().setMatchedDn( null );
083        super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
084    }
085
086
087    /**
088     * Sets the OID uniquely identifying this extended response (a.k.a. its
089     * name).
090     * 
091     * @param oid the OID of the extended response type.
092     */
093    @Override
094    public void setResponseName( String oid )
095    {
096        throw new UnsupportedOperationException( I18n.err( I18n.ERR_13504_FIX_OID, EXTENSION_OID ) );
097    }
098
099
100    /**
101     * {@inheritDoc}
102     */
103    @Override
104    public int hashCode()
105    {
106        int hash = 37;
107        // Seems simple but look at the equals() method ...
108        hash = hash * 17 + getClass().getName().hashCode();
109
110        return hash;
111    }
112
113
114    /**
115     * {@inheritDoc}
116     */
117    @Override
118    public boolean equals( Object obj )
119    {
120        if ( obj == this )
121        {
122            return true;
123        }
124
125        return obj instanceof CertGenerationResponseImpl;
126    }
127}