From 579ccf10c3f820bd61353e396ca8582cef8fab85 Mon Sep 17 00:00:00 2001 From: robokaso Date: Mon, 21 Jul 2008 09:19:54 +0000 Subject: [PATCH] IN PROGRESS - BATCH-712: Upgrade ItemReaders to use Parameterized types --- .../batch/item/jms/JmsItemReader.java | 17 ++++++++++------- .../batch/item/jms/JmsItemReaderTests.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java index 94133b872..06fd294a3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemReader.java @@ -45,13 +45,14 @@ import org.springframework.util.Assert; * @author Dave Syer * */ -public class JmsItemReader extends AbstractItemReader implements ItemRecoverer, ItemKeyGenerator, NewItemIdentifier { +public class JmsItemReader extends AbstractItemReader implements ItemRecoverer, ItemKeyGenerator, + NewItemIdentifier { protected Log logger = LogFactory.getLog(getClass()); private JmsOperations jmsTemplate; - private Class itemType; + private Class itemType; private String errorDestinationName; @@ -89,25 +90,27 @@ public class JmsItemReader extends AbstractItemReader implements ItemRecoverer, * Set the expected type of incoming message payloads. Set this to * {@link Message} to receive the raw underlying message. * - * @param itemType the java class of the items to be delivered. + * @param itemType the java class of the items to be delivered. Typically + * the same as the class parameter * * @throws IllegalStateException if the message payload is of the wrong * type. */ - public void setItemType(Class itemType) { + public void setItemType(Class itemType) { this.itemType = itemType; } - public Object read() { + @SuppressWarnings("unchecked") + public T read() { if (itemType != null && itemType.isAssignableFrom(Message.class)) { - return jmsTemplate.receive(); + return (T) jmsTemplate.receive(); } Object result = jmsTemplate.receiveAndConvert(); if (itemType != null && result != null) { Assert.state(itemType.isAssignableFrom(result.getClass()), "Received message payload of wrong type: expected [" + itemType + "]"); } - return result; + return (T) result; } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java index e0677a9f3..68b463a09 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java @@ -30,7 +30,7 @@ import org.springframework.jms.core.JmsOperations; public class JmsItemReaderTests extends TestCase { - JmsItemReader itemProvider = new JmsItemReader(); + JmsItemReader itemProvider = new JmsItemReader(); public void testNoItemTypeSunnyDay() { MockControl templateControl = MockControl.createControl(JmsOperations.class);