01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.scheduling.timer;
18:
19: import java.util.TimerTask;
20:
21: import org.springframework.beans.factory.FactoryBean;
22: import org.springframework.scheduling.support.MethodInvokingRunnable;
23:
24: /**
25: * FactoryBean that exposes a TimerTask object that delegates
26: * job execution to a specified (static or non-static) method.
27: * Avoids the need to implement a one-line TimerTask that just
28: * invokes an existing business method.
29: *
30: * <p>Derives from MethodInvokingRunnable to share common properties
31: * and behavior, effectively providing a TimerTask adapter for it.
32: *
33: * <p>Often used to populate a ScheduledTimerTask object with a specific
34: * reflective method invocation. Note that you can alternatively populate
35: * a ScheduledTimerTask object with a plain MethodInvokingRunnable instance
36: * as well (as of Spring 1.2.4), without the need for this special FactoryBean.
37: *
38: * @author Juergen Hoeller
39: * @since 19.02.2004
40: * @see DelegatingTimerTask
41: * @see ScheduledTimerTask#setTimerTask
42: * @see ScheduledTimerTask#setRunnable
43: * @see org.springframework.scheduling.support.MethodInvokingRunnable
44: * @see org.springframework.beans.factory.config.MethodInvokingFactoryBean
45: */
46: public class MethodInvokingTimerTaskFactoryBean extends
47: MethodInvokingRunnable implements FactoryBean {
48:
49: private TimerTask timerTask;
50:
51: public void afterPropertiesSet() throws ClassNotFoundException,
52: NoSuchMethodException {
53: super .afterPropertiesSet();
54: this .timerTask = new DelegatingTimerTask(this );
55: }
56:
57: public Object getObject() {
58: return this .timerTask;
59: }
60:
61: public Class getObjectType() {
62: return TimerTask.class;
63: }
64:
65: public boolean isSingleton() {
66: return true;
67: }
68:
69: }
|