001/*
002 * Copyright 2017 the original author or authors.
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *          https://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.springframework.batch.item.jms.builder;
018
019import org.springframework.batch.item.jms.JmsItemWriter;
020import org.springframework.jms.core.JmsOperations;
021import org.springframework.util.Assert;
022
023/**
024 * Creates a fully qualified JmsItemWriter.
025 *
026 * @author Glenn Renfro
027 *
028 * @since 4.0
029 */
030public class JmsItemWriterBuilder<T> {
031
032        private JmsOperations jmsTemplate;
033
034        /**
035         * Establish the JMS template that will be used by the {@link JmsItemWriter}.
036         *
037         * @param jmsTemplate a {@link JmsOperations} instance
038         * @return this instance for method chaining.
039         * @see JmsItemWriter#setJmsTemplate(JmsOperations)
040         */
041        public JmsItemWriterBuilder<T> jmsTemplate(JmsOperations jmsTemplate) {
042                this.jmsTemplate = jmsTemplate;
043
044                return this;
045        }
046
047        /**
048         * Returns a fully constructed {@link JmsItemWriter}.
049         *
050         * @return a new {@link JmsItemWriter}
051         */
052        public JmsItemWriter<T> build() {
053                Assert.notNull(this.jmsTemplate, "jmsTemplate is required.");
054                JmsItemWriter<T> jmsItemWriter = new JmsItemWriter<>();
055
056                jmsItemWriter.setJmsTemplate(this.jmsTemplate);
057                return jmsItemWriter;
058        }
059}