Address JavaFormat Violations in Core
Issue gh-743
This commit is contained in:
@@ -33,7 +33,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
*/
|
||||
public abstract class NamingException extends NestedRuntimeException {
|
||||
|
||||
private Throwable cause;
|
||||
private final Throwable cause;
|
||||
|
||||
/**
|
||||
* Overrides {@link NestedRuntimeException#getCause()} since serialization always
|
||||
@@ -47,7 +47,7 @@ public abstract class NamingException extends NestedRuntimeException {
|
||||
// the constructor, we check for the cause being "this" here, as the cause
|
||||
// could still be set to "this" via reflection: for example, by a remoting
|
||||
// deserializer like Hessian's.
|
||||
return (this.cause == this ? null : this.cause);
|
||||
return (this.cause != this) ? this.cause : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,6 +56,7 @@ public abstract class NamingException extends NestedRuntimeException {
|
||||
*/
|
||||
public NamingException(String msg) {
|
||||
super(msg);
|
||||
this.cause = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +77,7 @@ public abstract class NamingException extends NestedRuntimeException {
|
||||
* a proper subclass of {@link javax.naming.NamingException}.
|
||||
*/
|
||||
public NamingException(Throwable cause) {
|
||||
this(cause != null ? cause.getMessage() : null, cause);
|
||||
this((cause != null) ? cause.getMessage() : null, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,10 +40,6 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
import static org.springframework.ldap.config.ParserUtils.getBoolean;
|
||||
import static org.springframework.ldap.config.ParserUtils.getInt;
|
||||
import static org.springframework.ldap.config.ParserUtils.getString;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Eddu Melendez
|
||||
@@ -184,12 +180,12 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
.setFactoryMethod("urls").addConstructorArgValue(url);
|
||||
|
||||
builder.addPropertyValue("urls", urlsBuilder.getBeanDefinition());
|
||||
builder.addPropertyValue("base", getString(element, ATT_BASE, ""));
|
||||
builder.addPropertyValue("referral", getString(element, ATT_REFERRAL, null));
|
||||
builder.addPropertyValue("base", ParserUtils.getString(element, ATT_BASE, ""));
|
||||
builder.addPropertyValue("referral", ParserUtils.getString(element, ATT_REFERRAL, null));
|
||||
|
||||
boolean anonymousReadOnly = getBoolean(element, ATT_ANONYMOUS_READ_ONLY, false);
|
||||
boolean anonymousReadOnly = ParserUtils.getBoolean(element, ATT_ANONYMOUS_READ_ONLY, false);
|
||||
builder.addPropertyValue("anonymousReadOnly", anonymousReadOnly);
|
||||
boolean nativePooling = getBoolean(element, ATT_NATIVE_POOLING, false);
|
||||
boolean nativePooling = ParserUtils.getBoolean(element, ATT_NATIVE_POOLING, false);
|
||||
builder.addPropertyValue("pooled", nativePooling);
|
||||
|
||||
String authStrategyRef = element.getAttribute(ATT_AUTHENTICATION_STRATEGY_REF);
|
||||
@@ -224,7 +220,7 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
actualContextSourceDefinition = proxyBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
String id = ParserUtils.getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(actualContextSourceDefinition, id));
|
||||
|
||||
return actualContextSourceDefinition;
|
||||
@@ -255,10 +251,10 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
|
||||
populatePoolConfigProperties(builder, pooling2Element);
|
||||
|
||||
boolean testOnBorrow = getBoolean(pooling2Element, ATT_TEST_ON_BORROW, false);
|
||||
boolean testOnReturn = getBoolean(pooling2Element, ATT_TEST_ON_RETURN, false);
|
||||
boolean testWhileIdle = getBoolean(pooling2Element, ATT_TEST_WHILE_IDLE, false);
|
||||
boolean testOnCreate = getBoolean(pooling2Element, ATT_TEST_ON_CREATE, false);
|
||||
boolean testOnBorrow = ParserUtils.getBoolean(pooling2Element, ATT_TEST_ON_BORROW, false);
|
||||
boolean testOnReturn = ParserUtils.getBoolean(pooling2Element, ATT_TEST_ON_RETURN, false);
|
||||
boolean testWhileIdle = ParserUtils.getBoolean(pooling2Element, ATT_TEST_WHILE_IDLE, false);
|
||||
boolean testOnCreate = ParserUtils.getBoolean(pooling2Element, ATT_TEST_ON_CREATE, false);
|
||||
|
||||
if (testOnBorrow || testOnCreate || testWhileIdle || testOnReturn) {
|
||||
populatePoolValidationProperties(builder, pooling2Element);
|
||||
@@ -271,27 +267,28 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
builder.addPropertyValue("contextSource", targetContextSourceDefinition);
|
||||
|
||||
builder.addPropertyValue("maxActive",
|
||||
getString(poolingElement, ATT_MAX_ACTIVE, String.valueOf(DEFAULT_MAX_ACTIVE)));
|
||||
ParserUtils.getString(poolingElement, ATT_MAX_ACTIVE, String.valueOf(DEFAULT_MAX_ACTIVE)));
|
||||
builder.addPropertyValue("maxTotal",
|
||||
getString(poolingElement, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
|
||||
ParserUtils.getString(poolingElement, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
|
||||
builder.addPropertyValue("maxIdle",
|
||||
getString(poolingElement, ATT_MAX_IDLE, String.valueOf(DEFAULT_MAX_IDLE)));
|
||||
ParserUtils.getString(poolingElement, ATT_MAX_IDLE, String.valueOf(DEFAULT_MAX_IDLE)));
|
||||
builder.addPropertyValue("minIdle",
|
||||
getString(poolingElement, ATT_MIN_IDLE, String.valueOf(DEFAULT_MIN_IDLE)));
|
||||
ParserUtils.getString(poolingElement, ATT_MIN_IDLE, String.valueOf(DEFAULT_MIN_IDLE)));
|
||||
builder.addPropertyValue("maxWait",
|
||||
getString(poolingElement, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT)));
|
||||
String whenExhausted = getString(poolingElement, ATT_WHEN_EXHAUSTED, PoolExhaustedAction.BLOCK.name());
|
||||
ParserUtils.getString(poolingElement, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT)));
|
||||
String whenExhausted = ParserUtils.getString(poolingElement, ATT_WHEN_EXHAUSTED,
|
||||
PoolExhaustedAction.BLOCK.name());
|
||||
builder.addPropertyValue("whenExhaustedAction", PoolExhaustedAction.valueOf(whenExhausted).getValue());
|
||||
builder.addPropertyValue("timeBetweenEvictionRunsMillis",
|
||||
getString(poolingElement, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
builder.addPropertyValue("minEvictableIdleTimeMillis",
|
||||
getString(poolingElement, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
builder.addPropertyValue("numTestsPerEvictionRun", getString(poolingElement, ATT_TESTS_PER_EVICTION_RUN,
|
||||
String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));
|
||||
builder.addPropertyValue("timeBetweenEvictionRunsMillis", ParserUtils.getString(poolingElement,
|
||||
ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
builder.addPropertyValue("minEvictableIdleTimeMillis", ParserUtils.getString(poolingElement,
|
||||
ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
builder.addPropertyValue("numTestsPerEvictionRun", ParserUtils.getString(poolingElement,
|
||||
ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));
|
||||
|
||||
boolean testOnBorrow = getBoolean(poolingElement, ATT_TEST_ON_BORROW, false);
|
||||
boolean testOnReturn = getBoolean(poolingElement, ATT_TEST_ON_RETURN, false);
|
||||
boolean testWhileIdle = getBoolean(poolingElement, ATT_TEST_WHILE_IDLE, false);
|
||||
boolean testOnBorrow = ParserUtils.getBoolean(poolingElement, ATT_TEST_ON_BORROW, false);
|
||||
boolean testOnReturn = ParserUtils.getBoolean(poolingElement, ATT_TEST_ON_RETURN, false);
|
||||
boolean testWhileIdle = ParserUtils.getBoolean(poolingElement, ATT_TEST_WHILE_IDLE, false);
|
||||
|
||||
if (testOnBorrow || testOnReturn || testWhileIdle) {
|
||||
populatePoolValidationProperties(builder, poolingElement, testOnBorrow, testOnReturn, testWhileIdle);
|
||||
@@ -310,9 +307,9 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
|
||||
BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(DefaultDirContextValidator.class);
|
||||
validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, ""));
|
||||
validatorBuilder.addPropertyValue("base", ParserUtils.getString(element, ATT_VALIDATION_QUERY_BASE, ""));
|
||||
validatorBuilder.addPropertyValue("filter",
|
||||
getString(element, ATT_VALIDATION_QUERY_FILTER, DefaultDirContextValidator.DEFAULT_FILTER));
|
||||
ParserUtils.getString(element, ATT_VALIDATION_QUERY_FILTER, DefaultDirContextValidator.DEFAULT_FILTER));
|
||||
String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF);
|
||||
if (StringUtils.hasText(searchControlsRef)) {
|
||||
validatorBuilder.addPropertyReference("searchControls", searchControlsRef);
|
||||
@@ -320,13 +317,13 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition());
|
||||
|
||||
builder.addPropertyValue("timeBetweenEvictionRunsMillis",
|
||||
getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
ParserUtils.getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
builder.addPropertyValue("numTestsPerEvictionRun",
|
||||
getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN));
|
||||
ParserUtils.getInt(element, ATT_TESTS_PER_EVICTION_RUN, DEFAULT_TESTS_PER_EVICTION_RUN));
|
||||
builder.addPropertyValue("minEvictableIdleTimeMillis",
|
||||
getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
ParserUtils.getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
|
||||
String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS,
|
||||
String nonTransientExceptions = ParserUtils.getString(element, ATT_NON_TRANSIENT_EXCEPTIONS,
|
||||
CommunicationException.class.getName());
|
||||
String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions);
|
||||
Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>();
|
||||
@@ -334,8 +331,8 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
try {
|
||||
nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className));
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e);
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,8 +343,8 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
|
||||
BeanDefinitionBuilder validatorBuilder = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(org.springframework.ldap.pool2.validation.DefaultDirContextValidator.class);
|
||||
validatorBuilder.addPropertyValue("base", getString(element, ATT_VALIDATION_QUERY_BASE, ""));
|
||||
validatorBuilder.addPropertyValue("filter", getString(element, ATT_VALIDATION_QUERY_FILTER,
|
||||
validatorBuilder.addPropertyValue("base", ParserUtils.getString(element, ATT_VALIDATION_QUERY_BASE, ""));
|
||||
validatorBuilder.addPropertyValue("filter", ParserUtils.getString(element, ATT_VALIDATION_QUERY_FILTER,
|
||||
org.springframework.ldap.pool2.validation.DefaultDirContextValidator.DEFAULT_FILTER));
|
||||
String searchControlsRef = element.getAttribute(ATT_VALIDATION_QUERY_SEARCH_CONTROLS_REF);
|
||||
if (StringUtils.hasText(searchControlsRef)) {
|
||||
@@ -355,7 +352,7 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
}
|
||||
builder.addPropertyValue("dirContextValidator", validatorBuilder.getBeanDefinition());
|
||||
|
||||
String nonTransientExceptions = getString(element, ATT_NON_TRANSIENT_EXCEPTIONS,
|
||||
String nonTransientExceptions = ParserUtils.getString(element, ATT_NON_TRANSIENT_EXCEPTIONS,
|
||||
CommunicationException.class.getName());
|
||||
String[] strings = StringUtils.commaDelimitedListToStringArray(nonTransientExceptions);
|
||||
Set<Class<?>> nonTransientExceptionClasses = new HashSet<Class<?>>();
|
||||
@@ -363,8 +360,8 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
try {
|
||||
nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className));
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e);
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,36 +372,38 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
BeanDefinitionBuilder configBuilder = BeanDefinitionBuilder.rootBeanDefinition(PoolConfig.class);
|
||||
|
||||
configBuilder.addPropertyValue("maxTotal",
|
||||
getString(element, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
|
||||
ParserUtils.getString(element, ATT_MAX_TOTAL, String.valueOf(DEFAULT_MAX_TOTAL)));
|
||||
configBuilder.addPropertyValue("maxTotalPerKey",
|
||||
getString(element, ATT_MAX_TOTAL_PER_KEY, String.valueOf(DEFAULT_MAX_TOTAL_PER_KEY)));
|
||||
ParserUtils.getString(element, ATT_MAX_TOTAL_PER_KEY, String.valueOf(DEFAULT_MAX_TOTAL_PER_KEY)));
|
||||
configBuilder.addPropertyValue("maxIdlePerKey",
|
||||
getString(element, ATT_MAX_IDLE_PER_KEY, String.valueOf(DEFAULT_MAX_IDLE_PER_KEY)));
|
||||
ParserUtils.getString(element, ATT_MAX_IDLE_PER_KEY, String.valueOf(DEFAULT_MAX_IDLE_PER_KEY)));
|
||||
configBuilder.addPropertyValue("minIdlePerKey",
|
||||
getString(element, ATT_MIN_IDLE_PER_KEY, String.valueOf(DEFAULT_MIN_IDLE_PER_KEY)));
|
||||
ParserUtils.getString(element, ATT_MIN_IDLE_PER_KEY, String.valueOf(DEFAULT_MIN_IDLE_PER_KEY)));
|
||||
configBuilder.addPropertyValue("evictionPolicyClassName",
|
||||
getString(element, ATT_EVICTION_POLICY_CLASS, DEFAULT_EVICTION_POLICY_CLASS_NAME));
|
||||
configBuilder.addPropertyValue("fairness", getBoolean(element, ATT_FAIRNESS, DEFAULT_FAIRNESS));
|
||||
configBuilder.addPropertyValue("jmxEnabled", getBoolean(element, ATT_JMX_ENABLE, DEFAULT_JMX_ENABLE));
|
||||
configBuilder.addPropertyValue("jmxNameBase", getString(element, ATT_JMX_NAME_BASE, DEFAULT_JMX_NAME_BASE));
|
||||
ParserUtils.getString(element, ATT_EVICTION_POLICY_CLASS, DEFAULT_EVICTION_POLICY_CLASS_NAME));
|
||||
configBuilder.addPropertyValue("fairness", ParserUtils.getBoolean(element, ATT_FAIRNESS, DEFAULT_FAIRNESS));
|
||||
configBuilder.addPropertyValue("jmxEnabled",
|
||||
ParserUtils.getBoolean(element, ATT_JMX_ENABLE, DEFAULT_JMX_ENABLE));
|
||||
configBuilder.addPropertyValue("jmxNameBase",
|
||||
ParserUtils.getString(element, ATT_JMX_NAME_BASE, DEFAULT_JMX_NAME_BASE));
|
||||
configBuilder.addPropertyValue("jmxNamePrefix",
|
||||
getString(element, ATT_JMX_NAME_PREFIX, DEFAULT_JMX_NAME_PREFIX));
|
||||
configBuilder.addPropertyValue("lifo", getBoolean(element, ATT_LIFO, DEFAULT_LIFO));
|
||||
ParserUtils.getString(element, ATT_JMX_NAME_PREFIX, DEFAULT_JMX_NAME_PREFIX));
|
||||
configBuilder.addPropertyValue("lifo", ParserUtils.getBoolean(element, ATT_LIFO, DEFAULT_LIFO));
|
||||
configBuilder.addPropertyValue("maxWaitMillis",
|
||||
getString(element, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT_MILLIS)));
|
||||
configBuilder.addPropertyValue("blockWhenExhausted", Boolean
|
||||
.valueOf(getString(element, ATT_BLOCK_WHEN_EXHAUSTED, String.valueOf(DEFAULT_BLOCK_WHEN_EXHAUSTED))));
|
||||
configBuilder.addPropertyValue("testOnBorrow", getBoolean(element, ATT_TEST_ON_BORROW, false));
|
||||
configBuilder.addPropertyValue("testOnCreate", getBoolean(element, ATT_TEST_ON_CREATE, false));
|
||||
configBuilder.addPropertyValue("testOnReturn", getBoolean(element, ATT_TEST_ON_RETURN, false));
|
||||
configBuilder.addPropertyValue("testWhileIdle", getBoolean(element, ATT_TEST_WHILE_IDLE, false));
|
||||
ParserUtils.getString(element, ATT_MAX_WAIT, String.valueOf(DEFAULT_MAX_WAIT_MILLIS)));
|
||||
configBuilder.addPropertyValue("blockWhenExhausted", Boolean.valueOf(ParserUtils.getString(element,
|
||||
ATT_BLOCK_WHEN_EXHAUSTED, String.valueOf(DEFAULT_BLOCK_WHEN_EXHAUSTED))));
|
||||
configBuilder.addPropertyValue("testOnBorrow", ParserUtils.getBoolean(element, ATT_TEST_ON_BORROW, false));
|
||||
configBuilder.addPropertyValue("testOnCreate", ParserUtils.getBoolean(element, ATT_TEST_ON_CREATE, false));
|
||||
configBuilder.addPropertyValue("testOnReturn", ParserUtils.getBoolean(element, ATT_TEST_ON_RETURN, false));
|
||||
configBuilder.addPropertyValue("testWhileIdle", ParserUtils.getBoolean(element, ATT_TEST_WHILE_IDLE, false));
|
||||
configBuilder.addPropertyValue("timeBetweenEvictionRunsMillis",
|
||||
getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
configBuilder.addPropertyValue("numTestsPerEvictionRun",
|
||||
getString(element, ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));
|
||||
ParserUtils.getString(element, ATT_EVICTION_RUN_MILLIS, String.valueOf(DEFAULT_EVICTION_RUN_MILLIS)));
|
||||
configBuilder.addPropertyValue("numTestsPerEvictionRun", ParserUtils.getString(element,
|
||||
ATT_TESTS_PER_EVICTION_RUN, String.valueOf(DEFAULT_TESTS_PER_EVICTION_RUN)));
|
||||
configBuilder.addPropertyValue("minEvictableIdleTimeMillis",
|
||||
getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
configBuilder.addPropertyValue("softMinEvictableIdleTimeMillis", getString(element,
|
||||
ParserUtils.getString(element, ATT_EVICTABLE_TIME_MILLIS, String.valueOf(DEFAULT_EVICTABLE_MILLIS)));
|
||||
configBuilder.addPropertyValue("softMinEvictableIdleTimeMillis", ParserUtils.getString(element,
|
||||
ATT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS, String.valueOf(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS)));
|
||||
|
||||
builder.addConstructorArgValue(configBuilder.getBeanDefinition());
|
||||
@@ -412,9 +411,11 @@ public class ContextSourceParser implements BeanDefinitionParser {
|
||||
|
||||
static class UrlsFactory {
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
public static String[] urls(String value) {
|
||||
return StringUtils.commaDelimitedListToStringArray(value);
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.ldap.transaction.compensating.support.DefaultTempEntryRenamingStrategy;
|
||||
|
||||
import static org.springframework.ldap.config.ParserUtils.getString;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@@ -40,7 +38,7 @@ public class DefaultRenamingStrategyParser implements BeanDefinitionParser {
|
||||
.rootBeanDefinition(DefaultTempEntryRenamingStrategy.class);
|
||||
|
||||
builder.addPropertyValue("tempSuffix",
|
||||
getString(element, ATT_TEMP_SUFFIX, DefaultTempEntryRenamingStrategy.DEFAULT_TEMP_SUFFIX));
|
||||
ParserUtils.getString(element, ATT_TEMP_SUFFIX, DefaultTempEntryRenamingStrategy.DEFAULT_TEMP_SUFFIX));
|
||||
|
||||
AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
parserContext.getContainingBeanDefinition().getPropertyValues().addPropertyValue("renamingStrategy",
|
||||
|
||||
@@ -28,10 +28,6 @@ import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.query.SearchScope;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.springframework.ldap.config.ParserUtils.getBoolean;
|
||||
import static org.springframework.ldap.config.ParserUtils.getInt;
|
||||
import static org.springframework.ldap.config.ParserUtils.getString;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@@ -61,22 +57,26 @@ public class LdapTemplateParser implements BeanDefinitionParser {
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(LdapTemplate.class);
|
||||
|
||||
String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID);
|
||||
String contextSourceRef = ParserUtils.getString(element, ATT_CONTEXT_SOURCE_REF,
|
||||
ContextSourceParser.DEFAULT_ID);
|
||||
builder.addPropertyReference("contextSource", contextSourceRef);
|
||||
builder.addPropertyValue("defaultCountLimit", getInt(element, ATT_COUNT_LIMIT, DEFAULT_COUNT_LIMIT));
|
||||
builder.addPropertyValue("defaultTimeLimit", getInt(element, ATT_TIME_LIMIT, DEFAULT_TIME_LIMIT));
|
||||
builder.addPropertyValue("defaultCountLimit",
|
||||
ParserUtils.getInt(element, ATT_COUNT_LIMIT, DEFAULT_COUNT_LIMIT));
|
||||
builder.addPropertyValue("defaultTimeLimit", ParserUtils.getInt(element, ATT_TIME_LIMIT, DEFAULT_TIME_LIMIT));
|
||||
|
||||
String searchScope = getString(element, ATT_SEARCH_SCOPE, SearchScope.SUBTREE.toString());
|
||||
String searchScope = ParserUtils.getString(element, ATT_SEARCH_SCOPE, SearchScope.SUBTREE.toString());
|
||||
builder.addPropertyValue("defaultSearchScope", SearchScope.valueOf(searchScope).getId());
|
||||
builder.addPropertyValue("ignorePartialResultException", getBoolean(element, ATT_IGNORE_PARTIAL_RESULT, false));
|
||||
builder.addPropertyValue("ignoreNameNotFoundException", getBoolean(element, ATT_IGNORE_NAME_NOT_FOUND, false));
|
||||
builder.addPropertyValue("ignorePartialResultException",
|
||||
ParserUtils.getBoolean(element, ATT_IGNORE_PARTIAL_RESULT, false));
|
||||
builder.addPropertyValue("ignoreNameNotFoundException",
|
||||
ParserUtils.getBoolean(element, ATT_IGNORE_NAME_NOT_FOUND, false));
|
||||
|
||||
String odmRef = element.getAttribute(ATT_ODM_REF);
|
||||
if (StringUtils.hasText(odmRef)) {
|
||||
builder.addPropertyReference("objectDirectoryMapper", odmRef);
|
||||
}
|
||||
|
||||
String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
String id = ParserUtils.getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));
|
||||
|
||||
@@ -33,8 +33,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
|
||||
import static org.springframework.ldap.config.ParserUtils.getString;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@@ -55,7 +53,8 @@ public class TransactionManagerParser implements BeanDefinitionParser {
|
||||
@Override
|
||||
public BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||
|
||||
String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID);
|
||||
String contextSourceRef = ParserUtils.getString(element, ATT_CONTEXT_SOURCE_REF,
|
||||
ContextSourceParser.DEFAULT_ID);
|
||||
String dataSourceRef = element.getAttribute(ATT_DATA_SOURCE_REF);
|
||||
String sessionFactoryRef = element.getAttribute(ATT_SESSION_FACTORY_REF);
|
||||
|
||||
@@ -92,7 +91,7 @@ public class TransactionManagerParser implements BeanDefinitionParser {
|
||||
builder.addPropertyValue("renamingStrategy", parseDifferentSubtreeRenamingStrategy(differentSubtreeChild));
|
||||
}
|
||||
|
||||
String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
String id = ParserUtils.getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);
|
||||
|
||||
BeanDefinition beanDefinition = builder.getBeanDefinition();
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));
|
||||
@@ -117,7 +116,7 @@ public class TransactionManagerParser implements BeanDefinitionParser {
|
||||
.rootBeanDefinition(DefaultTempEntryRenamingStrategy.class);
|
||||
|
||||
builder.addPropertyValue("tempSuffix",
|
||||
getString(element, ATT_TEMP_SUFFIX, DefaultTempEntryRenamingStrategy.DEFAULT_TEMP_SUFFIX));
|
||||
ParserUtils.getString(element, ATT_TEMP_SUFFIX, DefaultTempEntryRenamingStrategy.DEFAULT_TEMP_SUFFIX));
|
||||
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
this.requestControlClass = Class.forName(this.defaultRequestControl);
|
||||
this.responseControlClass = Class.forName(this.defaultResponseControl);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
this.log.debug("Default control classes not found - falling back to LdapBP classes", e);
|
||||
catch (ClassNotFoundException ex) {
|
||||
this.log.debug("Default control classes not found - falling back to LdapBP classes", ex);
|
||||
|
||||
try {
|
||||
this.requestControlClass = Class.forName(this.fallbackRequestControl);
|
||||
@@ -119,7 +119,7 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
}
|
||||
catch (ClassNotFoundException e1) {
|
||||
throw new UncategorizedLdapException(
|
||||
"Neither default nor fallback classes are available - unable to proceed", e);
|
||||
"Neither default nor fallback classes are available - unable to proceed", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,8 +165,8 @@ public abstract class AbstractFallbackRequestAndResponseControlDirContextProcess
|
||||
try {
|
||||
result = (Control) constructor.newInstance(params);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ReflectionUtils.handleReflectionException(e);
|
||||
catch (Exception ex) {
|
||||
ReflectionUtils.handleReflectionException(ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -60,25 +60,29 @@ public class PagedResult {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PagedResult that = (PagedResult) o;
|
||||
|
||||
if (this.cookie != null ? !this.cookie.equals(that.cookie) : that.cookie != null)
|
||||
if ((this.cookie != null) ? !this.cookie.equals(that.cookie) : that.cookie != null) {
|
||||
return false;
|
||||
if (this.resultList != null ? !this.resultList.equals(that.resultList) : that.resultList != null)
|
||||
}
|
||||
if ((this.resultList != null) ? !this.resultList.equals(that.resultList) : that.resultList != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.resultList != null ? this.resultList.hashCode() : 0;
|
||||
result = 31 * result + (this.cookie != null ? this.cookie.hashCode() : 0);
|
||||
int result = (this.resultList != null) ? this.resultList.hashCode() : 0;
|
||||
result = 31 * result + ((this.cookie != null) ? this.cookie.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,22 +59,25 @@ public class PagedResultsCookie {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PagedResultsCookie that = (PagedResultsCookie) o;
|
||||
|
||||
if (!Arrays.equals(this.cookie, that.cookie))
|
||||
if (!Arrays.equals(this.cookie, that.cookie)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.cookie != null ? Arrays.hashCode(this.cookie) : 0;
|
||||
return (this.cookie != null) ? Arrays.hashCode(this.cookie) : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ public class PagedResultsRequestControl extends AbstractRequestControlDirContext
|
||||
this.requestControlClass = Class.forName(DEFAULT_REQUEST_CONTROL);
|
||||
this.responseControlClass = Class.forName(DEFAULT_RESPONSE_CONTROL);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
this.log.debug("Default control classes not found - falling back to LdapBP classes", e);
|
||||
catch (ClassNotFoundException ex) {
|
||||
this.log.debug("Default control classes not found - falling back to LdapBP classes", ex);
|
||||
|
||||
try {
|
||||
this.requestControlClass = Class.forName(LDAPBP_REQUEST_CONTROL);
|
||||
@@ -102,7 +102,7 @@ public class PagedResultsRequestControl extends AbstractRequestControlDirContext
|
||||
}
|
||||
catch (ClassNotFoundException e1) {
|
||||
throw new UncategorizedLdapException(
|
||||
"Neither default nor fallback classes are available - unable to proceed", e);
|
||||
"Neither default nor fallback classes are available - unable to proceed", ex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,8 +166,8 @@ public class PagedResultsRequestControl extends AbstractRequestControlDirContext
|
||||
try {
|
||||
result = (Control) constructor.newInstance(this.pageSize, actualCookie, this.critical);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ReflectionUtils.handleReflectionException(e);
|
||||
catch (Exception ex) {
|
||||
ReflectionUtils.handleReflectionException(ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -59,9 +59,9 @@ public class AttributesMapperCallbackHandler<T> extends CollectingNameClassPairC
|
||||
try {
|
||||
return this.mapper.mapFromAttributes(attributes);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,4 @@ public final class CollectingAuthenticationErrorCallback implements Authenticati
|
||||
return this.error != null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +65,4 @@ public class ContextMapperCallbackHandler<T> extends CollectingNameClassPairCall
|
||||
return this.mapper.mapFromContext(object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,4 +61,4 @@ public interface ContextSource {
|
||||
*/
|
||||
DirContext getContext(String principal, String credentials) throws NamingException;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +182,192 @@ class DefaultLdapClient implements LdapClient {
|
||||
this.ignoreSizeLimitExceededException = ignoreSizeLimitExceededException;
|
||||
}
|
||||
|
||||
<T> T computeWithReadOnlyContext(ContextExecutor<T> executor) {
|
||||
DirContext context = this.contextSource.getReadOnlyContext();
|
||||
try {
|
||||
return executor.executeWithContext(context);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
this.namingExceptionHandler.accept(ex);
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
closeContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
void runWithReadWriteContext(ContextRunnable runnable) {
|
||||
DirContext context = this.contextSource.getReadWriteContext();
|
||||
try {
|
||||
runnable.run(context);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
this.namingExceptionHandler.accept(ex);
|
||||
}
|
||||
finally {
|
||||
closeContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> NamingExceptionFunction<? extends Binding, T> function(ContextMapper<T> mapper) {
|
||||
return (result) -> mapper.mapFromContext(result.getObject());
|
||||
}
|
||||
|
||||
private <T> NamingExceptionFunction<? extends SearchResult, T> function(AttributesMapper<T> mapper) {
|
||||
return (result) -> mapper.mapFromAttributes(result.getAttributes());
|
||||
}
|
||||
|
||||
private <T> Enumeration<T> enumeration(NamingEnumeration<T> enumeration) {
|
||||
return new Enumeration<>() {
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
try {
|
||||
return enumeration.hasMore();
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
DefaultLdapClient.this.namingExceptionHandler.accept(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T nextElement() {
|
||||
try {
|
||||
return enumeration.next();
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
DefaultLdapClient.this.namingExceptionHandler.accept(ex);
|
||||
throw new NoSuchElementException("no such element", ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final Consumer<NamingException> namingExceptionHandler = (ex) -> {
|
||||
if (ex instanceof NameNotFoundException) {
|
||||
if (!this.ignoreNameNotFoundException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.warn("Base context not found, ignoring: " + ex.getMessage());
|
||||
return;
|
||||
}
|
||||
if (ex instanceof PartialResultException) {
|
||||
// Workaround for AD servers not handling referrals correctly.
|
||||
if (!this.ignorePartialResultException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.debug("PartialResultException encountered and ignored", ex);
|
||||
return;
|
||||
}
|
||||
if (ex instanceof SizeLimitExceededException) {
|
||||
if (!this.ignoreSizeLimitExceededException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.debug("SizeLimitExceededException encountered and ignored", ex);
|
||||
return;
|
||||
}
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
};
|
||||
|
||||
private <S extends NameClassPair, T> T toObject(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
try {
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
if (!enumeration.hasMoreElements()) {
|
||||
return null;
|
||||
}
|
||||
T result = function.apply(enumeration.nextElement());
|
||||
if (enumeration.hasMoreElements()) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(results);
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends NameClassPair, T> List<T> toList(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
if (results == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
try {
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
List<T> mapped = new ArrayList<>();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
T result = function.apply(enumeration.nextElement());
|
||||
if (result != null) {
|
||||
mapped.add(result);
|
||||
}
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(results);
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends NameClassPair, T> Stream<T> toStream(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
if (results == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
return StreamSupport
|
||||
.stream(Spliterators.spliteratorUnknownSize(enumeration.asIterator(), Spliterator.ORDERED), false)
|
||||
.map(function::apply).filter(Objects::nonNull).onClose(() -> closeNamingEnumeration(results));
|
||||
}
|
||||
|
||||
private void closeContext(DirContext ctx) {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void closeNamingEnumeration(NamingEnumeration<T> results) {
|
||||
if (results != null) {
|
||||
try {
|
||||
results.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ContextRunnable {
|
||||
|
||||
void run(DirContext ctx) throws NamingException;
|
||||
|
||||
}
|
||||
|
||||
interface NamingExceptionFunction<S, T> {
|
||||
|
||||
T apply(S element) throws NamingException;
|
||||
|
||||
default Function<S, T> wrap(Consumer<NamingException> handler) {
|
||||
return (s) -> {
|
||||
try {
|
||||
return apply(s);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
handler.accept(ex);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final class DefaultListSpec implements ListSpec {
|
||||
|
||||
private final Name name;
|
||||
@@ -475,12 +661,12 @@ class DefaultLdapClient implements LdapClient {
|
||||
runWithReadWriteContext((ctx) -> ctx.modifyAttributes(this.name, this.items));
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
catch (Throwable th) {
|
||||
if (renamed) {
|
||||
// attempt to change the name back
|
||||
runWithReadWriteContext((ctx) -> ctx.rename(this.name, this.entry.getDn()));
|
||||
}
|
||||
throw t;
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,190 +719,4 @@ class DefaultLdapClient implements LdapClient {
|
||||
|
||||
}
|
||||
|
||||
<T> T computeWithReadOnlyContext(ContextExecutor<T> executor) {
|
||||
DirContext context = this.contextSource.getReadOnlyContext();
|
||||
try {
|
||||
return executor.executeWithContext(context);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
this.namingExceptionHandler.accept(ex);
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
closeContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
void runWithReadWriteContext(ContextRunnable runnable) {
|
||||
DirContext context = this.contextSource.getReadWriteContext();
|
||||
try {
|
||||
runnable.run(context);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
this.namingExceptionHandler.accept(ex);
|
||||
}
|
||||
finally {
|
||||
closeContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> NamingExceptionFunction<? extends Binding, T> function(ContextMapper<T> mapper) {
|
||||
return (result) -> mapper.mapFromContext(result.getObject());
|
||||
}
|
||||
|
||||
private <T> NamingExceptionFunction<? extends SearchResult, T> function(AttributesMapper<T> mapper) {
|
||||
return (result) -> mapper.mapFromAttributes(result.getAttributes());
|
||||
}
|
||||
|
||||
private <T> Enumeration<T> enumeration(NamingEnumeration<T> enumeration) {
|
||||
return new Enumeration<>() {
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
try {
|
||||
return enumeration.hasMore();
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
DefaultLdapClient.this.namingExceptionHandler.accept(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T nextElement() {
|
||||
try {
|
||||
return enumeration.next();
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
DefaultLdapClient.this.namingExceptionHandler.accept(ex);
|
||||
throw new NoSuchElementException("no such element", ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final Consumer<NamingException> namingExceptionHandler = (ex) -> {
|
||||
if (ex instanceof NameNotFoundException) {
|
||||
if (!this.ignoreNameNotFoundException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.warn("Base context not found, ignoring: " + ex.getMessage());
|
||||
return;
|
||||
}
|
||||
if (ex instanceof PartialResultException) {
|
||||
// Workaround for AD servers not handling referrals correctly.
|
||||
if (!this.ignorePartialResultException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.debug("PartialResultException encountered and ignored", ex);
|
||||
return;
|
||||
}
|
||||
if (ex instanceof SizeLimitExceededException) {
|
||||
if (!this.ignoreSizeLimitExceededException) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
this.logger.debug("SizeLimitExceededException encountered and ignored", ex);
|
||||
return;
|
||||
}
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
};
|
||||
|
||||
private <S extends NameClassPair, T> T toObject(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
try {
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
if (!enumeration.hasMoreElements()) {
|
||||
return null;
|
||||
}
|
||||
T result = function.apply(enumeration.nextElement());
|
||||
if (enumeration.hasMoreElements()) {
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(results);
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends NameClassPair, T> List<T> toList(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
if (results == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
try {
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
List<T> mapped = new ArrayList<>();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
T result = function.apply(enumeration.nextElement());
|
||||
if (result != null) {
|
||||
mapped.add(result);
|
||||
}
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(results);
|
||||
}
|
||||
}
|
||||
|
||||
private <S extends NameClassPair, T> Stream<T> toStream(NamingEnumeration<S> results,
|
||||
NamingExceptionFunction<? super S, T> mapper) {
|
||||
if (results == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
Enumeration<S> enumeration = enumeration(results);
|
||||
Function<? super S, T> function = mapper.wrap(this.namingExceptionHandler);
|
||||
return StreamSupport
|
||||
.stream(Spliterators.spliteratorUnknownSize(enumeration.asIterator(), Spliterator.ORDERED), false)
|
||||
.map(function::apply).filter(Objects::nonNull).onClose(() -> closeNamingEnumeration(results));
|
||||
}
|
||||
|
||||
private void closeContext(DirContext ctx) {
|
||||
if (ctx != null) {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void closeNamingEnumeration(NamingEnumeration<T> results) {
|
||||
if (results != null) {
|
||||
try {
|
||||
results.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ContextRunnable {
|
||||
|
||||
void run(DirContext ctx) throws NamingException;
|
||||
|
||||
}
|
||||
|
||||
interface NamingExceptionFunction<S, T> {
|
||||
|
||||
T apply(S element) throws NamingException;
|
||||
|
||||
default Function<S, T> wrap(Consumer<NamingException> handler) {
|
||||
return (s) -> {
|
||||
try {
|
||||
return apply(s);
|
||||
}
|
||||
catch (NamingException ex) {
|
||||
handler.accept(ex);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -252,8 +252,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
tmpList.add(oneAttribute.getID());
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(attributesEnumeration);
|
||||
@@ -268,7 +268,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
enumeration.close();
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
@@ -294,8 +294,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
collectModifications(oneAttr, tmpList);
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(attributesEnumeration);
|
||||
@@ -327,7 +327,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
try {
|
||||
currentAttribute.initValuesAsNames();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException ex) {
|
||||
log.warn("Incompatible attributes; changed attribute has Name values but "
|
||||
+ "original cannot be converted to this");
|
||||
}
|
||||
@@ -413,7 +413,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
try {
|
||||
return (a == null || a.size() == 0 || a.get() == null);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -470,14 +470,16 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
// Check contents of arrays
|
||||
|
||||
// Order DOES matter, e.g. first names
|
||||
if (isAttributeUpdated(values, orderMatters, orig))
|
||||
if (isAttributeUpdated(values, orderMatters, orig)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (prev != null) {
|
||||
// Also check against updatedAttrs, since there might have been
|
||||
// a previous update
|
||||
if (isAttributeUpdated(values, orderMatters, prev))
|
||||
if (isAttributeUpdated(values, orderMatters, prev)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// FALSE since we have compared all values
|
||||
return false;
|
||||
@@ -548,8 +550,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
try {
|
||||
return oneAttr.get();
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,8 +715,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
closeNamingEnumeration(attributesEnumeration);
|
||||
@@ -733,7 +735,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
List<String> objects = collectAttributeValuesAsList(name, String.class);
|
||||
return objects.toArray(new String[objects.size()]);
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
catch (NoSuchAttributeException ex) {
|
||||
// The attribute does not exist - contract says to return null.
|
||||
return null;
|
||||
}
|
||||
@@ -748,7 +750,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
List<Object> list = collectAttributeValuesAsList(name, Object.class);
|
||||
return list.toArray(new Object[list.size()]);
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
catch (NoSuchAttributeException ex) {
|
||||
// The attribute does not exist - contract says to return null.
|
||||
return null;
|
||||
}
|
||||
@@ -770,7 +772,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
LdapUtils.collectAttributeValues(this.originalAttrs, name, attrSet, String.class);
|
||||
return attrSet;
|
||||
}
|
||||
catch (NoSuchAttributeException e) {
|
||||
catch (NoSuchAttributeException ex) {
|
||||
// The attribute does not exist - contract says to return null.
|
||||
return null;
|
||||
}
|
||||
@@ -1265,8 +1267,8 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
result.addAll(0, this.base);
|
||||
return result.toString();
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw new org.springframework.ldap.InvalidNameException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw new org.springframework.ldap.InvalidNameException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,25 +1299,34 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DirContextAdapter that = (DirContextAdapter) o;
|
||||
|
||||
if (this.updateMode != that.updateMode)
|
||||
if (this.updateMode != that.updateMode) {
|
||||
return false;
|
||||
if (this.base != null ? !this.base.equals(that.base) : that.base != null)
|
||||
}
|
||||
if ((this.base != null) ? !this.base.equals(that.base) : that.base != null) {
|
||||
return false;
|
||||
if (this.dn != null ? !this.dn.equals(that.dn) : that.dn != null)
|
||||
}
|
||||
if ((this.dn != null) ? !this.dn.equals(that.dn) : that.dn != null) {
|
||||
return false;
|
||||
if (this.originalAttrs != null ? !this.originalAttrs.equals(that.originalAttrs) : that.originalAttrs != null)
|
||||
}
|
||||
if ((this.originalAttrs != null) ? !this.originalAttrs.equals(that.originalAttrs)
|
||||
: that.originalAttrs != null) {
|
||||
return false;
|
||||
if (this.referralUrl != null ? !this.referralUrl.equals(that.referralUrl) : that.referralUrl != null)
|
||||
}
|
||||
if ((this.referralUrl != null) ? !this.referralUrl.equals(that.referralUrl) : that.referralUrl != null) {
|
||||
return false;
|
||||
if (this.updatedAttrs != null ? !this.updatedAttrs.equals(that.updatedAttrs) : that.updatedAttrs != null)
|
||||
}
|
||||
if ((this.updatedAttrs != null) ? !this.updatedAttrs.equals(that.updatedAttrs) : that.updatedAttrs != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1325,12 +1336,12 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.originalAttrs != null ? this.originalAttrs.hashCode() : 0;
|
||||
result = 31 * result + (this.dn != null ? this.dn.hashCode() : 0);
|
||||
result = 31 * result + (this.base != null ? this.base.hashCode() : 0);
|
||||
int result = (this.originalAttrs != null) ? this.originalAttrs.hashCode() : 0;
|
||||
result = 31 * result + ((this.dn != null) ? this.dn.hashCode() : 0);
|
||||
result = 31 * result + ((this.base != null) ? this.base.hashCode() : 0);
|
||||
result = 31 * result + (this.updateMode ? 1 : 0);
|
||||
result = 31 * result + (this.updatedAttrs != null ? this.updatedAttrs.hashCode() : 0);
|
||||
result = 31 * result + (this.referralUrl != null ? this.referralUrl.hashCode() : 0);
|
||||
result = 31 * result + ((this.updatedAttrs != null) ? this.updatedAttrs.hashCode() : 0);
|
||||
result = 31 * result + ((this.referralUrl != null) ? this.referralUrl.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1368,7 +1379,7 @@ public class DirContextAdapter implements DirContextOperations {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
log.warn("Error in toString()");
|
||||
}
|
||||
builder.append('}');
|
||||
|
||||
@@ -221,11 +221,11 @@ public class DistinguishedName implements Name {
|
||||
try {
|
||||
dn = parser.dn();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new BadLdapGrammarException("Failed to parse DN", e);
|
||||
catch (ParseException ex) {
|
||||
throw new BadLdapGrammarException("Failed to parse DN", ex);
|
||||
}
|
||||
catch (org.springframework.ldap.core.TokenMgrError e) {
|
||||
throw new BadLdapGrammarException("Failed to parse DN", e);
|
||||
catch (org.springframework.ldap.core.TokenMgrError ex) {
|
||||
throw new BadLdapGrammarException("Failed to parse DN", ex);
|
||||
}
|
||||
this.names = dn.names;
|
||||
}
|
||||
@@ -512,9 +512,9 @@ public class DistinguishedName implements Name {
|
||||
result.names = new LinkedList(this.names);
|
||||
return result;
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
catch (CloneNotSupportedException ex) {
|
||||
LOG.error("CloneNotSupported thrown from superclass - this should not happen");
|
||||
throw new UncategorizedLdapException("Fatal error in clone", e);
|
||||
throw new UncategorizedLdapException("Fatal error in clone", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,8 +693,9 @@ public class DistinguishedName implements Name {
|
||||
LdapRdn longname = (LdapRdn) longiter.previous();
|
||||
LdapRdn shortname = (LdapRdn) shortiter.previous();
|
||||
|
||||
if (!longname.equals(shortname))
|
||||
if (!longname.equals(shortname)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// if short list ended, all were equal
|
||||
@@ -721,7 +722,7 @@ public class DistinguishedName implements Name {
|
||||
try {
|
||||
distinguishedName = (DistinguishedName) name;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
catch (ClassCastException ex) {
|
||||
throw new InvalidNameException("Invalid name type");
|
||||
}
|
||||
|
||||
@@ -747,7 +748,7 @@ public class DistinguishedName implements Name {
|
||||
try {
|
||||
this.names.add(index, new LdapRdn(string));
|
||||
}
|
||||
catch (BadLdapGrammarException e) {
|
||||
catch (BadLdapGrammarException ex) {
|
||||
throw new InvalidNameException("Failed to parse rdn '" + string + "'");
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -170,8 +170,8 @@ public class LdapAttributes extends BasicAttributes {
|
||||
}
|
||||
|
||||
}
|
||||
catch (NamingException e) {
|
||||
log.error("Error formating attributes for output.", e);
|
||||
catch (NamingException ex) {
|
||||
log.error("Error formating attributes for output.", ex);
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
|
||||
|
||||
@@ -548,4 +548,4 @@ public interface LdapClient {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@ public class LdapRdn implements Serializable, Comparable {
|
||||
try {
|
||||
rdn = parser.rdn();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
catch (ParseException ex) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", ex);
|
||||
}
|
||||
catch (org.springframework.ldap.core.TokenMgrError e) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", e);
|
||||
catch (org.springframework.ldap.core.TokenMgrError ex) {
|
||||
throw new BadLdapGrammarException("Failed to parse Rdn", ex);
|
||||
}
|
||||
this.components = rdn.components;
|
||||
}
|
||||
@@ -292,4 +292,4 @@ public class LdapRdn implements Serializable, Comparable {
|
||||
return immutableRdn;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class LdapRdnComponent implements Comparable, Serializable {
|
||||
URI valueUri = new URI(null, null, this.value, null);
|
||||
return this.key + "=" + valueUri.toString();
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
catch (URISyntaxException ex) {
|
||||
// This should really never happen...
|
||||
return this.key + "=" + "value";
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
DirContext ctx = this.contextSource.getReadOnlyContext();
|
||||
|
||||
NamingEnumeration results = null;
|
||||
RuntimeException ex = null;
|
||||
RuntimeException exception = null;
|
||||
try {
|
||||
processor.preProcess(ctx);
|
||||
results = se.executeSearch(ctx);
|
||||
@@ -357,53 +357,53 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
handler.handleNameClassPair(result);
|
||||
}
|
||||
}
|
||||
catch (NameNotFoundException e) {
|
||||
catch (NameNotFoundException ex) {
|
||||
// It is possible to ignore errors caused by base not found
|
||||
if (this.ignoreNameNotFoundException) {
|
||||
LOG.warn("Base context not found, ignoring: " + e.getMessage());
|
||||
LOG.warn("Base context not found, ignoring: " + ex.getMessage());
|
||||
}
|
||||
else {
|
||||
ex = LdapUtils.convertLdapException(e);
|
||||
exception = LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
catch (PartialResultException e) {
|
||||
catch (PartialResultException ex) {
|
||||
// Workaround for AD servers not handling referrals correctly.
|
||||
if (this.ignorePartialResultException) {
|
||||
LOG.debug("PartialResultException encountered and ignored", e);
|
||||
LOG.debug("PartialResultException encountered and ignored", ex);
|
||||
}
|
||||
else {
|
||||
ex = LdapUtils.convertLdapException(e);
|
||||
exception = LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
catch (SizeLimitExceededException e) {
|
||||
catch (SizeLimitExceededException ex) {
|
||||
if (this.ignoreSizeLimitExceededException) {
|
||||
LOG.debug("SizeLimitExceededException encountered and ignored", e);
|
||||
LOG.debug("SizeLimitExceededException encountered and ignored", ex);
|
||||
}
|
||||
else {
|
||||
ex = LdapUtils.convertLdapException(e);
|
||||
exception = LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
ex = LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
exception = LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
processor.postProcess(ctx);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
if (ex == null) {
|
||||
ex = LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
if (exception == null) {
|
||||
exception = LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
else {
|
||||
// We already had an exception from above and should ignore
|
||||
// this one.
|
||||
LOG.debug("Ignoring Exception from postProcess, " + "main exception thrown instead", e);
|
||||
LOG.debug("Ignoring Exception from postProcess, " + "main exception thrown instead", ex);
|
||||
}
|
||||
}
|
||||
closeContextAndNamingEnumeration(ctx, results);
|
||||
// If we got an exception it should be thrown.
|
||||
if (ex != null) {
|
||||
throw ex;
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -810,8 +810,8 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
try {
|
||||
return ce.executeWithContext(ctx);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
closeContext(ctx);
|
||||
@@ -1102,14 +1102,14 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
LOG.debug("Entry " + name + " deleted");
|
||||
}
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
enumeration.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Never mind this
|
||||
}
|
||||
}
|
||||
@@ -1191,7 +1191,7 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
@@ -1207,7 +1207,7 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
try {
|
||||
results.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Never mind this.
|
||||
}
|
||||
}
|
||||
@@ -1237,53 +1237,6 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do-nothing implementation of {@link DirContextProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final class NullDirContextProcessor implements DirContextProcessor {
|
||||
|
||||
public void postProcess(DirContext ctx) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public void preProcess(DirContext ctx) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link NameClassPairCallbackHandler} that passes the NameClassPairs found to a
|
||||
* NameClassPairMapper and collects the results in a list.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public final static class MappingCollectingNameClassPairCallbackHandler<T>
|
||||
extends CollectingNameClassPairCallbackHandler<T> {
|
||||
|
||||
private NameClassPairMapper<T> mapper;
|
||||
|
||||
public MappingCollectingNameClassPairCallbackHandler(NameClassPairMapper<T> mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public T getObjectFromNameClassPair(NameClassPair nameClassPair) {
|
||||
try {
|
||||
return this.mapper.mapFromNameClassPair(nameClassPair);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1446,9 +1399,9 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
}, ctx);
|
||||
return AuthenticationStatus.SUCCESS;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug("Authentication failed for entry with DN '" + entryIdentification.getAbsoluteName() + "'", e);
|
||||
errorCallback.execute(e);
|
||||
catch (Exception ex) {
|
||||
LOG.debug("Authentication failed for entry with DN '" + entryIdentification.getAbsoluteName() + "'", ex);
|
||||
errorCallback.execute(ex);
|
||||
return AuthenticationStatus.UNDEFINED_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -1536,49 +1489,6 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
return searchForObject(LdapUtils.newLdapName(base), filter, searchControls, mapper);
|
||||
}
|
||||
|
||||
private static final class NullAuthenticatedLdapEntryContextCallback
|
||||
implements AuthenticatedLdapEntryContextCallback, AuthenticatedLdapEntryContextMapper<Object> {
|
||||
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class NullAuthenticationErrorCallback implements AuthenticationErrorCallback {
|
||||
|
||||
public void execute(Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class ReturningAuthenticatedLdapEntryContext<T>
|
||||
implements AuthenticatedLdapEntryContextCallback {
|
||||
|
||||
private final AuthenticatedLdapEntryContextMapper<T> mapper;
|
||||
|
||||
private T collectedObject;
|
||||
|
||||
private ReturningAuthenticatedLdapEntryContext(AuthenticatedLdapEntryContextMapper<T> mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
this.collectedObject = this.mapper.mapWithContext(ctx, ldapEntryIdentification);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -1922,28 +1832,28 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
try {
|
||||
return supplier.get();
|
||||
}
|
||||
catch (NameNotFoundException e) {
|
||||
catch (NameNotFoundException ex) {
|
||||
// It is possible to ignore errors caused by base not found
|
||||
if (!this.ignoreNameNotFoundException) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
LOG.warn("Base context not found, ignoring: " + e.getMessage());
|
||||
LOG.warn("Base context not found, ignoring: " + ex.getMessage());
|
||||
}
|
||||
catch (PartialResultException e) {
|
||||
catch (PartialResultException ex) {
|
||||
// Workaround for AD servers not handling referrals correctly.
|
||||
if (!this.ignorePartialResultException) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
LOG.debug("PartialResultException encountered and ignored", e);
|
||||
LOG.debug("PartialResultException encountered and ignored", ex);
|
||||
}
|
||||
catch (SizeLimitExceededException e) {
|
||||
catch (SizeLimitExceededException ex) {
|
||||
if (!this.ignoreSizeLimitExceededException) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
LOG.debug("SizeLimitExceededException encountered and ignored", e);
|
||||
LOG.debug("SizeLimitExceededException encountered and ignored", ex);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1990,4 +1900,94 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
|
||||
|
||||
}
|
||||
|
||||
private static final class NullAuthenticatedLdapEntryContextCallback
|
||||
implements AuthenticatedLdapEntryContextCallback, AuthenticatedLdapEntryContextMapper<Object> {
|
||||
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do-nothing implementation of {@link DirContextProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 2.0
|
||||
*/
|
||||
public static final class NullDirContextProcessor implements DirContextProcessor {
|
||||
|
||||
public void postProcess(DirContext ctx) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public void preProcess(DirContext ctx) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link NameClassPairCallbackHandler} that passes the NameClassPairs found to a
|
||||
* NameClassPairMapper and collects the results in a list.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public final static class MappingCollectingNameClassPairCallbackHandler<T>
|
||||
extends CollectingNameClassPairCallbackHandler<T> {
|
||||
|
||||
private NameClassPairMapper<T> mapper;
|
||||
|
||||
public MappingCollectingNameClassPairCallbackHandler(NameClassPairMapper<T> mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public T getObjectFromNameClassPair(NameClassPair nameClassPair) {
|
||||
try {
|
||||
return this.mapper.mapFromNameClassPair(nameClassPair);
|
||||
}
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class NullAuthenticationErrorCallback implements AuthenticationErrorCallback {
|
||||
|
||||
public void execute(Exception ex) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class ReturningAuthenticatedLdapEntryContext<T>
|
||||
implements AuthenticatedLdapEntryContextCallback {
|
||||
|
||||
private final AuthenticatedLdapEntryContextMapper<T> mapper;
|
||||
|
||||
private T collectedObject;
|
||||
|
||||
private ReturningAuthenticatedLdapEntryContext(AuthenticatedLdapEntryContextMapper<T> mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
|
||||
this.collectedObject = this.mapper.mapWithContext(ctx, ldapEntryIdentification);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
this.add(incomingValues.next());
|
||||
}
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
|
||||
if (attribute instanceof NameAwareAttribute) {
|
||||
@@ -169,11 +169,11 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
try {
|
||||
newValuesAsNames.put(LdapUtils.newLdapName(s), s);
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
catch (InvalidNameException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"This instance has values that are not valid distinguished names; "
|
||||
+ "cannot handle Name values",
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
else if (value instanceof LdapName) {
|
||||
@@ -249,7 +249,7 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
|
||||
return value;
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
catch (NoSuchElementException ex) {
|
||||
throw new IndexOutOfBoundsException("No value at index i");
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
catch (NoSuchElementException e) {
|
||||
catch (NoSuchElementException ex) {
|
||||
throw new IndexOutOfBoundsException("No value at index i");
|
||||
}
|
||||
}
|
||||
@@ -302,15 +302,18 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NameAwareAttribute that = (NameAwareAttribute) o;
|
||||
|
||||
if (this.id != null ? !this.id.equals(that.id) : that.id != null)
|
||||
if ((this.id != null) ? !this.id.equals(that.id) : that.id != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.values.size() != that.values.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -357,7 +360,7 @@ public final class NameAwareAttribute implements Attribute, Iterable<Object> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.id != null ? this.id.hashCode() : 0;
|
||||
int result = (this.id != null) ? this.id.hashCode() : 0;
|
||||
|
||||
int valuesHash = 7;
|
||||
Set<?> myValues = this.values;
|
||||
|
||||
@@ -111,22 +111,25 @@ public final class NameAwareAttributes implements Attributes {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NameAwareAttributes that = (NameAwareAttributes) o;
|
||||
|
||||
if (this.attributes != null ? !this.attributes.equals(that.attributes) : that.attributes != null)
|
||||
if ((this.attributes != null) ? !this.attributes.equals(that.attributes) : that.attributes != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.attributes != null ? this.attributes.hashCode() : 0;
|
||||
return (this.attributes != null) ? this.attributes.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -127,8 +127,8 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
try {
|
||||
this.contextFactory = Class.forName(DEFAULT_CONTEXT_FACTORY);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
LOG.trace("The default for contextFactory cannot be resolved", e);
|
||||
catch (ClassNotFoundException ex) {
|
||||
LOG.trace("The default for contextFactory cannot be resolved", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
credentials);
|
||||
return processedDirContext;
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
closeContext(ctx);
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,8 +198,8 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
try {
|
||||
this.authenticationStrategy.setupEnvironment(env, principal, credentials);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
catch (NamingException ex) {
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug("Exception closing context", e);
|
||||
catch (Exception ex) {
|
||||
LOG.debug("Exception closing context", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,8 +260,8 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
try {
|
||||
allValues = oneAttribute.getAll();
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e);
|
||||
catch (NamingException ex) {
|
||||
throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", ex);
|
||||
}
|
||||
|
||||
while (allValues.hasMoreElements()) {
|
||||
@@ -298,8 +298,8 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
URI valueUri = new URI(null, null, ldapEncoded, null);
|
||||
return valueUri.toString();
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
throw new UncategorizedLdapException("This really shouldn't happen - report this", e);
|
||||
catch (URISyntaxException ex) {
|
||||
throw new UncategorizedLdapException("This really shouldn't happen - report this", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,9 +357,9 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource
|
||||
|
||||
return ctx;
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
closeContext(ctx);
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,9 +151,9 @@ public abstract class AbstractTlsDirContextAuthenticationStrategy implements Dir
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (IOException ex) {
|
||||
LdapUtils.closeContext(ctx);
|
||||
throw new UncategorizedLdapException("Failed to negotiate TLS session", e);
|
||||
throw new UncategorizedLdapException("Failed to negotiate TLS session", ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -83,7 +83,7 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
try {
|
||||
ctx.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Never mind this
|
||||
}
|
||||
|
||||
@@ -140,9 +140,9 @@ public class DefaultDirObjectFactory implements DirObjectFactory {
|
||||
|
||||
nameString = pathString;
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalArgumentException("Supplied name starts with protocol prefix indicating a referral,"
|
||||
+ " but is not possible to parse to an URI", e);
|
||||
+ " but is not possible to parse to an URI", ex);
|
||||
}
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Resulting name after removal of referral information: '" + nameString + "'");
|
||||
|
||||
@@ -40,11 +40,11 @@ public abstract class DelegatingBaseLdapPathContextSourceSupport implements Base
|
||||
try {
|
||||
return (BaseLdapPathSource) getTarget();
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
catch (ClassCastException ex) {
|
||||
throw new UnsupportedOperationException(
|
||||
"This operation is not supported on a target ContextSource that does not "
|
||||
+ " implement BaseLdapPathContextSource",
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,9 @@ public class LookupAttemptingCallback
|
||||
try {
|
||||
return (DirContextOperations) ctx.lookup(ldapEntryIdentification.getRelativeName());
|
||||
}
|
||||
catch (NamingException e) {
|
||||
catch (NamingException ex) {
|
||||
// rethrow, because we aren't allowed to throw checked exceptions.
|
||||
throw LdapUtils.convertLdapException(e);
|
||||
throw LdapUtils.convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,9 +133,10 @@ class RangeOption implements Comparable<RangeOption> {
|
||||
}
|
||||
|
||||
public int compareTo(RangeOption that) {
|
||||
if (this.getInitial() != that.getInitial())
|
||||
if (this.getInitial() != that.getInitial()) {
|
||||
throw new IllegalStateException("Ranges cannot be compared, range-initial not the same: " + this.toString()
|
||||
+ " vs " + that.toString());
|
||||
}
|
||||
|
||||
if (this.getTerminal() == that.getTerminal()) {
|
||||
return 0;
|
||||
@@ -157,22 +158,26 @@ class RangeOption implements Comparable<RangeOption> {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this.getTerminal() > that.getTerminal() ? 1 : -1;
|
||||
return (this.getTerminal() > that.getTerminal()) ? 1 : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RangeOption that = (RangeOption) o;
|
||||
|
||||
if (this.initial != that.initial)
|
||||
if (this.initial != that.initial) {
|
||||
return false;
|
||||
if (this.terminal != that.terminal)
|
||||
}
|
||||
if (this.terminal != that.terminal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -194,7 +199,7 @@ class RangeOption implements Comparable<RangeOption> {
|
||||
}
|
||||
|
||||
int initial = getTerminal() + 1;
|
||||
int terminal = pageSize == TERMINAL_END_OF_RANGE ? TERMINAL_END_OF_RANGE : getTerminal() + pageSize;
|
||||
int terminal = (pageSize != TERMINAL_END_OF_RANGE) ? getTerminal() + pageSize : TERMINAL_END_OF_RANGE;
|
||||
|
||||
return new RangeOption(initial, terminal);
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ public class SingleContextSource implements ContextSource, DisposableBean {
|
||||
try {
|
||||
this.ctx.close();
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
LOG.warn("Error when closing", e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
LOG.warn("Error when closing", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class SingleContextSource implements ContextSource, DisposableBean {
|
||||
}
|
||||
else if (methodName.equals("equals")) {
|
||||
// Only consider equal when proxies are identical.
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
return (proxy != args[0]) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
else if (methodName.equals("hashCode")) {
|
||||
// Use hashCode of Connection proxy.
|
||||
@@ -208,8 +208,8 @@ public class SingleContextSource implements ContextSource, DisposableBean {
|
||||
try {
|
||||
return method.invoke(this.target, args);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
catch (InvocationTargetException ex) {
|
||||
throw ex.getTargetException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,22 +66,25 @@ public abstract class BinaryLogicalFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BinaryLogicalFilter that = (BinaryLogicalFilter) o;
|
||||
|
||||
if (this.queryList != null ? !this.queryList.equals(that.queryList) : that.queryList != null)
|
||||
if ((this.queryList != null) ? !this.queryList.equals(that.queryList) : that.queryList != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.queryList != null ? this.queryList.hashCode() : 0;
|
||||
return (this.queryList != null) ? this.queryList.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,25 +78,29 @@ public abstract class CompareFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CompareFilter that = (CompareFilter) o;
|
||||
|
||||
if (this.attribute != null ? !this.attribute.equals(that.attribute) : that.attribute != null)
|
||||
if ((this.attribute != null) ? !this.attribute.equals(that.attribute) : that.attribute != null) {
|
||||
return false;
|
||||
if (this.value != null ? !this.value.equals(that.value) : that.value != null)
|
||||
}
|
||||
if ((this.value != null) ? !this.value.equals(that.value) : that.value != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = this.attribute != null ? this.attribute.hashCode() : 0;
|
||||
result = 31 * result + (this.value != null ? this.value.hashCode() : 0);
|
||||
int result = (this.attribute != null) ? this.attribute.hashCode() : 0;
|
||||
result = 31 * result + ((this.value != null) ? this.value.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,4 +51,4 @@ public interface Filter {
|
||||
*/
|
||||
int hashCode();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,22 +68,25 @@ public class HardcodedFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HardcodedFilter that = (HardcodedFilter) o;
|
||||
|
||||
if (this.filter != null ? !this.filter.equals(that.filter) : that.filter != null)
|
||||
if ((this.filter != null) ? !this.filter.equals(that.filter) : that.filter != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.filter != null ? this.filter.hashCode() : 0;
|
||||
return (this.filter != null) ? this.filter.hashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,22 +58,25 @@ public class NotFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NotFilter notFilter = (NotFilter) o;
|
||||
|
||||
if (this.filter != null ? !this.filter.equals(notFilter.filter) : notFilter.filter != null)
|
||||
if ((this.filter != null) ? !this.filter.equals(notFilter.filter) : notFilter.filter != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.filter != null ? this.filter.hashCode() : 0;
|
||||
return (this.filter != null) ? this.filter.hashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,22 +56,25 @@ public class NotPresentFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NotPresentFilter that = (NotPresentFilter) o;
|
||||
|
||||
if (this.attribute != null ? !this.attribute.equals(that.attribute) : that.attribute != null)
|
||||
if ((this.attribute != null) ? !this.attribute.equals(that.attribute) : that.attribute != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.attribute != null ? this.attribute.hashCode() : 0;
|
||||
return (this.attribute != null) ? this.attribute.hashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,22 +57,25 @@ public class PresentFilter extends AbstractFilter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PresentFilter that = (PresentFilter) o;
|
||||
|
||||
if (this.attribute != null ? !this.attribute.equals(that.attribute) : that.attribute != null)
|
||||
if ((this.attribute != null) ? !this.attribute.equals(that.attribute) : that.attribute != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.attribute != null ? this.attribute.hashCode() : 0;
|
||||
return (this.attribute != null) ? this.attribute.hashCode() : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
package org.springframework.ldap.odm.annotations;
|
||||
|
||||
@@ -147,11 +147,11 @@ import org.springframework.ldap.odm.annotations.Transient;
|
||||
try {
|
||||
paramType = (ParameterizedType) field.getGenericType();
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
catch (ClassCastException ex) {
|
||||
throw new MetaDataException(
|
||||
String.format("Can't determine destination type for field %1$s in Entry class %2$s", field,
|
||||
field.getDeclaringClass()),
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
Type[] actualParamArguments = paramType.getActualTypeArguments();
|
||||
if (actualParamArguments.length == 1) {
|
||||
@@ -203,8 +203,8 @@ import org.springframework.ldap.odm.annotations.Transient;
|
||||
try {
|
||||
return (Collection<Object>) this.collectionClass.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new UncategorizedLdapException("Failed to instantiate collection class", e);
|
||||
catch (Exception ex) {
|
||||
throw new UncategorizedLdapException("Failed to instantiate collection class", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,19 +95,6 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
this.converterManager = converterManager;
|
||||
}
|
||||
|
||||
static final class EntityData {
|
||||
|
||||
final ObjectMetaData metaData;
|
||||
|
||||
final Filter ocFilter;
|
||||
|
||||
private EntityData(ObjectMetaData metaData, Filter ocFilter) {
|
||||
this.metaData = metaData;
|
||||
this.ocFilter = ocFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// A map of managed classes to to meta data about those classes
|
||||
private final ConcurrentMap<Class<?>, EntityData> metaDataMap = new ConcurrentHashMap<Class<?>, EntityData>();
|
||||
|
||||
@@ -165,10 +152,10 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
try {
|
||||
managedClass.getConstructor();
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
catch (NoSuchMethodException ex) {
|
||||
throw new InvalidEntryException(
|
||||
String.format("The class %1$s must have a zero argument constructor to be an Entry", managedClass),
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
|
||||
// Check we have all of the necessary converters for the class
|
||||
@@ -255,9 +242,9 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
|
||||
}
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new InvalidEntryException(String.format("Can't set attribute %1$s", attributeInfo.getName()),
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -459,8 +446,8 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
try {
|
||||
return (Name) getIdField(entry).get(entry);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new InvalidEntryException(String.format("Can't get Id field from Entry %1$s", entry), e);
|
||||
catch (Exception ex) {
|
||||
throw new InvalidEntryException(String.format("Can't get Id field from Entry %1$s", entry), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,8 +460,8 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
try {
|
||||
getIdField(entry).set(entry, id);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new InvalidEntryException(String.format("Can't set Id field on Entry %s to %s", entry, id), e);
|
||||
catch (Exception ex) {
|
||||
throw new InvalidEntryException(String.format("Can't set Id field on Entry %s to %s", entry, id), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,9 +509,9 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
AttributeMetaData attributeMetaData = getEntityData(clazz).metaData.getAttribute(field);
|
||||
return attributeMetaData.getName().toString();
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
catch (NoSuchFieldException ex) {
|
||||
throw new IllegalArgumentException(String.format("Field %s cannot be found in class %s", fieldName, clazz),
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,4 +530,17 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
|
||||
return true;
|
||||
}
|
||||
|
||||
static final class EntityData {
|
||||
|
||||
final ObjectMetaData metaData;
|
||||
|
||||
final Filter ocFilter;
|
||||
|
||||
private EntityData(ObjectMetaData metaData, Filter ocFilter) {
|
||||
this.metaData = metaData;
|
||||
this.ocFilter = ocFilter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,4 @@
|
||||
*
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
package org.springframework.ldap.odm.core.impl;
|
||||
package org.springframework.ldap.odm.core.impl;
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.odm.core;
|
||||
package org.springframework.ldap.odm.core;
|
||||
|
||||
@@ -45,8 +45,8 @@ public class ConversionServiceConverterManager implements ConverterManager {
|
||||
Class<?> clazz = ClassUtils.forName(DEFAULT_CONVERSION_SERVICE_CLASS, defaultClassLoader);
|
||||
this.conversionService = (GenericConversionService) clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
ReflectionUtils.handleReflectionException(e);
|
||||
catch (Exception ex) {
|
||||
ReflectionUtils.handleReflectionException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -97,65 +97,6 @@ public final class ConverterManagerFactoryBean implements FactoryBean {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConverterManagerFactoryBean.class);
|
||||
|
||||
/**
|
||||
* Configuration information for a single Converter instance.
|
||||
*/
|
||||
public static final class ConverterConfig {
|
||||
|
||||
// The set of classes the Converter will convert from.
|
||||
private Set<Class<?>> fromClasses = new HashSet<Class<?>>();
|
||||
|
||||
// The (optional) LDAP syntax.
|
||||
private String syntax = null;
|
||||
|
||||
// The set of classes the Converter will convert to.
|
||||
private Set<Class<?>> toClasses = new HashSet<Class<?>>();
|
||||
|
||||
// The Converter to use.
|
||||
private Converter converter = null;
|
||||
|
||||
public ConverterConfig() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromClasses Comma separated list of classes the {@link Converter} should
|
||||
* can convert from.
|
||||
*/
|
||||
public void setFromClasses(Set<Class<?>> fromClasses) {
|
||||
this.fromClasses = fromClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toClasses Comma separated list of classes the {@link Converter} can
|
||||
* convert to.
|
||||
*/
|
||||
public void setToClasses(Set<Class<?>> toClasses) {
|
||||
this.toClasses = toClasses;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param syntax An LDAP syntax supported by the {@link Converter}.
|
||||
*/
|
||||
public void setSyntax(String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param converter The {@link Converter} to use.
|
||||
*/
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("fromClasses=%1$s, syntax=%2$s, toClasses=%3$s, converter=%4$s", this.fromClasses,
|
||||
this.syntax, this.toClasses, this.converter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Set<ConverterConfig> converterConfigList = null;
|
||||
|
||||
/**
|
||||
@@ -219,4 +160,63 @@ public final class ConverterManagerFactoryBean implements FactoryBean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration information for a single Converter instance.
|
||||
*/
|
||||
public static final class ConverterConfig {
|
||||
|
||||
// The set of classes the Converter will convert from.
|
||||
private Set<Class<?>> fromClasses = new HashSet<Class<?>>();
|
||||
|
||||
// The (optional) LDAP syntax.
|
||||
private String syntax = null;
|
||||
|
||||
// The set of classes the Converter will convert to.
|
||||
private Set<Class<?>> toClasses = new HashSet<Class<?>>();
|
||||
|
||||
// The Converter to use.
|
||||
private Converter converter = null;
|
||||
|
||||
public ConverterConfig() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromClasses Comma separated list of classes the {@link Converter} should
|
||||
* can convert from.
|
||||
*/
|
||||
public void setFromClasses(Set<Class<?>> fromClasses) {
|
||||
this.fromClasses = fromClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toClasses Comma separated list of classes the {@link Converter} can
|
||||
* convert to.
|
||||
*/
|
||||
public void setToClasses(Set<Class<?>> toClasses) {
|
||||
this.toClasses = toClasses;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param syntax An LDAP syntax supported by the {@link Converter}.
|
||||
*/
|
||||
public void setSyntax(String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param converter The {@link Converter} to use.
|
||||
*/
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("fromClasses=%1$s, syntax=%2$s, toClasses=%3$s, converter=%4$s", this.fromClasses,
|
||||
this.syntax, this.toClasses, this.converter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public final class ConverterManagerImpl implements ConverterManager {
|
||||
try {
|
||||
result = syntaxConverter.convert(source, targetClass);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Ignore as we may still be able to convert successfully
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public final class ConverterManagerImpl implements ConverterManager {
|
||||
try {
|
||||
result = nullSyntaxConverter.convert(source, targetClass);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
// Handled at the end of the method
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,4 @@
|
||||
* @author Paul Harvey <paul.at.pauls-place.me.uk>
|
||||
*/
|
||||
|
||||
package org.springframework.ldap.odm.typeconversion.impl.converters;
|
||||
package org.springframework.ldap.odm.typeconversion.impl.converters;
|
||||
|
||||
@@ -122,7 +122,7 @@ public class DelegatingContext implements Context {
|
||||
*/
|
||||
public int hashCode() {
|
||||
final Context context = this.getInnermostDelegateContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ public class DelegatingContext implements Context {
|
||||
*/
|
||||
public String toString() {
|
||||
final Context context = this.getInnermostDelegateContext();
|
||||
return (context != null ? context.toString() : "Context is closed");
|
||||
return (context != null) ? context.toString() : "Context is closed";
|
||||
}
|
||||
|
||||
// ***** Context Interface Delegates *****//
|
||||
@@ -188,9 +188,9 @@ public class DelegatingContext implements Context {
|
||||
this.keyedObjectPool.invalidateObject(this.dirContextType, context);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
final NamingException namingException = new NamingException("Failed to return delegate Context to pool.");
|
||||
namingException.setRootCause(e);
|
||||
namingException.setRootCause(ex);
|
||||
throw namingException;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -121,7 +121,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
*/
|
||||
public int hashCode() {
|
||||
final DirContext context = this.getInnermostDelegateDirContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
*/
|
||||
public String toString() {
|
||||
final DirContext context = this.getInnermostDelegateDirContext();
|
||||
return (context != null ? context.toString() : "DirContext is closed");
|
||||
return (context != null) ? context.toString() : "DirContext is closed";
|
||||
}
|
||||
|
||||
// ***** DirContextProxy Interface Methods *****//
|
||||
|
||||
@@ -119,7 +119,7 @@ public class DelegatingLdapContext extends DelegatingDirContext implements LdapC
|
||||
*/
|
||||
public int hashCode() {
|
||||
final LdapContext context = this.getInnermostDelegateLdapContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +127,7 @@ public class DelegatingLdapContext extends DelegatingDirContext implements LdapC
|
||||
*/
|
||||
public String toString() {
|
||||
final LdapContext context = this.getInnermostDelegateLdapContext();
|
||||
return (context != null ? context.toString() : "LdapContext is closed");
|
||||
return (context != null) ? context.toString() : "LdapContext is closed";
|
||||
}
|
||||
|
||||
// ***** LdapContext Interface Delegates *****//
|
||||
|
||||
@@ -191,8 +191,8 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
|
||||
final DirContext dirContext = (DirContext) obj;
|
||||
return this.dirContextValidator.validateDirContext(contextType, dirContext);
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.warn("Failed to validate '" + obj + "' due to an unexpected exception.", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("Failed to validate '" + obj + "' due to an unexpected exception.", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -214,8 +214,8 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
|
||||
this.logger.debug("Closed " + key + " DirContext='" + dirContext + "'");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.warn("An exception occured while closing '" + obj + "'", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("An exception occured while closing '" + obj + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,8 +254,8 @@ class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {
|
||||
try {
|
||||
return method.invoke(this.target, args);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable targetException = e.getTargetException();
|
||||
catch (InvocationTargetException ex) {
|
||||
Throwable targetException = ex.getTargetException();
|
||||
Class<? extends Throwable> targetExceptionClass = targetException.getClass();
|
||||
|
||||
boolean nonTransientEncountered = false;
|
||||
|
||||
@@ -36,8 +36,8 @@ public class MutablePoolingContextSource extends PoolingContextSource {
|
||||
try {
|
||||
dirContext = (DirContext) this.keyedObjectPool.borrowObject(dirContextType);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", e);
|
||||
catch (Exception ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", ex);
|
||||
}
|
||||
|
||||
if (dirContext instanceof LdapContext) {
|
||||
|
||||
@@ -404,8 +404,8 @@ public class PoolingContextSource extends DelegatingBaseLdapPathContextSourceSup
|
||||
try {
|
||||
this.keyedObjectPool.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.warn("An exception occured while closing the underlying pool.", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("An exception occured while closing the underlying pool.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,8 +438,8 @@ public class PoolingContextSource extends DelegatingBaseLdapPathContextSourceSup
|
||||
try {
|
||||
dirContext = (DirContext) this.keyedObjectPool.borrowObject(dirContextType);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", e);
|
||||
catch (Exception ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", ex);
|
||||
}
|
||||
|
||||
if (dirContext instanceof LdapContext) {
|
||||
|
||||
@@ -182,8 +182,8 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, e);
|
||||
catch (Exception ex) {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, ex);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -124,7 +124,7 @@ public class DelegatingContext implements Context {
|
||||
*/
|
||||
public int hashCode() {
|
||||
final Context context = this.getInnermostDelegateContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class DelegatingContext implements Context {
|
||||
*/
|
||||
public String toString() {
|
||||
final Context context = this.getInnermostDelegateContext();
|
||||
return (context != null ? context.toString() : "Context is closed");
|
||||
return (context != null) ? context.toString() : "Context is closed";
|
||||
}
|
||||
|
||||
// ***** Context Interface Delegates *****//
|
||||
@@ -190,9 +190,9 @@ public class DelegatingContext implements Context {
|
||||
this.keyedObjectPool.invalidateObject(this.dirContextType, context);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
final NamingException namingException = new NamingException("Failed to return delegate Context to pool.");
|
||||
namingException.setRootCause(e);
|
||||
namingException.setRootCause(ex);
|
||||
throw namingException;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -123,7 +123,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
*/
|
||||
public int hashCode() {
|
||||
final DirContext context = this.getInnermostDelegateDirContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ public class DelegatingDirContext extends DelegatingContext implements DirContex
|
||||
*/
|
||||
public String toString() {
|
||||
final DirContext context = this.getInnermostDelegateDirContext();
|
||||
return (context != null ? context.toString() : "DirContext is closed");
|
||||
return (context != null) ? context.toString() : "DirContext is closed";
|
||||
}
|
||||
|
||||
// ***** DirContextProxy Interface Methods *****//
|
||||
|
||||
@@ -121,7 +121,7 @@ public class DelegatingLdapContext extends DelegatingDirContext implements LdapC
|
||||
*/
|
||||
public int hashCode() {
|
||||
final LdapContext context = this.getInnermostDelegateLdapContext();
|
||||
return (context != null ? context.hashCode() : 0);
|
||||
return (context != null) ? context.hashCode() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ public class DelegatingLdapContext extends DelegatingDirContext implements LdapC
|
||||
*/
|
||||
public String toString() {
|
||||
final LdapContext context = this.getInnermostDelegateLdapContext();
|
||||
return (context != null ? context.toString() : "LdapContext is closed");
|
||||
return (context != null) ? context.toString() : "LdapContext is closed";
|
||||
}
|
||||
|
||||
// ***** LdapContext Interface Delegates *****//
|
||||
|
||||
@@ -162,9 +162,9 @@ class DirContextPooledObjectFactory extends BaseKeyedPooledObjectFactory<Object,
|
||||
final DirContext dirContext = (DirContext) pooledObject.getObject();
|
||||
return this.dirContextValidator.validateDirContext(contextType, dirContext);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("Failed to validate '" + pooledObject.getObject() + "' due to an unexpected exception.",
|
||||
e);
|
||||
ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -189,8 +189,8 @@ class DirContextPooledObjectFactory extends BaseKeyedPooledObjectFactory<Object,
|
||||
this.logger.debug("Closed " + key + " DirContext='" + dirContext + "'");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.warn("An exception occured while closing '" + pooledObject.getObject() + "'", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("An exception occured while closing '" + pooledObject.getObject() + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,8 +277,8 @@ class DirContextPooledObjectFactory extends BaseKeyedPooledObjectFactory<Object,
|
||||
try {
|
||||
return method.invoke(this.target, args);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
Throwable targetException = e.getTargetException();
|
||||
catch (InvocationTargetException ex) {
|
||||
Throwable targetException = ex.getTargetException();
|
||||
Class<? extends Throwable> targetExceptionClass = targetException.getClass();
|
||||
|
||||
boolean nonTransientEncountered = false;
|
||||
|
||||
@@ -48,8 +48,8 @@ public class MutablePooledContextSource extends PooledContextSource {
|
||||
try {
|
||||
dirContext = (DirContext) this.keyedObjectPool.borrowObject(dirContextType);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", e);
|
||||
catch (Exception ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", ex);
|
||||
}
|
||||
|
||||
if (dirContext instanceof LdapContext) {
|
||||
|
||||
@@ -223,8 +223,8 @@ public class PooledContextSource extends DelegatingBaseLdapPathContextSourceSupp
|
||||
try {
|
||||
this.keyedObjectPool.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.warn("An exception occurred while closing the underlying pool.", e);
|
||||
catch (Exception ex) {
|
||||
this.logger.warn("An exception occurred while closing the underlying pool.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,8 +257,8 @@ public class PooledContextSource extends DelegatingBaseLdapPathContextSourceSupp
|
||||
try {
|
||||
dirContext = (DirContext) this.keyedObjectPool.borrowObject(dirContextType);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", e);
|
||||
catch (Exception ex) {
|
||||
throw new DataAccessResourceFailureException("Failed to borrow DirContext from pool.", ex);
|
||||
}
|
||||
|
||||
if (dirContext instanceof LdapContext) {
|
||||
|
||||
@@ -181,8 +181,8 @@ public class DefaultDirContextValidator implements DirContextValidator {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, e);
|
||||
catch (Exception ex) {
|
||||
this.logger.debug("DirContext '{}' failed validation with an exception.", dirContext, ex);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -23,9 +23,6 @@ import javax.naming.Name;
|
||||
|
||||
import org.springframework.ldap.filter.Filter;
|
||||
|
||||
import static org.springframework.ldap.query.CriteriaContainerType.AND;
|
||||
import static org.springframework.ldap.query.CriteriaContainerType.OR;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @since 2.0
|
||||
@@ -55,28 +52,28 @@ class DefaultContainerCriteria implements AppendableContainerCriteria {
|
||||
|
||||
@Override
|
||||
public ConditionCriteria and(String attribute) {
|
||||
AND.validateSameType(this.type);
|
||||
this.type = AND;
|
||||
CriteriaContainerType.AND.validateSameType(this.type);
|
||||
this.type = CriteriaContainerType.AND;
|
||||
|
||||
return new DefaultConditionCriteria(this, attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionCriteria or(String attribute) {
|
||||
OR.validateSameType(this.type);
|
||||
this.type = OR;
|
||||
CriteriaContainerType.OR.validateSameType(this.type);
|
||||
this.type = CriteriaContainerType.OR;
|
||||
|
||||
return new DefaultConditionCriteria(this, attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerCriteria and(ContainerCriteria nested) {
|
||||
if (this.type == OR) {
|
||||
return new DefaultContainerCriteria(this.topQuery).withType(AND).append(this.filter())
|
||||
if (this.type == CriteriaContainerType.OR) {
|
||||
return new DefaultContainerCriteria(this.topQuery).withType(CriteriaContainerType.AND).append(this.filter())
|
||||
.append(nested.filter());
|
||||
}
|
||||
else {
|
||||
this.type = AND;
|
||||
this.type = CriteriaContainerType.AND;
|
||||
this.filters.add(nested.filter());
|
||||
return this;
|
||||
}
|
||||
@@ -84,12 +81,12 @@ class DefaultContainerCriteria implements AppendableContainerCriteria {
|
||||
|
||||
@Override
|
||||
public ContainerCriteria or(ContainerCriteria nested) {
|
||||
if (this.type == AND) {
|
||||
return new DefaultContainerCriteria(this.topQuery).withType(OR).append(this.filter())
|
||||
if (this.type == CriteriaContainerType.AND) {
|
||||
return new DefaultContainerCriteria(this.topQuery).withType(CriteriaContainerType.OR).append(this.filter())
|
||||
.append(nested.filter());
|
||||
}
|
||||
else {
|
||||
this.type = OR;
|
||||
this.type = CriteriaContainerType.OR;
|
||||
this.filters.add(nested.filter());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -98,8 +98,9 @@ public final class LdapEncoder {
|
||||
*/
|
||||
public static String filterEncode(String value) {
|
||||
|
||||
if (value == null)
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// make buffer roomy
|
||||
StringBuilder encodedValue = new StringBuilder(value.length() * 2);
|
||||
@@ -142,8 +143,9 @@ public final class LdapEncoder {
|
||||
*/
|
||||
public static String nameEncode(String value) {
|
||||
|
||||
if (value == null)
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// make buffer roomy
|
||||
StringBuilder encodedValue = new StringBuilder(value.length() * 2);
|
||||
@@ -188,8 +190,9 @@ public final class LdapEncoder {
|
||||
*/
|
||||
static public String nameDecode(String value) throws BadLdapGrammarException {
|
||||
|
||||
if (value == null)
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// make buffer same size
|
||||
StringBuilder decoded = new StringBuilder(value.length());
|
||||
|
||||
@@ -84,8 +84,8 @@ public final class LdapNameBuilder {
|
||||
this.ldapName.add(new Rdn(key, value));
|
||||
return this;
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw new org.springframework.ldap.InvalidNameException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw new org.springframework.ldap.InvalidNameException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public final class LdapNameBuilder {
|
||||
this.ldapName.addAll(this.ldapName.size(), name);
|
||||
return this;
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw new org.springframework.ldap.InvalidNameException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw new org.springframework.ldap.InvalidNameException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -307,8 +307,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
handleAttributeValue(attribute.getID(), attribute.get(i), i, callbackHandler);
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,33 +319,6 @@ public final class LdapUtils {
|
||||
callbackHandler.handleAttributeValue(attributeID, value, i);
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributeValueCallbackHandler} to collect values in a supplied
|
||||
* collection.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
private static final class CollectingAttributeValueCallbackHandler<T> implements AttributeValueCallbackHandler {
|
||||
|
||||
private final Collection<T> collection;
|
||||
|
||||
private final Class<T> clazz;
|
||||
|
||||
public CollectingAttributeValueCallbackHandler(Collection<T> collection, Class<T> clazz) {
|
||||
Assert.notNull(collection, "Collection must not be null");
|
||||
Assert.notNull(clazz, "Clazz parameter must not be null");
|
||||
|
||||
this.collection = collection;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public void handleAttributeValue(String attributeName, Object attributeValue, int index) {
|
||||
Assert.isTrue(attributeName == null || this.clazz.isAssignableFrom(attributeValue.getClass()));
|
||||
this.collection.add(this.clazz.cast(attributeValue));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a CompositeName to a String in a way that avoids escaping problems, such
|
||||
* as the dreaded "triple backslash" problem.
|
||||
@@ -387,8 +360,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
return new LdapName(convertCompositeNameToString(compositeName));
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -396,8 +369,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
result.addAll(0, name);
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -418,8 +391,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
return new LdapName(distinguishedName);
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +430,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
result.remove(0);
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,8 +456,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
result.addAll(0, pathToPrepend);
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -544,8 +517,8 @@ public final class LdapUtils {
|
||||
try {
|
||||
return oneAttribute.get();
|
||||
}
|
||||
catch (javax.naming.NamingException e) {
|
||||
throw convertLdapException(e);
|
||||
catch (javax.naming.NamingException ex) {
|
||||
throw convertLdapException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -787,4 +760,31 @@ public final class LdapUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributeValueCallbackHandler} to collect values in a supplied
|
||||
* collection.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
private static final class CollectingAttributeValueCallbackHandler<T> implements AttributeValueCallbackHandler {
|
||||
|
||||
private final Collection<T> collection;
|
||||
|
||||
private final Class<T> clazz;
|
||||
|
||||
public CollectingAttributeValueCallbackHandler(Collection<T> collection, Class<T> clazz) {
|
||||
Assert.notNull(collection, "Collection must not be null");
|
||||
Assert.notNull(clazz, "Clazz parameter must not be null");
|
||||
|
||||
this.collection = collection;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public void handleAttributeValue(String attributeName, Object attributeValue, int index) {
|
||||
Assert.isTrue(attributeName == null || this.clazz.isAssignableFrom(attributeValue.getClass()));
|
||||
this.collection.add(this.clazz.cast(attributeValue));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public class BindOperationExecutor implements CompensatingTransactionOperationEx
|
||||
try {
|
||||
this.ldapOperations.unbind(this.dn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Failed to rollback, dn:" + this.dn.toString(), e);
|
||||
catch (Exception ex) {
|
||||
log.warn("Failed to rollback, dn:" + this.dn.toString(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ModifyAttributesOperationExecutor implements CompensatingTransactio
|
||||
log.debug("Rolling back modifyAttributes operation");
|
||||
this.ldapOperations.modifyAttributes(this.dn, this.compensatingModifications);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
log.warn("Failed to rollback ModifyAttributes operation, dn: " + this.dn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +87,10 @@ public class RebindOperationExecutor implements CompensatingTransactionOperation
|
||||
this.ldapOperations.unbind(this.originalDn);
|
||||
this.ldapOperations.rename(this.temporaryDn, this.originalDn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
log.warn(
|
||||
"Failed to rollback operation, dn: " + this.originalDn + "; temporary DN:this. " + this.temporaryDn,
|
||||
e);
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class RenameOperationExecutor implements CompensatingTransactionOperation
|
||||
try {
|
||||
this.ldapOperations.rename(this.newDn, this.originalDn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
log.warn("Unable to rollback rename operation. " + "originalDn: " + this.newDn + "; newDn:this. "
|
||||
+ this.originalDn);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class UnbindOperationExecutor implements CompensatingTransactionOperation
|
||||
try {
|
||||
this.ldapOperations.rename(this.temporaryDn, this.originalDn);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception ex) {
|
||||
log.warn("Filed to rollback unbind operation, temporaryDn: " + this.temporaryDn + "; originalDn:this. "
|
||||
+ this.originalDn);
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ public class ContextSourceAndDataSourceTransactionManager extends DataSourceTran
|
||||
try {
|
||||
this.ldapManagerDelegate.doBegin(actualTransactionObject.getLdapTransactionObject(), definition);
|
||||
}
|
||||
catch (TransactionException e) {
|
||||
catch (TransactionException ex) {
|
||||
// Failed to start LDAP transaction - make sure we clean up properly
|
||||
super.doCleanupAfterCompletion(actualTransactionObject.getDataSourceTransactionObject());
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,28 +162,6 @@ public class ContextSourceAndDataSourceTransactionManager extends DataSourceTran
|
||||
this.ldapManagerDelegate.setRenamingStrategy(renamingStrategy);
|
||||
}
|
||||
|
||||
private final static class ContextSourceAndDataSourceTransactionObject {
|
||||
|
||||
private Object ldapTransactionObject;
|
||||
|
||||
private Object dataSourceTransactionObject;
|
||||
|
||||
public ContextSourceAndDataSourceTransactionObject(Object ldapTransactionObject,
|
||||
Object dataSourceTransactionObject) {
|
||||
this.ldapTransactionObject = ldapTransactionObject;
|
||||
this.dataSourceTransactionObject = dataSourceTransactionObject;
|
||||
}
|
||||
|
||||
public Object getDataSourceTransactionObject() {
|
||||
return this.dataSourceTransactionObject;
|
||||
}
|
||||
|
||||
public Object getLdapTransactionObject() {
|
||||
return this.ldapTransactionObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.jdbc.datasource.DataSourceTransactionManager#doSuspend(java.
|
||||
@@ -209,4 +187,26 @@ public class ContextSourceAndDataSourceTransactionManager extends DataSourceTran
|
||||
this.ldapManagerDelegate.checkRenamingStrategy();
|
||||
}
|
||||
|
||||
}
|
||||
private final static class ContextSourceAndDataSourceTransactionObject {
|
||||
|
||||
private Object ldapTransactionObject;
|
||||
|
||||
private Object dataSourceTransactionObject;
|
||||
|
||||
public ContextSourceAndDataSourceTransactionObject(Object ldapTransactionObject,
|
||||
Object dataSourceTransactionObject) {
|
||||
this.ldapTransactionObject = ldapTransactionObject;
|
||||
this.dataSourceTransactionObject = dataSourceTransactionObject;
|
||||
}
|
||||
|
||||
public Object getDataSourceTransactionObject() {
|
||||
return this.dataSourceTransactionObject;
|
||||
}
|
||||
|
||||
public Object getLdapTransactionObject() {
|
||||
return this.ldapTransactionObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
try {
|
||||
this.ldapManagerDelegate.doBegin(actualTransactionObject.getLdapTransactionObject(), definition);
|
||||
}
|
||||
catch (TransactionException e) {
|
||||
catch (TransactionException ex) {
|
||||
// Failed to start LDAP transaction - make sure we clean up properly
|
||||
super.doCleanupAfterCompletion(actualTransactionObject.getHibernateTransactionObject());
|
||||
throw e;
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,28 +162,6 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
this.ldapManagerDelegate.setRenamingStrategy(renamingStrategy);
|
||||
}
|
||||
|
||||
private static final class ContextSourceAndHibernateTransactionObject {
|
||||
|
||||
private Object ldapTransactionObject;
|
||||
|
||||
private Object hibernateTransactionObject;
|
||||
|
||||
public ContextSourceAndHibernateTransactionObject(Object ldapTransactionObject,
|
||||
Object hibernateTransactionObject) {
|
||||
this.ldapTransactionObject = ldapTransactionObject;
|
||||
this.hibernateTransactionObject = hibernateTransactionObject;
|
||||
}
|
||||
|
||||
public Object getHibernateTransactionObject() {
|
||||
return this.hibernateTransactionObject;
|
||||
}
|
||||
|
||||
public Object getLdapTransactionObject() {
|
||||
return this.ldapTransactionObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @see
|
||||
* org.springframework.orm.hibernate5.HibernateTransactionManager#doSuspend(java.lang.
|
||||
@@ -209,4 +187,26 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa
|
||||
this.ldapManagerDelegate.checkRenamingStrategy();
|
||||
}
|
||||
|
||||
private static final class ContextSourceAndHibernateTransactionObject {
|
||||
|
||||
private Object ldapTransactionObject;
|
||||
|
||||
private Object hibernateTransactionObject;
|
||||
|
||||
public ContextSourceAndHibernateTransactionObject(Object ldapTransactionObject,
|
||||
Object hibernateTransactionObject) {
|
||||
this.ldapTransactionObject = ldapTransactionObject;
|
||||
this.hibernateTransactionObject = hibernateTransactionObject;
|
||||
}
|
||||
|
||||
public Object getHibernateTransactionObject() {
|
||||
return this.hibernateTransactionObject;
|
||||
}
|
||||
|
||||
public Object getLdapTransactionObject() {
|
||||
return this.ldapTransactionObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -185,4 +185,4 @@ public class ContextSourceTransactionManager extends AbstractPlatformTransaction
|
||||
return (txObject.getHolder() != null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +111,8 @@ public class ContextSourceTransactionManagerDelegate extends AbstractCompensatin
|
||||
LOG.debug("Closing target context");
|
||||
ctx.close();
|
||||
}
|
||||
catch (NamingException e) {
|
||||
LOG.warn("Failed to close target context", e);
|
||||
catch (NamingException ex) {
|
||||
LOG.warn("Failed to close target context", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class TransactionAwareDirContextInvocationHandler implements InvocationHa
|
||||
}
|
||||
else if (methodName.equals("equals")) {
|
||||
// Only consider equal when proxies are identical.
|
||||
return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE);
|
||||
return (proxy != args[0]) ? Boolean.FALSE : Boolean.TRUE;
|
||||
}
|
||||
else if (methodName.equals("hashCode")) {
|
||||
// Use hashCode of Connection proxy.
|
||||
@@ -89,8 +89,8 @@ public class TransactionAwareDirContextInvocationHandler implements InvocationHa
|
||||
try {
|
||||
return method.invoke(this.target, args);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
catch (InvocationTargetException ex) {
|
||||
throw ex.getTargetException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ public class DefaultTempEntryRenamingStrategy implements TempEntryRenamingStrate
|
||||
String leafNode = (String) temporaryName.remove(temporaryName.size() - 1);
|
||||
temporaryName.add(new Rdn(leafNode + this.tempSuffix));
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw new org.springframework.ldap.InvalidNameException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw new org.springframework.ldap.InvalidNameException(ex);
|
||||
}
|
||||
|
||||
return temporaryName;
|
||||
|
||||
@@ -83,8 +83,8 @@ public class DifferentSubtreeTempEntryRenamingStrategy implements TempEntryRenam
|
||||
|
||||
return newName;
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
throw new org.springframework.ldap.InvalidNameException(e);
|
||||
catch (InvalidNameException ex) {
|
||||
throw new org.springframework.ldap.InvalidNameException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ public abstract class AbstractCompensatingTransactionManagerDelegate {
|
||||
TransactionSynchronizationManager.bindResource(getTransactionSynchronizationKey(), contextHolder);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CannotCreateTransactionException("Could not create DirContext instance for transaction", e);
|
||||
catch (Exception ex) {
|
||||
throw new CannotCreateTransactionException("Could not create DirContext instance for transaction", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,4 @@ public abstract class CompensatingTransactionHolderSupport extends ResourceHolde
|
||||
this.transactionOperationManager = transactionOperationManager;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +55,4 @@ public class CompensatingTransactionObject {
|
||||
this.holder = holder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ public final class CompensatingTransactionUtils {
|
||||
try {
|
||||
method.invoke(target, args);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
catch (InvocationTargetException ex) {
|
||||
throw ex.getTargetException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class DefaultCompensatingTransactionOperationManager implements Compensat
|
||||
try {
|
||||
rollbackOperation.rollback();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new TransactionSystemException("Error occurred during rollback", e);
|
||||
catch (Exception ex) {
|
||||
throw new TransactionSystemException("Error occurred during rollback", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,8 +110,8 @@ public class DefaultCompensatingTransactionOperationManager implements Compensat
|
||||
try {
|
||||
operationExecutor.commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new TransactionSystemException("Error occurred during commit", e);
|
||||
catch (Exception ex) {
|
||||
throw new TransactionSystemException("Error occurred during commit", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user