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.shared.ldap.model.exception;
021
022
023import org.apache.directory.shared.i18n.I18n;
024import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
025
026
027/**
028 * An LDAPException that extends the {@link LdapOperationException}
029 * carrying with it the corresponding result codes for this condition.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 */
033public class LdapUnwillingToPerformException extends LdapOperationException
034{
035    /** The serial version UUID */
036    static final long serialVersionUID = 1L;
037
038    /**
039     * Creates a new instance of LdapUnwillingToPerformException, with
040     * a default ResultCode to UNWILING_TO_PERFORM.
041     */
042    public LdapUnwillingToPerformException()
043    {
044        super( ResultCodeEnum.UNWILLING_TO_PERFORM, null );
045    }
046
047
048    /**
049     * Creates a new instance of LdapUnwillingToPerformException.
050     *
051     * @param resultCode the ResultCodeEnum for this exception
052     * @param message The exception message
053     */
054    public LdapUnwillingToPerformException( ResultCodeEnum resultCode, String message )
055    {
056        super( message );
057        checkResultCode( resultCode );
058        this.resultCode = resultCode;
059    }
060    
061    
062    /**
063     *
064     * @param resultCode the ResultCodeEnum for this exception
065     * @param message The exception message
066     * @param cause The root cause for this exception
067     */
068    public LdapUnwillingToPerformException( ResultCodeEnum resultCode, String message, Throwable cause )
069    {
070        super( message, cause );
071        checkResultCode( resultCode );
072        this.resultCode = resultCode;
073    }
074
075
076    /**
077     * Creates a new instance of LdapUnwillingToPerformException.
078     *
079     * @param message The exception message
080     */
081    public LdapUnwillingToPerformException( String message )
082    {
083        super( ResultCodeEnum.UNWILLING_TO_PERFORM, message );
084    }
085
086
087    /**
088     * Creates a new instance of LdapUnwillingToPerformException.
089     *
090     * @param resultCode the ResultCodeEnum for this exception
091     */
092    public LdapUnwillingToPerformException( ResultCodeEnum resultCode )
093    {
094        super( null );
095        checkResultCode( resultCode );
096        this.resultCode = resultCode;
097    }
098
099
100    /**
101     * Checks to make sure the resultCode value is right for this exception
102     * type.
103     *
104     * @throws IllegalArgumentException
105     *             if the result code is not one of
106     *             {@link ResultCodeEnum#UNWILLING_TO_PERFORM},
107     *             {@link ResultCodeEnum#UNAVAILABLE_CRITICAL_EXTENSION}.
108     */
109    private void checkResultCode( ResultCodeEnum resultCode )
110    {
111        switch ( resultCode )
112        {
113            case UNWILLING_TO_PERFORM :
114            case UNAVAILABLE_CRITICAL_EXTENSION :
115                return;
116
117            default:
118                throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESUT_CODE, resultCode ) );
119        }
120    }
121}