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 */
020 package org.apache.directory.shared.ldap.exception;
021
022
023 import org.apache.directory.shared.i18n.I18n;
024 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
025
026
027 /**
028 * LDAP specific {@link LdapOperationException} that preserves resultCode
029 * resolution.
030 *
031 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032 * @version $Rev: 923834 $
033 */
034 public class LdapServiceUnavailableException extends LdapOperationException
035 {
036 /** The serial version UUID */
037 static final long serialVersionUID = 1L;
038
039
040 /**
041 * Creates a new instance of LdapServiceUnavailableException.
042 *
043 * @param resultCode the ResultCodeEnum for this exception
044 * @param message The exception message
045 */
046 public LdapServiceUnavailableException( ResultCodeEnum resultCode, String message )
047 {
048 super( message );
049 checkResultCode( resultCode );
050 this.resultCode = resultCode;
051 }
052
053
054 /**
055 * Creates a new instance of LdapServiceUnavailableException.
056 *
057 * @param resultCode the ResultCodeEnum for this exception
058 */
059 public LdapServiceUnavailableException( ResultCodeEnum resultCode )
060 {
061 super( null );
062 checkResultCode( resultCode );
063 this.resultCode = resultCode;
064 }
065
066
067 /**
068 * Checks to make sure the resultCode value is right for this exception
069 * type.
070 *
071 * @throws IllegalArgumentException
072 * if the result code is not one of
073 * {@link ResultCodeEnum#BUSY},
074 * {@link ResultCodeEnum#UNAVAILABLE}.
075 */
076 private void checkResultCode( ResultCodeEnum resultCode )
077 {
078 switch ( resultCode )
079 {
080 case BUSY :
081 case UNAVAILABLE :
082 return;
083
084 default:
085 throw new IllegalArgumentException( I18n.err( I18n.ERR_04140, resultCode ) );
086 }
087 }
088 }