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.model.exception; 021 022 023import org.apache.directory.api.i18n.I18n; 024import org.apache.directory.api.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 /** 040 * Creates a new instance of LdapUnwillingToPerformException, with 041 * a default ResultCode to UNWILING_TO_PERFORM. 042 */ 043 public LdapUnwillingToPerformException() 044 { 045 super( ResultCodeEnum.UNWILLING_TO_PERFORM, null ); 046 } 047 048 049 /** 050 * Creates a new instance of LdapUnwillingToPerformException. 051 * 052 * @param resultCode the ResultCodeEnum for this exception 053 * @param message The exception message 054 */ 055 public LdapUnwillingToPerformException( ResultCodeEnum resultCode, String message ) 056 { 057 super( message ); 058 checkResultCode( resultCode ); 059 this.resultCode = resultCode; 060 } 061 062 063 /** 064 * 065 * @param resultCode the ResultCodeEnum for this exception 066 * @param message The exception message 067 * @param cause The root cause for this exception 068 */ 069 public LdapUnwillingToPerformException( ResultCodeEnum resultCode, String message, Throwable cause ) 070 { 071 super( message, cause ); 072 checkResultCode( resultCode ); 073 this.resultCode = resultCode; 074 } 075 076 077 /** 078 * Creates a new instance of LdapUnwillingToPerformException. 079 * 080 * @param message The exception message 081 */ 082 public LdapUnwillingToPerformException( String message ) 083 { 084 super( ResultCodeEnum.UNWILLING_TO_PERFORM, message ); 085 } 086 087 088 /** 089 * Creates a new instance of LdapUnwillingToPerformException. 090 * 091 * @param resultCode the ResultCodeEnum for this exception 092 */ 093 public LdapUnwillingToPerformException( ResultCodeEnum resultCode ) 094 { 095 super( null ); 096 checkResultCode( resultCode ); 097 this.resultCode = resultCode; 098 } 099 100 101 /** 102 * Checks to make sure the resultCode value is right for this exception 103 * type. 104 * 105 * @throws IllegalArgumentException 106 * if the result code is not one of 107 * {@link ResultCodeEnum#UNWILLING_TO_PERFORM}, 108 * {@link ResultCodeEnum#UNAVAILABLE_CRITICAL_EXTENSION}. 109 */ 110 private void checkResultCode( ResultCodeEnum resultCode ) 111 { 112 switch ( resultCode ) 113 { 114 case UNWILLING_TO_PERFORM: 115 case UNAVAILABLE_CRITICAL_EXTENSION: 116 return; 117 118 default: 119 throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESULT_CODE, resultCode ) ); 120 } 121 } 122}