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