EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.item.jms]

COVERAGE SUMMARY FOR SOURCE FILE [JmsItemReader.java]

nameclass, %method, %block, %line, %
JmsItemReader.java100% (1/1)80%  (4/5)90%  (79/88)87%  (15.7/18)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JmsItemReader100% (1/1)80%  (4/5)90%  (79/88)87%  (15.7/18)
afterPropertiesSet (): void 0%   (0/1)0%   (0/5)0%   (0/2)
setJmsTemplate (JmsOperations): void 100% (1/1)87%  (27/31)95%  (5.7/6)
JmsItemReader (): void 100% (1/1)100% (8/8)100% (2/2)
read (): Object 100% (1/1)100% (40/40)100% (6/6)
setItemType (Class): void 100% (1/1)100% (4/4)100% (2/2)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.item.jms;
18 
19import javax.jms.Message;
20 
21import org.apache.commons.logging.Log;
22import org.apache.commons.logging.LogFactory;
23import org.springframework.batch.item.ItemReader;
24import org.springframework.beans.factory.InitializingBean;
25import org.springframework.jms.core.JmsOperations;
26import org.springframework.jms.core.JmsTemplate;
27import org.springframework.util.Assert;
28 
29/**
30 * An {@link ItemReader} for JMS using a {@link JmsTemplate}. The template
31 * should have a default destination, which will be used to provide items in
32 * {@link #read()}.<br/>
33 * <br/>
34 * 
35 * The implementation is thread safe after its properties are set (normal
36 * singleton behavior).
37 * 
38 * @author Dave Syer
39 * 
40 */
41public class JmsItemReader<T> implements ItemReader<T>, InitializingBean {
42 
43        protected Log logger = LogFactory.getLog(getClass());
44 
45        protected Class<? extends T> itemType;
46 
47        protected JmsOperations jmsTemplate;
48 
49        /**
50         * Setter for jms template.
51         * 
52         * @param jmsTemplate a {@link JmsOperations} instance
53         */
54        public void setJmsTemplate(JmsOperations jmsTemplate) {
55                this.jmsTemplate = jmsTemplate;
56                if (jmsTemplate instanceof JmsTemplate) {
57                        JmsTemplate template = (JmsTemplate) jmsTemplate;
58                        Assert.isTrue(template.getReceiveTimeout() != JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT,
59                                        "JmsTemplate must have a receive timeout!");
60                        Assert.isTrue(template.getDefaultDestination() != null || template.getDefaultDestinationName() != null,
61                                        "JmsTemplate must have a defaultDestination or defaultDestinationName!");
62                }
63        }
64 
65        /**
66         * Set the expected type of incoming message payloads. Set this to
67         * {@link Message} to receive the raw underlying message.
68         * 
69         * @param itemType the java class of the items to be delivered. Typically
70         * the same as the class parameter
71         * 
72         * @throws IllegalStateException if the message payload is of the wrong
73         * type.
74         */
75        public void setItemType(Class<? extends T> itemType) {
76                this.itemType = itemType;
77        }
78 
79        @SuppressWarnings("unchecked")
80        public T read() {
81                if (itemType != null && itemType.isAssignableFrom(Message.class)) {
82                        return (T) jmsTemplate.receive();
83                }
84                Object result = jmsTemplate.receiveAndConvert();
85                if (itemType != null && result != null) {
86                        Assert.state(itemType.isAssignableFrom(result.getClass()),
87                                        "Received message payload of wrong type: expected [" + itemType + "]");
88                }
89                return (T) result;
90        }
91 
92        public void afterPropertiesSet() throws Exception {
93                Assert.notNull(this.jmsTemplate, "The 'jmsTemplate' is required.");
94        }
95}

[all classes][org.springframework.batch.item.jms]
EMMA 2.0.5312 (C) Vladimir Roubtsov