Minor cleanup.

This commit is contained in:
Mattias Hellborg Arthursson
2013-11-18 14:54:43 +01:00
parent f89daf692e
commit 086497d66e
9 changed files with 18 additions and 16 deletions

View File

@@ -197,7 +197,7 @@ 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));
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e);
}
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.ldap.core;
import org.springframework.ldap.UncategorizedLdapException;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.slf4j.Logger;
@@ -536,7 +537,7 @@ public class DistinguishedName implements Name {
}
catch (CloneNotSupportedException e) {
log.error("CloneNotSupported thrown from superclass - this should not happen");
throw new RuntimeException("Fatal error in clone", e);
throw new UncategorizedLdapException("Fatal error in clone", e);
}
}

View File

@@ -1811,7 +1811,7 @@ public interface LdapOperations {
* @throws org.springframework.ldap.NamingException on error.
* @since 2.0
*/
public <T> List<T> find(Name base, Filter filter, SearchControls searchControls, Class<T> clazz);
<T> List<T> find(Name base, Filter filter, SearchControls searchControls, Class<T> clazz);
/**
* Search for entries in the LDAP directory. The referenced class must have object-directory

View File

@@ -163,7 +163,7 @@ public final class NameAwareAttribute implements Attribute {
newValuesAsNames.put(LdapUtils.newLdapName(s), s);
} catch (InvalidNameException e) {
throw new IllegalArgumentException("This instance has values that are not valid distinguished names; " +
"cannot handle Name values");
"cannot handle Name values", e);
}
} else {
throw new IllegalArgumentException("This instance has non-string attribute values; " +

View File

@@ -27,7 +27,7 @@ import java.util.List;
*/
public abstract class BinaryLogicalFilter extends AbstractFilter {
protected List<Filter> queryList = new LinkedList<Filter>();
private List<Filter> queryList = new LinkedList<Filter>();
public StringBuffer encode(StringBuffer buff) {
if (queryList.size() <= 0) {
@@ -47,7 +47,7 @@ public abstract class BinaryLogicalFilter extends AbstractFilter {
buff.append("(").append(getLogicalOperator());
for (Filter query : queryList) {
buff = query.encode(buff);
query.encode(buff);
}
buff.append(")");

View File

@@ -49,11 +49,8 @@ public class WhitespaceWildcardsFilter extends EqualsFilter {
return "*";
}
// trim value, we will add in stars first and last anywhay
value = value.trim();
// filter encode so that any stars etc. are preserved
String filterEncoded = LdapEncoder.filterEncode(value);
String filterEncoded = LdapEncoder.filterEncode(value.trim());
// Now replace all whitespace with stars
Matcher m = starReplacePattern.matcher(filterEncoded);

View File

@@ -130,7 +130,7 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper {
managedClass.getConstructor();
} catch (NoSuchMethodException e) {
throw new InvalidEntryException(String.format(
"The class %1$s must have a zero argument constructor to be an Entry", managedClass));
"The class %1$s must have a zero argument constructor to be an Entry", managedClass), e);
}
// Check we have all of the necessary converters for the class

View File

@@ -316,9 +316,9 @@ public final class SchemaToJava {
directory.mkdirs();
outputFile.createNewFile();
} catch (SecurityException se) {
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()));
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), se);
} catch (IOException ioe) {
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()));
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), ioe);
}
return outputFile;

View File

@@ -19,7 +19,10 @@ package org.springframework.ldap.test;
import org.apache.commons.io.IOUtils;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.ldap.UncategorizedLdapException;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.LdapAttributes;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
@@ -46,6 +49,7 @@ import java.util.Set;
* @author Mattias Hellborg Arthursson
*/
public final class LdapTestUtils {
private final static Logger logger = LoggerFactory.getLogger(LdapTestUtils.class);
public static final String DEFAULT_PRINCIPAL = "uid=admin,ou=system";
public static final String DEFAULT_PASSWORD = "secret";
@@ -103,7 +107,7 @@ public final class LdapTestUtils {
try {
embeddedServer = EmbeddedLdapServer.newEmbeddedServer(defaultPartitionName, defaultPartitionSuffix, port);
} catch (Exception e) {
throw new RuntimeException("Failed to start embedded server");
throw new UncategorizedLdapException("Failed to start embedded server", e);
}
}
@@ -190,7 +194,7 @@ public final class LdapTestUtils {
}
}
} catch (NamingException e) {
e.printStackTrace();
logger.debug("Error cleaning sub-contexts", e);
} finally {
try {
enumeration.close();
@@ -254,7 +258,7 @@ public final class LdapTestUtils {
context.bind(dn, null, record);
}
} catch (Exception e) {
throw new RuntimeException("Failed to populate LDIF", e);
throw new UncategorizedLdapException("Failed to populate LDIF", e);
}
}