From 94fe3e5c83293d73dabbdc1242a1f1cfa4c4fa68 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Mon, 8 Oct 2007 21:54:44 +0000 Subject: [PATCH] Reviewed javadoc. --- .../ldap/support/LdapUtils.java | 330 ++++++++---------- .../ldap/support/ListComparator.java | 72 ++-- 2 files changed, 189 insertions(+), 213 deletions(-) diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/LdapUtils.java b/spring-ldap/src/main/java/org/springframework/ldap/support/LdapUtils.java index 251b169e..507c91c2 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/LdapUtils.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/support/LdapUtils.java @@ -32,186 +32,164 @@ import org.springframework.util.Assert; */ public final class LdapUtils { - private static final Log logger = LogFactory.getLog(LdapUtils.class); + private static final Log logger = LogFactory.getLog(LdapUtils.class); - /** - * Not to be instantiated. - */ - private LdapUtils() { + /** + * Not to be instantiated. + */ + private LdapUtils() { - } + } - /** - * Close the given JNDI Context and ignore any thrown exception. This is - * useful for typical finally blocks in JNDI code. - * - * @param context - * the JNDI Context to close (may be null) - */ - public static void closeContext(DirContext context) { - if (context != null) { - try { - context.close(); - } catch (NamingException ex) { - logger.debug("Could not close JNDI DirContext", ex); - } catch (Throwable ex) { - // We don't trust the JNDI provider: It might throw - // RuntimeException or Error. - logger.debug("Unexpected exception on closing JNDI DirContext", - ex); - } - } - } + /** + * Close the given JNDI Context and ignore any thrown exception. This is + * useful for typical finally blocks in JNDI code. + * + * @param context the JNDI Context to close (may be null) + */ + public static void closeContext(DirContext context) { + if (context != null) { + try { + context.close(); + } + catch (NamingException ex) { + logger.debug("Could not close JNDI DirContext", ex); + } + catch (Throwable ex) { + // We don't trust the JNDI provider: It might throw + // RuntimeException or Error. + logger.debug("Unexpected exception on closing JNDI DirContext", ex); + } + } + } - /** - * Convert the specified checked - * {@link javax.naming.NamingException NamingException} to a Spring LDAP - * runtime {@link org.springframework.ldap.NamingException NamingException} - * equivalent. - * - * @param ex - * the original checked NamingException to convert - * @return the Spring LDAP runtime NamingException wrapping the given - * exception - */ - public static NamingException convertLdapException( - javax.naming.NamingException ex) { - Assert.notNull(ex, "NamingException must not be null"); + /** + * Convert the specified checked + * {@link javax.naming.NamingException NamingException} to a Spring LDAP + * runtime {@link org.springframework.ldap.NamingException NamingException} + * equivalent. + * + * @param ex the original checked NamingException to convert + * @return the Spring LDAP runtime NamingException wrapping the given + * exception + */ + public static NamingException convertLdapException(javax.naming.NamingException ex) { + Assert.notNull(ex, "NamingException must not be null"); - if (ex instanceof javax.naming.directory.AttributeInUseException) { - return new org.springframework.ldap.AttributeInUseException( - (javax.naming.directory.AttributeInUseException) ex); - } - if (ex instanceof javax.naming.directory.AttributeModificationException) { - return new org.springframework.ldap.AttributeModificationException( - (javax.naming.directory.AttributeModificationException) ex); - } - if (ex instanceof javax.naming.AuthenticationException) { - return new org.springframework.ldap.AuthenticationException( - (javax.naming.AuthenticationException) ex); - } - if (ex instanceof javax.naming.AuthenticationNotSupportedException) { - return new org.springframework.ldap.AuthenticationNotSupportedException( - (javax.naming.AuthenticationNotSupportedException) ex); - } - if (ex instanceof javax.naming.CannotProceedException) { - return new org.springframework.ldap.CannotProceedException( - (javax.naming.CannotProceedException) ex); - } - if (ex instanceof javax.naming.CommunicationException) { - return new org.springframework.ldap.CommunicationException( - (javax.naming.CommunicationException) ex); - } - if (ex instanceof javax.naming.ConfigurationException) { - return new org.springframework.ldap.ConfigurationException( - (javax.naming.ConfigurationException) ex); - } - if (ex instanceof javax.naming.ContextNotEmptyException) { - return new org.springframework.ldap.ContextNotEmptyException( - (javax.naming.ContextNotEmptyException) ex); - } - if (ex instanceof javax.naming.InsufficientResourcesException) { - return new org.springframework.ldap.InsufficientResourcesException( - (javax.naming.InsufficientResourcesException) ex); - } - if (ex instanceof javax.naming.InterruptedNamingException) { - return new org.springframework.ldap.InterruptedNamingException( - (javax.naming.InterruptedNamingException) ex); - } - if (ex instanceof javax.naming.directory.InvalidAttributeIdentifierException) { - return new org.springframework.ldap.InvalidAttributeIdentifierException( - (javax.naming.directory.InvalidAttributeIdentifierException) ex); - } - if (ex instanceof javax.naming.directory.InvalidAttributesException) { - return new org.springframework.ldap.InvalidAttributesException( - (javax.naming.directory.InvalidAttributesException) ex); - } - if (ex instanceof javax.naming.directory.InvalidAttributeValueException) { - return new org.springframework.ldap.InvalidAttributeValueException( - (javax.naming.directory.InvalidAttributeValueException) ex); - } - if (ex instanceof javax.naming.InvalidNameException) { - return new org.springframework.ldap.InvalidNameException( - (javax.naming.InvalidNameException) ex); - } - if (ex instanceof javax.naming.directory.InvalidSearchControlsException) { - return new org.springframework.ldap.InvalidSearchControlsException( - (javax.naming.directory.InvalidSearchControlsException) ex); - } - if (ex instanceof javax.naming.directory.InvalidSearchFilterException) { - return new org.springframework.ldap.InvalidSearchFilterException( - (javax.naming.directory.InvalidSearchFilterException) ex); - } - if (ex instanceof javax.naming.ldap.LdapReferralException) { - return new org.springframework.ldap.LdapReferralException( - (javax.naming.ldap.LdapReferralException) ex); - } - if (ex instanceof javax.naming.LimitExceededException) { - return new org.springframework.ldap.LimitExceededException( - (javax.naming.LimitExceededException) ex); - } - if (ex instanceof javax.naming.LinkException) { - return new org.springframework.ldap.LinkException( - (javax.naming.LinkException) ex); - } - if (ex instanceof javax.naming.LinkLoopException) { - return new org.springframework.ldap.LinkLoopException( - (javax.naming.LinkLoopException) ex); - } - if (ex instanceof javax.naming.MalformedLinkException) { - return new org.springframework.ldap.MalformedLinkException( - (javax.naming.MalformedLinkException) ex); - } - if (ex instanceof javax.naming.NameAlreadyBoundException) { - return new org.springframework.ldap.NameAlreadyBoundException( - (javax.naming.NameAlreadyBoundException) ex); - } - if (ex instanceof javax.naming.NameNotFoundException) { - return new org.springframework.ldap.NameNotFoundException( - (javax.naming.NameNotFoundException) ex); - } - if (ex instanceof javax.naming.NoInitialContextException) { - return new org.springframework.ldap.NoInitialContextException( - (javax.naming.NoInitialContextException) ex); - } - if (ex instanceof javax.naming.NoPermissionException) { - return new org.springframework.ldap.NoPermissionException( - (javax.naming.NoPermissionException) ex); - } - if (ex instanceof javax.naming.directory.NoSuchAttributeException) { - return new org.springframework.ldap.NoSuchAttributeException( - (javax.naming.directory.NoSuchAttributeException) ex); - } - if (ex instanceof javax.naming.NotContextException) { - return new org.springframework.ldap.NotContextException( - (javax.naming.NotContextException) ex); - } - if (ex instanceof javax.naming.OperationNotSupportedException) { - return new org.springframework.ldap.OperationNotSupportedException( - (javax.naming.OperationNotSupportedException) ex); - } - if (ex instanceof javax.naming.PartialResultException) { - return new org.springframework.ldap.PartialResultException( - (javax.naming.PartialResultException) ex); - } - if (ex instanceof javax.naming.directory.SchemaViolationException) { - return new org.springframework.ldap.SchemaViolationException( - (javax.naming.directory.SchemaViolationException) ex); - } - if (ex instanceof javax.naming.ServiceUnavailableException) { - return new org.springframework.ldap.ServiceUnavailableException( - (javax.naming.ServiceUnavailableException) ex); - } - if (ex instanceof javax.naming.SizeLimitExceededException) { - return new org.springframework.ldap.SizeLimitExceededException( - (javax.naming.SizeLimitExceededException) ex); - } - if (ex instanceof javax.naming.TimeLimitExceededException) { - return new org.springframework.ldap.TimeLimitExceededException( - (javax.naming.TimeLimitExceededException) ex); - } + if (ex instanceof javax.naming.directory.AttributeInUseException) { + return new org.springframework.ldap.AttributeInUseException( + (javax.naming.directory.AttributeInUseException) ex); + } + if (ex instanceof javax.naming.directory.AttributeModificationException) { + return new org.springframework.ldap.AttributeModificationException( + (javax.naming.directory.AttributeModificationException) ex); + } + if (ex instanceof javax.naming.AuthenticationException) { + return new org.springframework.ldap.AuthenticationException((javax.naming.AuthenticationException) ex); + } + if (ex instanceof javax.naming.AuthenticationNotSupportedException) { + return new org.springframework.ldap.AuthenticationNotSupportedException( + (javax.naming.AuthenticationNotSupportedException) ex); + } + if (ex instanceof javax.naming.CannotProceedException) { + return new org.springframework.ldap.CannotProceedException((javax.naming.CannotProceedException) ex); + } + if (ex instanceof javax.naming.CommunicationException) { + return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex); + } + if (ex instanceof javax.naming.ConfigurationException) { + return new org.springframework.ldap.ConfigurationException((javax.naming.ConfigurationException) ex); + } + if (ex instanceof javax.naming.ContextNotEmptyException) { + return new org.springframework.ldap.ContextNotEmptyException((javax.naming.ContextNotEmptyException) ex); + } + if (ex instanceof javax.naming.InsufficientResourcesException) { + return new org.springframework.ldap.InsufficientResourcesException( + (javax.naming.InsufficientResourcesException) ex); + } + if (ex instanceof javax.naming.InterruptedNamingException) { + return new org.springframework.ldap.InterruptedNamingException((javax.naming.InterruptedNamingException) ex); + } + if (ex instanceof javax.naming.directory.InvalidAttributeIdentifierException) { + return new org.springframework.ldap.InvalidAttributeIdentifierException( + (javax.naming.directory.InvalidAttributeIdentifierException) ex); + } + if (ex instanceof javax.naming.directory.InvalidAttributesException) { + return new org.springframework.ldap.InvalidAttributesException( + (javax.naming.directory.InvalidAttributesException) ex); + } + if (ex instanceof javax.naming.directory.InvalidAttributeValueException) { + return new org.springframework.ldap.InvalidAttributeValueException( + (javax.naming.directory.InvalidAttributeValueException) ex); + } + if (ex instanceof javax.naming.InvalidNameException) { + return new org.springframework.ldap.InvalidNameException((javax.naming.InvalidNameException) ex); + } + if (ex instanceof javax.naming.directory.InvalidSearchControlsException) { + return new org.springframework.ldap.InvalidSearchControlsException( + (javax.naming.directory.InvalidSearchControlsException) ex); + } + if (ex instanceof javax.naming.directory.InvalidSearchFilterException) { + return new org.springframework.ldap.InvalidSearchFilterException( + (javax.naming.directory.InvalidSearchFilterException) ex); + } + if (ex instanceof javax.naming.ldap.LdapReferralException) { + return new org.springframework.ldap.LdapReferralException((javax.naming.ldap.LdapReferralException) ex); + } + if (ex instanceof javax.naming.LimitExceededException) { + return new org.springframework.ldap.LimitExceededException((javax.naming.LimitExceededException) ex); + } + if (ex instanceof javax.naming.LinkException) { + return new org.springframework.ldap.LinkException((javax.naming.LinkException) ex); + } + if (ex instanceof javax.naming.LinkLoopException) { + return new org.springframework.ldap.LinkLoopException((javax.naming.LinkLoopException) ex); + } + if (ex instanceof javax.naming.MalformedLinkException) { + return new org.springframework.ldap.MalformedLinkException((javax.naming.MalformedLinkException) ex); + } + if (ex instanceof javax.naming.NameAlreadyBoundException) { + return new org.springframework.ldap.NameAlreadyBoundException((javax.naming.NameAlreadyBoundException) ex); + } + if (ex instanceof javax.naming.NameNotFoundException) { + return new org.springframework.ldap.NameNotFoundException((javax.naming.NameNotFoundException) ex); + } + if (ex instanceof javax.naming.NoInitialContextException) { + return new org.springframework.ldap.NoInitialContextException((javax.naming.NoInitialContextException) ex); + } + if (ex instanceof javax.naming.NoPermissionException) { + return new org.springframework.ldap.NoPermissionException((javax.naming.NoPermissionException) ex); + } + if (ex instanceof javax.naming.directory.NoSuchAttributeException) { + return new org.springframework.ldap.NoSuchAttributeException( + (javax.naming.directory.NoSuchAttributeException) ex); + } + if (ex instanceof javax.naming.NotContextException) { + return new org.springframework.ldap.NotContextException((javax.naming.NotContextException) ex); + } + if (ex instanceof javax.naming.OperationNotSupportedException) { + return new org.springframework.ldap.OperationNotSupportedException( + (javax.naming.OperationNotSupportedException) ex); + } + if (ex instanceof javax.naming.PartialResultException) { + return new org.springframework.ldap.PartialResultException((javax.naming.PartialResultException) ex); + } + if (ex instanceof javax.naming.directory.SchemaViolationException) { + return new org.springframework.ldap.SchemaViolationException( + (javax.naming.directory.SchemaViolationException) ex); + } + if (ex instanceof javax.naming.ServiceUnavailableException) { + return new org.springframework.ldap.ServiceUnavailableException( + (javax.naming.ServiceUnavailableException) ex); + } + if (ex instanceof javax.naming.SizeLimitExceededException) { + return new org.springframework.ldap.SizeLimitExceededException((javax.naming.SizeLimitExceededException) ex); + } + if (ex instanceof javax.naming.TimeLimitExceededException) { + return new org.springframework.ldap.TimeLimitExceededException((javax.naming.TimeLimitExceededException) ex); + } - // fallback - return new org.springframework.ldap.UncategorizedLdapException(ex); - } + // fallback + return new org.springframework.ldap.UncategorizedLdapException(ex); + } } diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/ListComparator.java b/spring-ldap/src/main/java/org/springframework/ldap/support/ListComparator.java index 5b13ce2a..1e5c9807 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/ListComparator.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/support/ListComparator.java @@ -22,46 +22,44 @@ import java.util.List; * Comparator for comparing lists of Comparable objects. * * @author Mattias Arthursson - * */ public class ListComparator implements Comparator { - /** - * Compare two lists of Comparable objects. - * - * @param o1 - * the first object to be compared. - * @param o2 - * the second object to be compared. - * @throws ClassCastException - * if either of the lists contains an object that is not - * Comparable. - */ - public int compare(Object o1, Object o2) { - List list1 = (List) o1; - List list2 = (List) o2; + /** + * Compare two lists of Comparable objects. + * + * @param o1 the first object to be compared. + * @param o2 the second object to be compared. + * @throws ClassCastException if any of the lists contains an object that + * is not Comparable. + */ + public int compare(Object o1, Object o2) { + List list1 = (List) o1; + List list2 = (List) o2; - for (int i = 0; i < list1.size(); i++) { - if (list2.size() > i) { - Comparable component1 = (Comparable) list1.get(i); - Comparable component2 = (Comparable) list2.get(i); - int componentsCompared = component1.compareTo(component2); - if (componentsCompared != 0) { - return componentsCompared; - } - } else { - // First instance has more components, so that instance is - // greater. - return 1; - } - } + for (int i = 0; i < list1.size(); i++) { + if (list2.size() > i) { + Comparable component1 = (Comparable) list1.get(i); + Comparable component2 = (Comparable) list2.get(i); + int componentsCompared = component1.compareTo(component2); + if (componentsCompared != 0) { + return componentsCompared; + } + } + else { + // First instance has more components, so that instance is + // greater. + return 1; + } + } - // All components so far are equal - if the other instance has - // more components it is greater otherwise they are equal. - if (list2.size() > list1.size()) { - return -1; - } else { - return 0; - } - } + // All components so far are equal - if the other instance has + // more components it is greater otherwise they are equal. + if (list2.size() > list1.size()) { + return -1; + } + else { + return 0; + } + } }