Coverage Report - org.kuali.rice.core.impl.resourceloader.SpringBeanFactoryResourceLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
SpringBeanFactoryResourceLoader
0%
0/14
0%
0/4
1.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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  
 package org.kuali.rice.core.impl.resourceloader;
 17  
 
 18  
 import javax.xml.namespace.QName;
 19  
 
 20  
 import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader;
 21  
 import org.springframework.beans.BeansException;
 22  
 import org.springframework.beans.factory.BeanFactory;
 23  
 import org.springframework.beans.factory.BeanFactoryAware;
 24  
 
 25  
 /**
 26  
  * A ResourceLoader that is BeanFactoryAware and can be wired inside of Spring to provide
 27  
  * resource loading capabilities to that Spring BeanFactory.
 28  
  *
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  
 public class SpringBeanFactoryResourceLoader extends BaseResourceLoader implements BeanFactoryAware {
 32  
 
 33  
         private BeanFactory beanFactory;
 34  
 
 35  
         public SpringBeanFactoryResourceLoader() {
 36  0
                 this(new QName("", "BeanFactoryResourceLoader"));
 37  0
         }
 38  
 
 39  
         public SpringBeanFactoryResourceLoader(QName name) {
 40  0
                 super(name);
 41  0
         }
 42  
 
 43  
         public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
 44  0
                 this.beanFactory = beanFactory;
 45  0
         }
 46  
 
 47  
         protected BeanFactory getBeanFactory() {
 48  0
                 return this.beanFactory;
 49  
         }
 50  
 
 51  
         @Override
 52  
         public Object getService(QName serviceName) {
 53  0
                 String resolvedServiceName = resolveServiceName(serviceName);
 54  0
                 if (this.beanFactory.containsBean(resolvedServiceName)) {
 55  0
                         Object service = this.beanFactory.getBean(resolvedServiceName);
 56  0
                         if (service != null) {
 57  0
                                 return postProcessService(serviceName, service);
 58  
                         }
 59  
                 }
 60  0
                 return super.getService(serviceName);
 61  
         }
 62  
 
 63  
         /**
 64  
          * Resolves the given QName service name to a String representation which is used
 65  
          * to lookup the service in Spring.  Default implementation simply calls toString()
 66  
          * on the QName.
 67  
          */
 68  
         protected String resolveServiceName(QName serviceName) {
 69  0
                 return serviceName.toString();
 70  
         }
 71  
 
 72  
 
 73  
 
 74  
 }