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.configuration.support; |
18 | |
19 | import java.util.Map; |
20 | |
21 | import org.apache.commons.logging.Log; |
22 | import org.apache.commons.logging.LogFactory; |
23 | import org.springframework.batch.core.configuration.JobFactory; |
24 | import org.springframework.batch.core.configuration.JobRegistry; |
25 | |
26 | /** |
27 | * Generic service that can bind and unbind a {@link JobFactory} in a |
28 | * {@link JobRegistry}. |
29 | * |
30 | * @author Dave Syer |
31 | * |
32 | */ |
33 | public class JobFactoryRegistrationListener { |
34 | |
35 | private Log logger = LogFactory.getLog(getClass()); |
36 | |
37 | private JobRegistry jobRegistry; |
38 | |
39 | /** |
40 | * Public setter for a {@link JobRegistry} to use for all the bind and |
41 | * unbind events. |
42 | * |
43 | * @param jobRegistry {@link JobRegistry} |
44 | */ |
45 | public void setJobRegistry(JobRegistry jobRegistry) { |
46 | this.jobRegistry = jobRegistry; |
47 | } |
48 | |
49 | /** |
50 | * Take the {@link JobFactory} provided and register it with the |
51 | * {@link JobRegistry}. |
52 | * @param jobFactory a {@link JobFactory} |
53 | * @param params not needed by this listener. |
54 | * @throws Exception if there is a problem |
55 | */ |
56 | public void bind(JobFactory jobFactory, Map<String, ?> params) throws Exception { |
57 | logger.info("Binding JobFactory: " + jobFactory.getJobName()); |
58 | jobRegistry.register(jobFactory); |
59 | } |
60 | |
61 | /** |
62 | * Take the {@link JobFactory} provided and unregister it with the |
63 | * {@link JobRegistry}. |
64 | * @param jobFactory a {@link JobFactory} |
65 | * @param params not needed by this listener. |
66 | * @throws Exception if there is a problem |
67 | */ |
68 | public void unbind(JobFactory jobFactory, Map<String, ?> params) throws Exception { |
69 | logger.info("Unbinding JobFactory: " + jobFactory.getJobName()); |
70 | jobRegistry.unregister(jobFactory.getJobName()); |
71 | } |
72 | |
73 | } |