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