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 | |
17 | package org.springframework.batch.repeat.policy; |
18 | |
19 | import org.springframework.batch.repeat.CompletionPolicy; |
20 | import org.springframework.batch.repeat.ExitStatus; |
21 | import org.springframework.batch.repeat.RepeatContext; |
22 | import org.springframework.batch.repeat.context.RepeatContextSupport; |
23 | |
24 | /** |
25 | * Very simple base class for {@link CompletionPolicy} implementations. |
26 | * |
27 | * @author Dave Syer |
28 | * |
29 | */ |
30 | public class CompletionPolicySupport implements CompletionPolicy { |
31 | |
32 | /** |
33 | * Delegate to {@link #isComplete(RepeatContext)}. |
34 | * |
35 | * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, |
36 | * ExitStatus) |
37 | */ |
38 | public boolean isComplete(RepeatContext context, ExitStatus result) { |
39 | return isComplete(context); |
40 | } |
41 | |
42 | /** |
43 | * Always true. |
44 | * |
45 | * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext) |
46 | */ |
47 | public boolean isComplete(RepeatContext context) { |
48 | return true; |
49 | } |
50 | |
51 | /** |
52 | * Build a new {@link RepeatContextSupport} and return it. |
53 | * |
54 | * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext) |
55 | */ |
56 | public RepeatContext start(RepeatContext context) { |
57 | return new RepeatContextSupport(context); |
58 | } |
59 | |
60 | /** |
61 | * Increment the context so the counter is up to date. Do nothing else. |
62 | * |
63 | * @see org.springframework.batch.repeat.CompletionPolicy#update(org.springframework.batch.repeat.RepeatContext) |
64 | */ |
65 | public void update(RepeatContext context) { |
66 | if (context instanceof RepeatContextSupport) { |
67 | ((RepeatContextSupport) context).increment(); |
68 | } |
69 | } |
70 | |
71 | } |