LDAP-238: ContextMapper and NameClassPairCallbackHandler now throws NamingException.

This commit is contained in:
Mattias Hellborg Arthursson
2013-08-28 17:11:15 +02:00
parent d2d050ee2d
commit 6bffcfe9b1
6 changed files with 27 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,11 @@
*/
package org.springframework.ldap.core;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
import java.util.LinkedList;
import java.util.List;
import javax.naming.NameClassPair;
/**
* A NameClassPairCallbackHandler to collect all results in an internal List.
*
@@ -46,7 +46,7 @@ public abstract class CollectingNameClassPairCallbackHandler implements
* {@link #getObjectFromNameClassPair(NameClassPair)} and add the result to
* the internal list.
*/
public void handleNameClassPair(NameClassPair nameClassPair) {
public final void handleNameClassPair(NameClassPair nameClassPair) throws NamingException {
list.add(getObjectFromNameClassPair(nameClassPair));
}
@@ -57,7 +57,8 @@ public abstract class CollectingNameClassPairCallbackHandler implements
* @param nameClassPair
* a NameClassPair from a search operation.
* @return an object constructed from the data in the NameClassPair.
* @throws NamingException if an error occurs.
*/
public abstract Object getObjectFromNameClassPair(
NameClassPair nameClassPair);
NameClassPair nameClassPair) throws NamingException;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,14 @@
package org.springframework.ldap.core;
import javax.naming.Binding;
import javax.naming.Name;
import javax.naming.directory.SearchResult;
import org.springframework.ldap.core.support.AbstractContextMapper;
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
import javax.naming.Binding;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.directory.SearchResult;
/**
* An interface used by LdapTemplate to map LDAP Contexts to beans. When a
* DirObjectFactory is set on the ContextSource, the objects returned from
@@ -60,6 +61,7 @@ public interface ContextMapper {
* <code>DirObjectFactory</code> has been specified on the
* <code>ContextSource</code>.
* @return an object built from the data in the context.
* @throws NamingException if an error occurs.
*/
Object mapFromContext(Object ctx);
Object mapFromContext(Object ctx) throws NamingException;
}

View File

@@ -19,6 +19,7 @@ import org.springframework.util.Assert;
import javax.naming.Binding;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
/**
* A CollectingNameClassPairCallbackHandler to wrap a ContextMapper. That is,
@@ -51,8 +52,10 @@ public class ContextMapperCallbackHandler extends
* @param nameClassPair
* a Binding instance.
* @return the Object returned from the mapper.
* @throws NamingException if an error occurs.
* @throws ObjectRetrievalException if the object of the nameClassPair is null.
*/
public Object getObjectFromNameClassPair(NameClassPair nameClassPair) {
public Object getObjectFromNameClassPair(NameClassPair nameClassPair) throws NamingException {
if (!(nameClassPair instanceof Binding)) {
throw new IllegalArgumentException("Parameter must be an instance of Binding");
}

View File

@@ -17,6 +17,7 @@
package org.springframework.ldap.core;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
/**
* Callback interface used by {@link LdapTemplate} search, list and listBindings
@@ -36,6 +37,8 @@ public interface NameClassPairCallbackHandler {
* @param nameClassPair
* the NameClassPair returned from the
* <code>NamingEnumeration</code>.
* @throws NamingException if an error occurs.
*/
void handleNameClassPair(NameClassPair nameClassPair);
void handleNameClassPair(NameClassPair nameClassPair) throws NamingException;
;
}

View File

@@ -20,6 +20,7 @@ import org.junit.Before;
import org.junit.Test;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -46,7 +47,7 @@ public class CollectingNameClassPairCallbackHandlerTest {
}
@Test
public void testHandleNameClassPair() {
public void testHandleNameClassPair() throws NamingException {
tested.handleNameClassPair(expectedNameClassPair);
List result = tested.getList();
assertEquals(1, result.size());

View File

@@ -19,6 +19,7 @@ import org.junit.Before;
import org.junit.Test;
import javax.naming.Binding;
import javax.naming.NamingException;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
@@ -42,7 +43,7 @@ public class ContextMapperCallbackHandlerTest {
}
@Test
public void testGetObjectFromNameClassPair() {
public void testGetObjectFromNameClassPair() throws NamingException {
Object expectedObject = "object";
Object expectedResult = "result";
Binding expectedBinding = new Binding("some name", expectedObject);
@@ -54,7 +55,7 @@ public class ContextMapperCallbackHandlerTest {
}
@Test(expected = ObjectRetrievalException.class)
public void testGetObjectFromNameClassPairObjectRetrievalException() {
public void testGetObjectFromNameClassPairObjectRetrievalException() throws NamingException {
Binding expectedBinding = new Binding("some name", null);
tested.getObjectFromNameClassPair(expectedBinding);
}