Coverage Report - org.kuali.rice.core.resourceloader.ResourceLoaderServiceFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
ResourceLoaderServiceFactoryBean
0%
0/23
0%
0/4
1.231
 
 1  
 /*
 2  
  * Copyright 2007-2008 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.resourceloader;
 17  
 
 18  
 import javax.xml.namespace.QName;
 19  
 
 20  
 import org.kuali.rice.core.config.ConfigurationException;
 21  
 import org.kuali.rice.core.resourceloader.ResourceLoader;
 22  
 import org.springframework.beans.factory.BeanNameAware;
 23  
 import org.springframework.beans.factory.FactoryBean;
 24  
 import org.springframework.beans.factory.InitializingBean;
 25  
 
 26  
 /**
 27  
  * Exports services in the {@link GlobalResourceLoader} as beans available to Spring.
 28  
  * 
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class ResourceLoaderServiceFactoryBean implements BeanNameAware, FactoryBean, InitializingBean {
 32  
     /**
 33  
      * The service to retrieve.  If unset, defaults to bean name.
 34  
      */
 35  
     private String serviceName;
 36  
     /**
 37  
      * The KSB namespace in which to look for the service, default is null, which is 'local' services
 38  
      */
 39  
     private String namespace;
 40  
     /**
 41  
      * Whether we provide a singleton.  Since we cannot make that guarantee, the default is 'false'
 42  
      */
 43  
     private boolean singleton;
 44  
     /**
 45  
      * The resource loader in which to look up the service
 46  
      */
 47  
     private ResourceLoader resourceLoader;
 48  
 
 49  
     /**
 50  
      * @return the configured service name
 51  
      */
 52  
     public String getServiceName() {
 53  0
         return serviceName;
 54  
     }
 55  
 
 56  
     /**
 57  
      * @param serviceName the service name to retrieve from the ResourceLoader
 58  
      */
 59  
     public void setServiceName(String serviceName) {
 60  0
         this.serviceName = serviceName;
 61  0
     }
 62  
     
 63  
     /**
 64  
      * @return the namespace under which to look up the service/bean
 65  
      */
 66  
     public String getNamespace() {
 67  0
         return namespace;
 68  
     }
 69  
 
 70  
     /**
 71  
      * @param namespace the namespace under which to look up the service/bean
 72  
      */
 73  
     public void setNamespace(String namespace) {
 74  0
         this.namespace = namespace;
 75  0
     }
 76  
 
 77  
     /**
 78  
      * @param singleton whether we know that the target bean will be a singleton
 79  
      */
 80  
     public void setSingleton(boolean singleton) {
 81  0
         this.singleton = singleton;
 82  0
     }
 83  
 
 84  
     /**
 85  
      * @see org.springframework.beans.factory.FactoryBean#isSingleton()
 86  
      */
 87  
     public boolean isSingleton() {
 88  0
         return singleton;
 89  
     }
 90  
 
 91  
     /**
 92  
      * @param resourceLoader the ResourceLoader in which to look up the service
 93  
      */
 94  
     public void setResourceLoader(ResourceLoader resourceLoader) {
 95  0
         this.resourceLoader = resourceLoader;
 96  0
     }
 97  
 
 98  
     /**
 99  
      * @return the ResourceLoader with which this factory bean has been configured
 100  
      */
 101  
     public ResourceLoader getResourceLoader() {
 102  0
         return resourceLoader;
 103  
     }
 104  
     
 105  
     /**
 106  
      * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
 107  
      */
 108  
     public void setBeanName(String name) {
 109  
         // by default the service name is just the bean name
 110  0
         this.serviceName = name;
 111  0
     }
 112  
 
 113  
     public void afterPropertiesSet() throws Exception {
 114  0
         if (this.getServiceName() == null) {
 115  0
             throw new ConfigurationException("No serviceName given.");
 116  
         }
 117  0
         if (this.resourceLoader == null) {
 118  0
             this.resourceLoader = GlobalResourceLoader.getResourceLoader();
 119  
         }
 120  0
     }
 121  
 
 122  
     /**
 123  
      * Constructs a QName from the defined namespace and beanName
 124  
      * @param beanName the bean name to look up
 125  
      * @return a QName with beanName qualified with namespace
 126  
      */
 127  
     protected QName getQName(String beanName) {
 128  0
         return new QName(namespace, beanName);
 129  
     }
 130  
 
 131  
     /**
 132  
      * @see org.springframework.beans.factory.FactoryBean#getObject()
 133  
      */
 134  
     public Object getObject() throws Exception {
 135  0
         return resourceLoader.getService(getQName(this.getServiceName()));
 136  
     }
 137  
 
 138  
     /**
 139  
      * @see org.springframework.beans.factory.FactoryBean#getObjectType()
 140  
      */
 141  
     public Class getObjectType() {
 142  
         // we cannot know the type before lookup, so return null as per contract
 143  0
         return null;
 144  
     }
 145  
 }