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.amqp.builder; 018 019import org.springframework.amqp.core.AmqpTemplate; 020import org.springframework.batch.item.amqp.AmqpItemWriter; 021import org.springframework.util.Assert; 022 023/** 024 * A builder implementation for the {@link AmqpItemWriter} 025 * @author Glenn Renfro 026 * @since 4.0 027 * @see AmqpItemWriter 028 */ 029public class AmqpItemWriterBuilder<T> { 030 031 private AmqpTemplate amqpTemplate; 032 033 /** 034 * Establish the amqpTemplate to be used by the AmqpItemWriter. 035 * @param amqpTemplate the template to be used. 036 * @return this instance for method chaining 037 * @see AmqpItemWriter#AmqpItemWriter(AmqpTemplate) 038 */ 039 public AmqpItemWriterBuilder<T> amqpTemplate(AmqpTemplate amqpTemplate) { 040 this.amqpTemplate = amqpTemplate; 041 042 return this; 043 } 044 045 /** 046 * Validates and builds a {@link AmqpItemWriter}. 047 * 048 * @return a {@link AmqpItemWriter} 049 */ 050 public AmqpItemWriter<T> build() { 051 Assert.notNull(this.amqpTemplate, "amqpTemplate is required."); 052 053 AmqpItemWriter<T> writer = new AmqpItemWriter<>(this.amqpTemplate); 054 055 return writer; 056 } 057 058}