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