Preparing to replace the exceptions.

This commit is contained in:
Ulrik Sandberg
2007-01-09 23:19:57 +00:00
parent d386dc9c39
commit 5f44a65c9f
6 changed files with 289 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/*
* 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.DataIntegrityViolationException;
/**
* Exception that indicates that an invalid or missing Attribute has been
* supplied to an LDAP operation.
*
* @author Mattias Arthursson
* @deprecated Should be replaced with the matching mirrored NamingException
*/
public class AttributesIntegrityViolationException extends
DataIntegrityViolationException {
private static final long serialVersionUID = -6368616096960202571L;
public AttributesIntegrityViolationException(String msg) {
super(msg);
}
public AttributesIntegrityViolationException(String msg, Throwable t) {
super(msg, t);
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.InvalidDataAccessResourceUsageException;
/**
* Thrown to indicate that an invalid value has been supplied to an LDAP
* operation. This could be an invalid filter or dn.
*
* @author Mattias Arthursson
*/
public class BadLdapGrammarException extends
InvalidDataAccessResourceUsageException {
private static final long serialVersionUID = 961612585331409470L;
public BadLdapGrammarException(String message) {
super(message);
}
public BadLdapGrammarException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,96 @@
/*
* 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;
/**
* 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 InvalidSearchFilterException) {
return new BadLdapGrammarException("Invalid search filter",
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 InvalidAttributesException) {
return new AttributesIntegrityViolationException(
"Invalid attributes", namingException);
}
if (namingException instanceof LimitExceededException) {
return new SearchLimitExceededException("Too many objects found",
namingException);
}
if (namingException instanceof CommunicationException) {
throw new DataRetrievalFailureException(
"Unable to communicate with LDAP server", namingException);
}
// Fallback - other type of NamingException encountered.
return new UncategorizedLdapException("Operation failed",
namingException);
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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);
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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
*
*/
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);
}

View File

@@ -0,0 +1,37 @@
/*
* 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;
/**
* Indicates that the search limit was exceeded in a search.
*
* @author Mattias Arthursson
* @deprecated Should be replaced with the matching mirrored NamingException
*/
public class SearchLimitExceededException extends DataRetrievalFailureException {
private static final long serialVersionUID = 6899885947075235580L;
public SearchLimitExceededException(String msg) {
super(msg);
}
public SearchLimitExceededException(String msg, Throwable cause) {
super(msg, cause);
}
}