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 */
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.ExtendedResponseImpl;
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 ExtendedResponseImpl 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_04166, 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     * Gets the OID uniquely identifying this extended response (a.k.a. its
089     * name).
090     * 
091     * @return the OID of the extended response type.
092     */
093    @Override
094    public String getResponseName()
095    {
096        return EXTENSION_OID;
097    }
098
099
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}