From f3a54c72d2e0cd5e9cd926dabdb5983cb0979b66 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Sun, 1 Apr 2007 22:06:52 +0000 Subject: [PATCH] No longer throwing DataAccessException from ContextSource. --- .../ldap/pool/PoolingContextSource.java | 8 +- .../ldap/core/ContextSource.java | 10 +-- .../DefaultNamingExceptionTranslator.java | 83 ------------------- .../ldap/support/EntryNotFoundException.java | 38 --------- .../support/NamingExceptionTranslator.java | 41 --------- ...mpensatingTransactionOperationFactory.java | 6 +- .../TransactionAwareContextSourceProxy.java | 6 +- 7 files changed, 15 insertions(+), 177 deletions(-) delete mode 100644 spring-ldap/src/main/java/org/springframework/ldap/support/DefaultNamingExceptionTranslator.java delete mode 100644 spring-ldap/src/main/java/org/springframework/ldap/support/EntryNotFoundException.java delete mode 100644 spring-ldap/src/main/java/org/springframework/ldap/support/NamingExceptionTranslator.java diff --git a/sandbox/src/main/java/org/springframework/ldap/pool/PoolingContextSource.java b/sandbox/src/main/java/org/springframework/ldap/pool/PoolingContextSource.java index b3a333ef..7023e8b4 100644 --- a/sandbox/src/main/java/org/springframework/ldap/pool/PoolingContextSource.java +++ b/sandbox/src/main/java/org/springframework/ldap/pool/PoolingContextSource.java @@ -27,8 +27,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.pool.impl.GenericKeyedObjectPool; import org.apache.commons.pool.impl.GenericObjectPool; -import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.ldap.NamingException; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.validation.DirContextValidator; @@ -428,18 +428,18 @@ public class PoolingContextSource implements ContextSource { /** * @see org.springframework.ldap.ContextSource#getReadOnlyContext() */ - public DirContext getReadOnlyContext() throws DataAccessException { + public DirContext getReadOnlyContext() throws NamingException { return this.getContext(DirContextType.READ_ONLY); } /** * @see org.springframework.ldap.ContextSource#getReadWriteContext() */ - public DirContext getReadWriteContext() throws DataAccessException { + public DirContext getReadWriteContext() throws NamingException { return this.getContext(DirContextType.READ_WRITE); } - protected DirContext getContext(DirContextType dirContextType) throws DataAccessException { + protected DirContext getContext(DirContextType dirContextType) throws NamingException { final DirContext dirContext; try { dirContext = (DirContext)this.keyedObjectPool.borrowObject(dirContextType); diff --git a/spring-ldap/src/main/java/org/springframework/ldap/core/ContextSource.java b/spring-ldap/src/main/java/org/springframework/ldap/core/ContextSource.java index 8a259a31..3d2522c7 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/core/ContextSource.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/core/ContextSource.java @@ -18,7 +18,7 @@ package org.springframework.ldap.core; import javax.naming.directory.DirContext; -import org.springframework.dao.DataAccessException; +import org.springframework.ldap.NamingException; /** * Interface used to retrieve and authenticate LDAP contexts. @@ -35,17 +35,17 @@ public interface ContextSource { * perform read-only operations on. * * @return A DirContext instance, never null. - * @throws DataAccessException + * @throws NamingException * if some error occurs creating an DirContext. */ - public DirContext getReadOnlyContext() throws DataAccessException; + public DirContext getReadOnlyContext() throws NamingException; /** * Gets a read-write DirContext. * * @return A DirContext instance, never null. - * @throws DataAccessException + * @throws NamingException * if some error occurs creating an DirContext. */ - public DirContext getReadWriteContext() throws DataAccessException; + public DirContext getReadWriteContext() throws NamingException; } \ No newline at end of file diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/DefaultNamingExceptionTranslator.java b/spring-ldap/src/main/java/org/springframework/ldap/support/DefaultNamingExceptionTranslator.java deleted file mode 100644 index 033c5825..00000000 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/DefaultNamingExceptionTranslator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2002-2005 the original author or authors. - * - * 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.springframework.ldap.support; - -import javax.naming.CommunicationException; -import javax.naming.ContextNotEmptyException; -import javax.naming.LimitExceededException; -import javax.naming.NameAlreadyBoundException; -import javax.naming.NameNotFoundException; -import javax.naming.NamingException; -import javax.naming.directory.InvalidAttributesException; -import javax.naming.directory.InvalidSearchControlsException; -import javax.naming.directory.InvalidSearchFilterException; - -import org.springframework.dao.DataAccessException; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.ldap.BadLdapGrammarException; - -/** - * The default implementation of NamingExceptionTranslator. - * - * @author Mattias Arthursson - */ -public class DefaultNamingExceptionTranslator implements - NamingExceptionTranslator { - - /* - * (non-Javadoc) - * - * @see org.springframework.ldap.NamingExceptionTranslator#translate(java.lang.String, - * java.lang.String, java.lang.String, javax.naming.NamingException) - */ - public DataAccessException translate(NamingException namingException) { - - if (namingException instanceof NameNotFoundException) { - return new EntryNotFoundException("Entry not found", - namingException); - } - - if (namingException instanceof InvalidSearchControlsException) { - return new InvalidDataAccessApiUsageException( - "Invalid search controls supplied by internal API", - namingException); - } - - if (namingException instanceof NameAlreadyBoundException) { - return new DataIntegrityViolationException("Name already bound", - namingException); - } - - if (namingException instanceof ContextNotEmptyException) { - return new DataIntegrityViolationException( - "The context needs to be empty in order to be removed", - namingException); - } - - if (namingException instanceof CommunicationException) { - throw new DataRetrievalFailureException( - "Unable to communicate with LDAP server", namingException); - } - - // Fallback - other type of NamingException encountered. - return new UncategorizedDataAccessException("Operation failed", - namingException) {}; - } -} diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/EntryNotFoundException.java b/spring-ldap/src/main/java/org/springframework/ldap/support/EntryNotFoundException.java deleted file mode 100644 index 6d1c205c..00000000 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/EntryNotFoundException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2002-2005 the original author or authors. - * - * 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.springframework.ldap.support; - -import org.springframework.dao.DataRetrievalFailureException; - -/** - * Represents that an entry could not be found. - * - * @author Mattias Arthursson - * @deprecated Should be replaced with the matching mirrored NamingException - */ -public class EntryNotFoundException extends DataRetrievalFailureException { - - private static final long serialVersionUID = -1268390922996332424L; - - public EntryNotFoundException(String msg) { - super(msg); - } - - public EntryNotFoundException(String msg, Throwable cause) { - super(msg, cause); - } -} diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/NamingExceptionTranslator.java b/spring-ldap/src/main/java/org/springframework/ldap/support/NamingExceptionTranslator.java deleted file mode 100644 index bae4e2c8..00000000 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/NamingExceptionTranslator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2002-2005 the original author or authors. - * - * 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.springframework.ldap.support; - -import javax.naming.NamingException; - -import org.springframework.dao.DataAccessException; - -/** - * Interface to be implemented by classes that can translate between - * NamingExceptions and DataAccessExceptions. - * - * @author Mattias Arthursson - * @deprecated Use {@link LdapUtils#convertLdapException(NamingException)} - * instead. - */ -public interface NamingExceptionTranslator { - /** - * Translate the given NamingException into a generic data access exception. - * - * @param namingException - * the offending NamingException. - * - * @return the DataAccessException to throw. - */ - public DataAccessException translate(NamingException namingException); -} diff --git a/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/LdapCompensatingTransactionOperationFactory.java b/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/LdapCompensatingTransactionOperationFactory.java index e932122a..a862707e 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/LdapCompensatingTransactionOperationFactory.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/LdapCompensatingTransactionOperationFactory.java @@ -25,7 +25,7 @@ import javax.naming.directory.DirContext; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.dao.DataAccessException; +import org.springframework.ldap.NamingException; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.core.LdapTemplate; @@ -109,7 +109,7 @@ public class LdapCompensatingTransactionOperationFactory implements * * @see org.springframework.ldap.ContextSource#getReadOnlyContext() */ - public DirContext getReadOnlyContext() throws DataAccessException { + public DirContext getReadOnlyContext() throws NamingException { return getNonClosingDirContextProxy(ctx); } @@ -118,7 +118,7 @@ public class LdapCompensatingTransactionOperationFactory implements * * @see org.springframework.ldap.ContextSource#getReadWriteContext() */ - public DirContext getReadWriteContext() throws DataAccessException { + public DirContext getReadWriteContext() throws NamingException { return getNonClosingDirContextProxy(ctx); } diff --git a/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/TransactionAwareContextSourceProxy.java b/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/TransactionAwareContextSourceProxy.java index 17d73513..969d5b58 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/TransactionAwareContextSourceProxy.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/transaction/core/TransactionAwareContextSourceProxy.java @@ -19,7 +19,7 @@ import java.lang.reflect.Proxy; import javax.naming.directory.DirContext; -import org.springframework.dao.DataAccessException; +import org.springframework.ldap.NamingException; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -61,7 +61,7 @@ public class TransactionAwareContextSourceProxy implements ContextSource { * * @see org.springframework.ldap.core.ContextSource#getReadOnlyContext() */ - public DirContext getReadOnlyContext() throws DataAccessException { + public DirContext getReadOnlyContext() throws NamingException { return getReadWriteContext(); } @@ -81,7 +81,7 @@ public class TransactionAwareContextSourceProxy implements ContextSource { * * @see org.springframework.ldap.core.ContextSource#getReadWriteContext() */ - public DirContext getReadWriteContext() throws DataAccessException { + public DirContext getReadWriteContext() throws NamingException { DirContextHolder contextHolder = (DirContextHolder) TransactionSynchronizationManager .getResource(target); DirContext ctx = null;