Coverage Report - org.kuali.rice.krad.config.GlobalResourceLoaderServiceFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
GlobalResourceLoaderServiceFactoryBean
0%
0/24
0%
0/8
1.8
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.krad.config;
 18  
 
 19  
 import org.kuali.rice.core.api.config.ConfigurationException;
 20  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 21  
 import org.springframework.beans.factory.FactoryBean;
 22  
 import org.springframework.beans.factory.InitializingBean;
 23  
 
 24  
 /**
 25  
  * Exports services in the {@link org.kuali.rice.core.api.resourceloader.GlobalResourceLoader} as beans available to Spring.
 26  
  * 
 27  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 28  
  *
 29  
  */
 30  
 public class GlobalResourceLoaderServiceFactoryBean implements FactoryBean<Object>, InitializingBean {
 31  
 
 32  
         private String serviceName;
 33  
         private boolean singleton;
 34  
         private boolean mustExist;
 35  
 
 36  
         // used to prevent a stack overflow when trying to get the service
 37  0
         private boolean isFetchingService = false;
 38  
         
 39  0
         public GlobalResourceLoaderServiceFactoryBean() {
 40  0
                 this.mustExist = true;
 41  0
         }
 42  
         
 43  
         public Object getObject() throws Exception {
 44  0
                 if (isFetchingService) return null; // we already have been invoked, don't recurse, just return null.
 45  0
                 isFetchingService = true;
 46  
                 try {
 47  0
                         Object service = GlobalResourceLoader.getService(this.getServiceName());
 48  0
                         if (mustExist && service == null) {
 49  0
                                 throw new IllegalStateException("Service must exist and no service could be located with name: " + this.getServiceName());
 50  
                         }
 51  0
                         return service;
 52  
                 } finally {
 53  0
                         isFetchingService = false;
 54  
                 }
 55  
         }
 56  
 
 57  
         public Class<?> getObjectType() {
 58  0
                 return Object.class;
 59  
         }
 60  
 
 61  
         public boolean isSingleton() {
 62  0
                 return singleton;
 63  
         }
 64  
 
 65  
         public String getServiceName() {
 66  0
                 return serviceName;
 67  
         }
 68  
 
 69  
         public void setServiceName(String serviceName) {
 70  0
                 this.serviceName = serviceName;
 71  0
         }
 72  
 
 73  
         public void setSingleton(boolean singleton) {
 74  0
                 this.singleton = singleton;
 75  0
         }
 76  
         
 77  
         public boolean isMustExist() {
 78  0
                 return mustExist;
 79  
         }
 80  
         
 81  
         public void setMustExist(boolean mustExist) {
 82  0
                 this.mustExist = mustExist;
 83  0
         }
 84  
         
 85  
 
 86  
         public void afterPropertiesSet() throws Exception {
 87  0
                 if (this.getServiceName() == null) {
 88  0
                         throw new ConfigurationException("No serviceName given.");
 89  
                 }
 90  0
         }
 91  
 
 92  
 }