01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.kuali.rice.resourceloader;
18:
19: import javax.xml.namespace.QName;
20:
21: import org.apache.log4j.Logger;
22: import org.springframework.context.ConfigurableApplicationContext;
23: import org.springframework.context.support.ClassPathXmlApplicationContext;
24:
25: /**
26: * A simple {@link ResourceLoader} which wraps a Spring {@link ConfigurableApplicationContext}.
27: *
28: * Starts and stops the {@link ConfigurableApplicationContext}.
29: *
30: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
31: */
32: public class SpringResourceLoader extends BaseResourceLoader {
33:
34: private static final Logger LOG = Logger
35: .getLogger(SpringResourceLoader.class);
36:
37: private ConfigurableApplicationContext context;
38:
39: private String fileLoc;
40:
41: public SpringResourceLoader(QName name, String fileLoc) {
42: super (name);
43: this .fileLoc = fileLoc;
44: }
45:
46: public Object getService(QName serviceName) {
47: if (this .getContext().containsBean(serviceName.toString())) {
48: Object service = this .getContext().getBean(
49: serviceName.toString());
50: return postProcessService(serviceName, service);
51: }
52: return super .getService(serviceName);
53: }
54:
55: @Override
56: public void start() throws Exception {
57: LOG.info("Creating Spring context " + this .fileLoc);
58: this .context = new ClassPathXmlApplicationContext(this .fileLoc);
59: super .start();
60: }
61:
62: @Override
63: public void stop() throws Exception {
64: LOG.info("Stoping Spring context " + this .fileLoc);
65: this .context.close();
66: super .stop();
67: }
68:
69: public ConfigurableApplicationContext getContext() {
70: return this.context;
71: }
72:
73: }
|