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 * A subclass of {@link LdapOperationException} designed to hold an unequivocal LDAP 029 * result code. 030 * 031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 032 */ 033public class LdapInvalidDnException extends LdapOperationException 034{ 035 /** The serial version UUID */ 036 static final long serialVersionUID = 1L; 037 038 039 /** 040 * To be used by some special exceptions like LdapInvalidDnException 041 * 042 * @param message The message for this exception 043 */ 044 public LdapInvalidDnException( String message ) 045 { 046 super( message ); 047 } 048 049 050 /** 051 * to be used by some special exceptions like LdapInvalidDnException 052 * 053 * @param message The exception message 054 * @param cause The root cause for this exception 055 */ 056 public LdapInvalidDnException( String message, Throwable cause ) 057 { 058 super( message, cause ); 059 } 060 061 062 /** 063 * Creates a new instance of LdapInvalidDnException. 064 * 065 * @param resultCode the ResultCodeEnum for this exception 066 * @param message The exception message 067 */ 068 public LdapInvalidDnException( ResultCodeEnum resultCode, String message ) 069 { 070 super( message ); 071 checkResultCode( resultCode ); 072 this.resultCode = resultCode; 073 } 074 075 076 /** 077 * Creates a new instance of LdapInvalidDnException. 078 * 079 * @param resultCode the ResultCodeEnum for this exception 080 * @param message The exception message 081 * @param cause The root cause for this exception 082 */ 083 public LdapInvalidDnException( ResultCodeEnum resultCode, String message, Throwable cause ) 084 { 085 super( message, cause ); 086 checkResultCode( resultCode ); 087 this.resultCode = resultCode; 088 } 089 090 091 /** 092 * Creates a new instance of LdapInvalidDnException. 093 * 094 * @param resultCode the ResultCodeEnum for this exception 095 */ 096 public LdapInvalidDnException( ResultCodeEnum resultCode ) 097 { 098 super( null ); 099 checkResultCode( resultCode ); 100 this.resultCode = resultCode; 101 } 102 103 104 /** 105 * Checks to make sure the resultCode value is right for this exception 106 * type. 107 * 108 * @throws IllegalArgumentException 109 * if the result code is not one of 110 * {@link ResultCodeEnum#INVALID_DN_SYNTAX}, 111 * {@link ResultCodeEnum#NAMING_VIOLATION}. 112 */ 113 private void checkResultCode( ResultCodeEnum resultCode ) 114 { 115 switch ( resultCode ) 116 { 117 case INVALID_DN_SYNTAX: 118 case NAMING_VIOLATION: 119 return; 120 121 default: 122 throw new IllegalArgumentException( I18n.err( I18n.ERR_04140_UNACCEPTABLE_RESULT_CODE, resultCode ) ); 123 } 124 } 125}