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.core.step.tasklet; |
18 | |
19 | import java.util.Map; |
20 | |
21 | import org.springframework.batch.core.ExitStatus; |
22 | import org.springframework.util.Assert; |
23 | |
24 | /** |
25 | * Maps exit codes to {@link org.springframework.batch.core.ExitStatus} |
26 | * according to injected map. The injected map is required to contain a value |
27 | * for 'else' key, this value will be returned if the injected map |
28 | * does not contain value for the exit code returned by the system process. |
29 | * |
30 | * @author Robert Kasanicky |
31 | */ |
32 | public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExitCodeMapper { |
33 | |
34 | public static final String ELSE_KEY = "else"; |
35 | |
36 | private Map<Object, ExitStatus> mappings; |
37 | |
38 | public ExitStatus getExitStatus(int exitCode) { |
39 | ExitStatus exitStatus = mappings.get(exitCode); |
40 | if (exitStatus != null) { |
41 | return exitStatus; |
42 | } else { |
43 | return mappings.get(ELSE_KEY); |
44 | } |
45 | } |
46 | |
47 | /** |
48 | * @param mappings <code>Integer</code> exit code keys to |
49 | * {@link org.springframework.batch.core.ExitStatus} values. |
50 | */ |
51 | public void setMappings(Map<Object, ExitStatus> mappings) { |
52 | Assert.notNull(mappings.get(ELSE_KEY)); |
53 | this.mappings = mappings; |
54 | } |
55 | |
56 | } |