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