001/* 002 * Copyright 2006-2007 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.repeat.policy; 018 019import org.springframework.batch.repeat.CompletionPolicy; 020import org.springframework.batch.repeat.RepeatStatus; 021import org.springframework.batch.repeat.RepeatContext; 022import org.springframework.batch.repeat.context.RepeatContextSupport; 023 024/** 025 * Very simple base class for {@link CompletionPolicy} implementations. 026 * 027 * @author Dave Syer 028 * 029 */ 030public class CompletionPolicySupport implements CompletionPolicy { 031 032 /** 033 * If exit status is not continuable return <code>true</code>, otherwise 034 * delegate to {@link #isComplete(RepeatContext)}. 035 * 036 * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, 037 * RepeatStatus) 038 */ 039 @Override 040 public boolean isComplete(RepeatContext context, RepeatStatus result) { 041 if (result != null && !result.isContinuable()) { 042 return true; 043 } 044 else { 045 return isComplete(context); 046 } 047 } 048 049 /** 050 * Always true. 051 * 052 * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext) 053 */ 054 @Override 055 public boolean isComplete(RepeatContext context) { 056 return true; 057 } 058 059 /** 060 * Build a new {@link RepeatContextSupport} and return it. 061 * 062 * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext) 063 */ 064 @Override 065 public RepeatContext start(RepeatContext context) { 066 return new RepeatContextSupport(context); 067 } 068 069 /** 070 * Increment the context so the counter is up to date. Do nothing else. 071 * 072 * @see org.springframework.batch.repeat.CompletionPolicy#update(org.springframework.batch.repeat.RepeatContext) 073 */ 074 @Override 075 public void update(RepeatContext context) { 076 if (context instanceof RepeatContextSupport) { 077 ((RepeatContextSupport) context).increment(); 078 } 079 } 080 081}