001 /* 002 * Copyright 2007 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ksb.messaging.resourceloader; 017 018 import javax.xml.namespace.QName; 019 020 import org.kuali.rice.core.config.Config; 021 import org.kuali.rice.core.config.ConfigContext; 022 import org.kuali.rice.core.config.ConfigurationException; 023 import org.kuali.rice.core.resourceloader.BaseResourceLoader; 024 import org.kuali.rice.core.resourceloader.GlobalResourceLoader; 025 import org.kuali.rice.core.resourceloader.ResourceLoader; 026 import org.kuali.rice.core.resourceloader.SpringResourceLoader; 027 import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator; 028 import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocatorImpl; 029 030 031 032 /** 033 * Creates KSBs root resource loader with all the correct children attached ready for starting. 034 * Uses config object to store QNames so everything is good with the current context classloader. 035 * 036 * Can grab any KSB specific resource loader from the resource loading stack. 037 * 038 * 039 * @author Kuali Rice Team (rice.collab@kuali.org) 040 * 041 */ 042 public class KSBResourceLoaderFactory { 043 044 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger 045 .getLogger(KSBResourceLoaderFactory.class); 046 047 private static final String KSB_ROOT_RESOURCE_LOACER_NAME = "KSB_ROOT_RESOURCE_LOADER"; 048 private static final String KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME = "KSB_REMOTE_RESOURCE_LOADER"; 049 050 private static void initialize() { 051 Config config = ConfigContext.getCurrentContextConfig(); 052 if (config.getServiceNamespace() == null) { 053 throw new ConfigurationException("No service namespace available at this time"); 054 } 055 if (getRootResourceLoaderName() == null) { 056 setRootResourceLoaderName(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), KSB_ROOT_RESOURCE_LOACER_NAME)); 057 } 058 if (getRemoteResourceLoaderName() == null) { 059 setRemoteResourceLoaderName(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME)); 060 } 061 } 062 063 public static ResourceLoader createRootKSBRemoteResourceLoader() { 064 initialize(); 065 ResourceLoader rootResourceLoader = new BaseResourceLoader(getRootResourceLoaderName()); 066 rootResourceLoader.addResourceLoader(new RemoteResourceServiceLocatorImpl(getRemoteResourceLoaderName())); 067 return rootResourceLoader; 068 } 069 070 public static ResourceLoader createThinClientKSBResourceLoader() { 071 ResourceLoader resourceLoader = new SpringResourceLoader(new QName("", "KSB_THIN_CLIENT_RESOURCE_LOADER"), "classpath:org/kuali/rice/ksb/config/KSBThinClientSpringBeans.xml"); 072 GlobalResourceLoader.addResourceLoader(resourceLoader); 073 return resourceLoader; 074 } 075 076 public static BaseResourceLoader getRootResourceLoader() { 077 return (BaseResourceLoader)GlobalResourceLoader.getResourceLoader(getRootResourceLoaderName()); 078 } 079 080 public static RemoteResourceServiceLocator getRemoteResourceLocator() { 081 return (RemoteResourceServiceLocator)GlobalResourceLoader.getResourceLoader(getRemoteResourceLoaderName()); 082 } 083 084 public static QName getRootResourceLoaderName() { 085 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_ROOT_RESOURCE_LOACER_NAME); 086 } 087 088 public static void setRootResourceLoaderName(QName name) { 089 ConfigContext.getCurrentContextConfig().putObject(KSB_ROOT_RESOURCE_LOACER_NAME, name); 090 } 091 092 public static QName getRemoteResourceLoaderName() { 093 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME); 094 } 095 096 public static void setRemoteResourceLoaderName(QName remoteResourceLoaderName) { 097 ConfigContext.getCurrentContextConfig().putObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME, remoteResourceLoaderName); 098 } 099 100 }