Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2006-2007 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.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.batch.item.jms;
An org.springframework.batch.item.ItemReader for JMS using a org.springframework.jms.core.JmsTemplate. The template should have a default destination, which will be used to provide items in read().

The implementation is thread safe after its properties are set (normal singleton behavior).

Author(s):
Dave Syer
public class JmsItemReader<T> implements ItemReader<T>, InitializingBean {
	protected Log logger = LogFactory.getLog(getClass());
	protected Class<? extends T> itemType;
Setter for jms template.

Parameters:
jmsTemplate a org.springframework.jms.core.JmsOperations instance
	public void setJmsTemplate(JmsOperations jmsTemplate) {
		this. = jmsTemplate;
		if (jmsTemplate instanceof JmsTemplate) {
			JmsTemplate template = (JmsTemplatejmsTemplate;
					"JmsTemplate must have a receive timeout!");
			Assert.isTrue(template.getDefaultDestination() != null || template.getDefaultDestinationName() != null,
					"JmsTemplate must have a defaultDestination or defaultDestinationName!");
		}
	}

Set the expected type of incoming message payloads. Set this to javax.jms.Message to receive the raw underlying message.

Parameters:
itemType the java class of the items to be delivered. Typically the same as the class parameter
Throws:
java.lang.IllegalStateException if the message payload is of the wrong type.
	public void setItemType(Class<? extends T> itemType) {
		this. = itemType;
	}
	@SuppressWarnings("unchecked")
	public T read() {
		if ( != null && .isAssignableFrom(Message.class)) {
			return (T) .receive();
		}
		if ( != null && result != null) {
					"Received message payload of wrong type: expected [" +  + "]");
		}
		return (T) result;
	}
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(this."The 'jmsTemplate' is required.");
	}
New to GrepCode? Check out our FAQ X