1 | /* |
2 | * Copyright 2002-2013 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.listener; |
17 | |
18 | import org.springframework.batch.core.JobExecutionListener; |
19 | |
20 | /** |
21 | * This {@link AbstractListenerFactoryBean} implementation is used to create a |
22 | * {@link JobExecutionListener}. |
23 | * |
24 | * @author Lucas Ward |
25 | * @author Dan Garrette |
26 | * @since 2.0 |
27 | * @see AbstractListenerFactoryBean |
28 | * @see JobListenerMetaData |
29 | */ |
30 | public class JobListenerFactoryBean extends AbstractListenerFactoryBean { |
31 | |
32 | @Override |
33 | protected ListenerMetaData getMetaDataFromPropertyName(String propertyName) { |
34 | return JobListenerMetaData.fromPropertyName(propertyName); |
35 | } |
36 | |
37 | @Override |
38 | protected ListenerMetaData[] getMetaDataValues() { |
39 | return JobListenerMetaData.values(); |
40 | } |
41 | |
42 | @Override |
43 | protected Class<?> getDefaultListenerClass() { |
44 | return JobExecutionListener.class; |
45 | } |
46 | |
47 | @Override |
48 | public Class<?> getObjectType() { |
49 | return JobExecutionListener.class; |
50 | } |
51 | |
52 | /** |
53 | * Convenience method to wrap any object and expose the appropriate |
54 | * {@link JobExecutionListener} interfaces. |
55 | * |
56 | * @param delegate a delegate object |
57 | * @return a JobListener instance constructed from the delegate |
58 | */ |
59 | public static JobExecutionListener getListener(Object delegate) { |
60 | JobListenerFactoryBean factory = new JobListenerFactoryBean(); |
61 | factory.setDelegate(delegate); |
62 | return (JobExecutionListener) factory.getObject(); |
63 | } |
64 | |
65 | /** |
66 | * Convenience method to check whether the given object is or can be made |
67 | * into a {@link JobExecutionListener}. |
68 | * |
69 | * @param delegate the object to check |
70 | * @return true if the delegate is an instance of |
71 | * {@link JobExecutionListener}, or contains the marker annotations |
72 | */ |
73 | public static boolean isListener(Object delegate) { |
74 | return AbstractListenerFactoryBean.isListener(delegate, JobExecutionListener.class, JobListenerMetaData |
75 | .values()); |
76 | } |
77 | } |