1 | /* |
2 | * Copyright 2011 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 | package org.springframework.batch.core.job; |
17 | |
18 | import java.util.List; |
19 | |
20 | import org.springframework.batch.core.JobParameters; |
21 | import org.springframework.batch.core.JobParametersInvalidException; |
22 | import org.springframework.batch.core.JobParametersValidator; |
23 | import org.springframework.beans.factory.InitializingBean; |
24 | import org.springframework.util.Assert; |
25 | |
26 | /** |
27 | * Composite {@link JobParametersValidator} that passes the job parameters through a sequence of |
28 | * injected <code>JobParametersValidator</code>s |
29 | * |
30 | * @author Morten Andersen-Gott |
31 | * |
32 | */ |
33 | public class CompositeJobParametersValidator implements JobParametersValidator, InitializingBean { |
34 | |
35 | private List<JobParametersValidator> validators; |
36 | |
37 | /** |
38 | * Validates the JobParameters according to the injected JobParameterValidators |
39 | * Validation stops and exception is thrown on first validation error |
40 | * |
41 | * @param parameters some {@link JobParameters} |
42 | * @throws JobParametersInvalidException if the parameters are invalid |
43 | */ |
44 | public void validate(JobParameters parameters) throws JobParametersInvalidException { |
45 | for (JobParametersValidator validator : validators) { |
46 | validator.validate(parameters); |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * Public setter for the validators |
52 | * @param validators |
53 | */ |
54 | public void setValidators(List<JobParametersValidator> validators) { |
55 | this.validators = validators; |
56 | } |
57 | |
58 | public void afterPropertiesSet() throws Exception { |
59 | Assert.notNull(validators, "The 'validators' may not be null"); |
60 | Assert.notEmpty(validators, "The 'validators' may not be empty"); |
61 | } |
62 | |
63 | |
64 | |
65 | } |