class LdapUtils {

	public static NamingException convertLdapException(javax.naming.NamingException ex) {
		Assert.notNull(ex, "NamingException must not be null");

		if (javax.naming.directory.AttributeInUseException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.AttributeInUseException(
					(javax.naming.directory.AttributeInUseException) ex);
		}
		if (javax.naming.directory.AttributeModificationException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.AttributeModificationException(
					(javax.naming.directory.AttributeModificationException) ex);
		}
		if (javax.naming.CannotProceedException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.CannotProceedException((javax.naming.CannotProceedException) ex);
		}
		if (javax.naming.CommunicationException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.CommunicationException((javax.naming.CommunicationException) ex);
		}
		if (javax.naming.ConfigurationException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.ConfigurationException((javax.naming.ConfigurationException) ex);
		}
		if (javax.naming.ContextNotEmptyException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.ContextNotEmptyException((javax.naming.ContextNotEmptyException) ex);
		}
		if (javax.naming.InsufficientResourcesException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InsufficientResourcesException(
					(javax.naming.InsufficientResourcesException) ex);
		}
		if (javax.naming.InterruptedNamingException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InterruptedNamingException((javax.naming.InterruptedNamingException) ex);
		}
		if (javax.naming.directory.InvalidAttributeIdentifierException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidAttributeIdentifierException(
					(javax.naming.directory.InvalidAttributeIdentifierException) ex);
		}
		if (javax.naming.directory.InvalidAttributesException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidAttributesException(
					(javax.naming.directory.InvalidAttributesException) ex);
		}
		if (javax.naming.directory.InvalidAttributeValueException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidAttributeValueException(
					(javax.naming.directory.InvalidAttributeValueException) ex);
		}
		if (javax.naming.InvalidNameException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidNameException((javax.naming.InvalidNameException) ex);
		}
		if (javax.naming.directory.InvalidSearchControlsException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidSearchControlsException(
					(javax.naming.directory.InvalidSearchControlsException) ex);
		}
		if (javax.naming.directory.InvalidSearchFilterException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.InvalidSearchFilterException(
					(javax.naming.directory.InvalidSearchFilterException) ex);
		}

		if (javax.naming.ldap.LdapReferralException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.LdapReferralException((javax.naming.ldap.LdapReferralException) ex);
		}

        if (javax.naming.ReferralException.class.isAssignableFrom(ex.getClass())) {
            return new org.springframework.ldap.ReferralException((javax.naming.ReferralException) ex);
        }

		// LimitExceededException hierarchy
		if (javax.naming.SizeLimitExceededException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.SizeLimitExceededException((javax.naming.SizeLimitExceededException) ex);
		}
		if (javax.naming.TimeLimitExceededException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.TimeLimitExceededException((javax.naming.TimeLimitExceededException) ex);
		}
		// this class is the superclass of the two above
		if (javax.naming.LimitExceededException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.LimitExceededException((javax.naming.LimitExceededException) ex);
		}

		// LinkException hierarchy
		if (javax.naming.LinkLoopException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.LinkLoopException((javax.naming.LinkLoopException) ex);
		}
		if (javax.naming.MalformedLinkException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.MalformedLinkException((javax.naming.MalformedLinkException) ex);
		}
		// this class is the superclass of the two above
		if (javax.naming.LinkException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.LinkException((javax.naming.LinkException) ex);
		}

		if (javax.naming.NameAlreadyBoundException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NameAlreadyBoundException((javax.naming.NameAlreadyBoundException) ex);
		}
		if (javax.naming.NameNotFoundException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NameNotFoundException((javax.naming.NameNotFoundException) ex);
		}

		// NamingSecurityException hierarchy
		if (javax.naming.NoPermissionException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NoPermissionException((javax.naming.NoPermissionException) ex);
		}
		if (javax.naming.AuthenticationException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.AuthenticationException((javax.naming.AuthenticationException) ex);
		}
		if (javax.naming.AuthenticationNotSupportedException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.AuthenticationNotSupportedException(
					(javax.naming.AuthenticationNotSupportedException) ex);
		}
        if (javax.naming.NamingSecurityException.class.isAssignableFrom(ex.getClass())) {
            return new org.springframework.ldap.NamingSecurityException((javax.naming.NamingSecurityException) ex);
        }

		if (javax.naming.NoInitialContextException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NoInitialContextException((javax.naming.NoInitialContextException) ex);
		}
		if (javax.naming.directory.NoSuchAttributeException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NoSuchAttributeException(
					(javax.naming.directory.NoSuchAttributeException) ex);
		}
		if (javax.naming.NotContextException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.NotContextException((javax.naming.NotContextException) ex);
		}
		if (javax.naming.OperationNotSupportedException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.OperationNotSupportedException(
					(javax.naming.OperationNotSupportedException) ex);
		}
		if (javax.naming.PartialResultException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.PartialResultException((javax.naming.PartialResultException) ex);
		}
		if (javax.naming.directory.SchemaViolationException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.SchemaViolationException(
					(javax.naming.directory.SchemaViolationException) ex);
		}
		if (javax.naming.ServiceUnavailableException.class.isAssignableFrom(ex.getClass())) {
			return new org.springframework.ldap.ServiceUnavailableException(
					(javax.naming.ServiceUnavailableException) ex);
		}

		// fallback
		return new org.springframework.ldap.UncategorizedLdapException(ex);
	}

	private  LdapUtils();

}