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.quartz;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21:
22: import org.quartz.xml.JobSchedulingDataProcessor;
23:
24: import org.springframework.context.ResourceLoaderAware;
25: import org.springframework.core.io.DefaultResourceLoader;
26: import org.springframework.core.io.ResourceLoader;
27: import org.springframework.scheduling.SchedulingException;
28:
29: /**
30: * Subclass of Quartz' JobSchedulingDataProcessor that considers
31: * given filenames as Spring resource locations.
32: *
33: * @author Juergen Hoeller
34: * @since 1.1
35: * @see org.springframework.core.io.ResourceLoader
36: */
37: public class ResourceJobSchedulingDataProcessor extends
38: JobSchedulingDataProcessor implements ResourceLoaderAware {
39:
40: private ResourceLoader resourceLoader = new DefaultResourceLoader();
41:
42: public void setResourceLoader(ResourceLoader resourceLoader) {
43: this .resourceLoader = (resourceLoader != null ? resourceLoader
44: : new DefaultResourceLoader());
45: }
46:
47: protected InputStream getInputStream(String fileName) {
48: try {
49: return this .resourceLoader.getResource(fileName)
50: .getInputStream();
51: } catch (IOException ex) {
52: throw new SchedulingException(
53: "Could not load job scheduling data XML file", ex);
54: }
55: }
56:
57: }
|