Coverage Report - org.kuali.rice.core.impl.resourceloader.RiceResourceLoaderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
RiceResourceLoaderFactory
0%
0/38
0%
0/18
2.286
 
 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 java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.servlet.ServletContext;
 23  
 import javax.xml.namespace.QName;
 24  
 
 25  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 26  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 27  
 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
 28  
 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
 29  
 import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader;
 30  
 
 31  
 
 32  
 
 33  
 /**
 34  
  * Creates resource loader for rice spring context.
 35  
  * Uses config object to store QNames so everything is good with the current context classloader.
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class RiceResourceLoaderFactory {
 40  
 
 41  
         private static final String RICE_ROOT_RESOURCE_LOADER_NAME = "RICE_ROOT_RESOURCE_LOADER";
 42  
         private static final String RICE_SPRING_RESOURCE_LOADER_NAME = "RICE_SPRING_RESOURCE_LOADER_NAME";
 43  
         
 44  
         public static ResourceLoader createRootRiceResourceLoader(ServletContext context, List<String> springFileLocations, String prefix) {
 45  
                 //FIXME: RICE MODULARITY
 46  
                 //hack to not break the hack in ResourceLoaderContainer.moveKSBLoadersDownHack();
 47  0
                 if ("KSB".equals(prefix.toUpperCase())) {
 48  0
                         prefix = "K~S~B";
 49  
                 }
 50  
                 
 51  0
                 String applicationId = CoreConfigHelper.getApplicationId();
 52  0
                 final QName root = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_ROOT_RESOURCE_LOADER_NAME);
 53  
                 
 54  0
                 if (getRootResourceLoaderNames() == null || !getRootResourceLoaderNames().contains(root)) {
 55  0
                         addRootResourceLoaderName(root);
 56  
                 }
 57  
                 
 58  0
                 final QName spring = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_SPRING_RESOURCE_LOADER_NAME);
 59  0
                 if (getSpringResourceLoaderNames() == null || !getSpringResourceLoaderNames().contains(root)) {
 60  0
                         addSpringResourceLoaderName(spring);
 61  
                 }
 62  
                 
 63  0
                 final ResourceLoader rootResourceLoader = new BaseResourceLoader(root, new SimpleServiceLocator());
 64  
                 
 65  0
                 final ResourceLoader springResourceLoader = new SpringResourceLoader(spring, springFileLocations, context);
 66  0
                 rootResourceLoader.addResourceLoaderFirst(springResourceLoader);
 67  
                 
 68  0
                 return rootResourceLoader;
 69  
         }
 70  
 
 71  
         public static Collection<BaseResourceLoader> getRootResourceLoaders() {
 72  0
                 final Collection<QName> names = getRootResourceLoaderNames();
 73  0
                 final Collection<BaseResourceLoader> loaders = new ArrayList<BaseResourceLoader>();
 74  0
                 for (QName name : names) {
 75  0
                         loaders.add((BaseResourceLoader) GlobalResourceLoader.getResourceLoader(name));
 76  
                 }
 77  0
                 return loaders;
 78  
         }
 79  
 
 80  
         public static Collection<SpringResourceLoader> getSpringResourceLoaders() {
 81  0
                 final Collection<QName> names = getSpringResourceLoaderNames();
 82  0
                 final Collection<SpringResourceLoader> loaders = new ArrayList<SpringResourceLoader>();
 83  0
                 for (QName name : names) {
 84  0
                         loaders.add((SpringResourceLoader) GlobalResourceLoader.getResourceLoader(name));
 85  
                 }
 86  0
                 return loaders;
 87  
         }
 88  
 
 89  
         @SuppressWarnings("unchecked")
 90  
         private static Collection<QName> getRootResourceLoaderNames() {
 91  0
                 return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME);
 92  
         }
 93  
 
 94  
         private static void addRootResourceLoaderName(QName name) {
 95  
                 @SuppressWarnings("unchecked")
 96  0
                 Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME);
 97  0
                 if (names == null) {
 98  0
                         names = new ArrayList<QName>();
 99  
                 }
 100  0
                 names.add(name);
 101  
                 
 102  0
                 ConfigContext.getCurrentContextConfig().putObject(RICE_ROOT_RESOURCE_LOADER_NAME, names);
 103  0
         }
 104  
 
 105  
         @SuppressWarnings("unchecked")
 106  
         private static Collection<QName> getSpringResourceLoaderNames() {
 107  0
                 return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME);
 108  
         }
 109  
 
 110  
         private static void addSpringResourceLoaderName(QName name) {
 111  
                 @SuppressWarnings("unchecked")
 112  0
                 Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME);
 113  0
                 if (names == null) {
 114  0
                         names = new ArrayList<QName>();
 115  
                 }
 116  0
                 names.add(name);
 117  
                 
 118  0
                 ConfigContext.getCurrentContextConfig().putObject(RICE_SPRING_RESOURCE_LOADER_NAME, names);
 119  0
         }
 120  
 
 121  
 }