KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > scheduling > quartz > DelegatingJob


1 /*
2  * Copyright 2002-2006 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.scheduling.quartz;
18
19 import org.quartz.Job;
20 import org.quartz.JobExecutionContext;
21 import org.quartz.JobExecutionException;
22
23 import org.springframework.util.Assert;
24
25 /**
26  * Simple Quartz {@link org.quartz.Job} adapter that delegates to a
27  * given {@link java.lang.Runnable} instance.
28  *
29  * <p>Typically used in combination with property injection on the
30  * Runnable instance, receiving parameters from the Quartz JobDataMap
31  * that way instead of via the JobExecutionContext.
32  *
33  * @author Juergen Hoeller
34  * @since 2.0
35  * @see SpringBeanJobFactory
36  * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
37  */

38 public class DelegatingJob implements Job {
39
40     private final Runnable JavaDoc delegate;
41
42
43     /**
44      * Create a new DelegatingJob.
45      * @param delegate the Runnable implementation to delegate to
46      */

47     public DelegatingJob(Runnable JavaDoc delegate) {
48         Assert.notNull(delegate, "Delegate must not be null");
49         this.delegate = delegate;
50     }
51
52     /**
53      * Return the wrapped Runnable implementation.
54      */

55     public final Runnable JavaDoc getDelegate() {
56         return this.delegate;
57     }
58
59
60     /**
61      * Delegates execution to the underlying Runnable,
62      * converting any Exception thrown to a Quartz JobExecutionException
63      * (as required by the Job contract).
64      */

65     public void execute(JobExecutionContext context) throws JobExecutionException {
66         try {
67             this.delegate.run();
68         }
69         catch (Exception JavaDoc ex) {
70             throw new JobExecutionException(ex);
71         }
72     }
73
74 }
75
Popular Tags