Author: akarasulu
Date: Sat Nov 13 08:27:03 2004
New Revision: 57577
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/exception/LdapServiceUnavailableException.java
Log:
forgot to check in this exception
Added:
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/exception/LdapServiceUnavailableException.java
==============================================================================
--- (empty file)
+++
incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/exception/LdapServiceUnavailableException.java
Sat Nov 13 08:27:03 2004
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ldap.common.exception;
+
+
+import javax.naming.ServiceUnavailableException;
+
+import org.apache.eve.exception.EveException;
+import org.apache.ldap.common.message.ResultCodeEnum;
+
+
+/**
+ * LDAP specific ServiceUnavailableException that preserves resultCode
+ * resolution.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LdapServiceUnavailableException extends
ServiceUnavailableException
+ implements EveException
+{
+ /** the LDAP result code to be checked */
+ private final ResultCodeEnum resultCode;
+
+
+ /**
+ * Creates an LDAP specific ServiceUnavailableException that preserves
+ * resultCode resolution.
+ *
+ * @param resultCode the LDAP result code to be checked
+ * @throws IllegalArgumentException if the result code is not within the
set
+ * [EMAIL PROTECTED] ResultCodeEnum#SERVICEUNAVAILABLE_CODES}.
+ */
+ public LdapServiceUnavailableException( ResultCodeEnum resultCode )
+ {
+ super();
+ checkResultCode( resultCode );
+ this.resultCode = resultCode;
+ }
+
+
+ /**
+ * Creates an LDAP specific ServiceUnavailableException that preserves
+ * resultCode resolution.
+ *
+ * @param explanation the reason for the exception to pass to super
+ * @param resultCode the LDAP result code to be checked
+ * @throws IllegalArgumentException if the result code is not within the
set
+ * [EMAIL PROTECTED] ResultCodeEnum#SERVICEUNAVAILABLE_CODES}.
+ */
+ public LdapServiceUnavailableException( String explanation, ResultCodeEnum
resultCode )
+ {
+ super( explanation );
+ checkResultCode( resultCode );
+ this.resultCode = resultCode;
+ }
+
+
+ /**
+ * Checks to see if the LDAP result code is valid for this exception.
+ *
+ * @param resultCode the LDAP result code to be checked
+ * @throws IllegalArgumentException if the result code is not within the
set
+ * [EMAIL PROTECTED] ResultCodeEnum#SERVICEUNAVAILABLE_CODES}.
+ */
+ private void checkResultCode( ResultCodeEnum resultCode )
+ {
+ if ( ! ResultCodeEnum.getServiceCodes().contains( resultCode ) )
+ {
+ String msg = "Only the following LDAP result codes can be used: "
+ + ResultCodeEnum.getSearchCodes() ;
+ throw new IllegalArgumentException( msg );
+ }
+ }
+
+
+ /**
+ * Returns one of the resultCodes within the set [EMAIL PROTECTED]
+ * ResultCodeEnum#SERVICEUNAVAILABLE_CODES}.
+ *
+ * @see LdapException#getResultCode()
+ */
+ public final ResultCodeEnum getResultCode()
+ {
+ return resultCode;
+ }
+}