01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
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: package org.kuali.rice.resourceloader;
17:
18: import javax.xml.namespace.QName;
19:
20: import org.kuali.rice.config.ConfigurationException;
21: import org.kuali.rice.core.Core;
22: import org.springframework.beans.BeansException;
23: import org.springframework.beans.factory.BeanFactory;
24: import org.springframework.beans.factory.BeanFactoryAware;
25: import org.springframework.beans.factory.InitializingBean;
26:
27: /**
28: * Wraps {@link BeanFactory} in {@link BeanFactoryResourceLoader} and places the {@link ResourceLoader}
29: * at the top of the {@link GlobalResourceLoader} stack.
30: *
31: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
32: *
33: */
34: public class RiceSpringResourceLoaderConfigurer implements
35: BeanFactoryAware, InitializingBean {
36:
37: private QName name;
38: private String localServiceName;
39: private String serviceNameSpaceURI;
40:
41: private BeanFactory beanFactory;
42:
43: public void setBeanFactory(BeanFactory beanFactory)
44: throws BeansException {
45: this .beanFactory = beanFactory;
46: }
47:
48: public void afterPropertiesSet() throws Exception {
49: if (this .name == null) {
50: if (this .getServiceNameSpaceURI() == null) {
51: this .setServiceNameSpaceURI(Core
52: .getCurrentContextConfig().getMessageEntity());
53: }
54: if (this .getLocalServiceName() == null) {
55: throw new ConfigurationException("Need to give "
56: + this .getClass().getName()
57: + " a LocalServiceName");
58: }
59: }
60:
61: ResourceLoader beanFactoryRL = new BeanFactoryResourceLoader(
62: getName(), this .beanFactory);
63: GlobalResourceLoader.addResourceLoaderFirst(beanFactoryRL);
64: }
65:
66: public QName getName() {
67: if (this .name == null) {
68: this .setName(new QName(this .getServiceNameSpaceURI(), this
69: .getLocalServiceName()));
70: }
71: return name;
72: }
73:
74: public void setName(QName name) {
75: this .name = name;
76: }
77:
78: public String getLocalServiceName() {
79: return localServiceName;
80: }
81:
82: public void setLocalServiceName(String localServiceName) {
83: this .localServiceName = localServiceName;
84: }
85:
86: public String getServiceNameSpaceURI() {
87: return serviceNameSpaceURI;
88: }
89:
90: public void setServiceNameSpaceURI(String serviceNameSpaceURI) {
91: this.serviceNameSpaceURI = serviceNameSpaceURI;
92: }
93:
94: }
|