001 /**
002 * Copyright 2005-2013 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 org.kuali.rice.core.api.config.CoreConfigHelper;
019 import org.kuali.rice.core.api.config.property.ConfigContext;
020 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
021 import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader;
022 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
023 import org.kuali.rice.ksb.api.bus.ServiceBus;
024
025 import javax.xml.namespace.QName;
026
027
028
029 /**
030 * Creates KSBs root resource loader with all the correct children attached ready for starting.
031 * Uses config object to store QNames so everything is good with the current context classloader.
032 *
033 * Can grab any KSB specific resource loader from the resource loading stack.
034 *
035 *
036 * @author Kuali Rice Team (rice.collab@kuali.org)
037 *
038 */
039 public class KSBResourceLoaderFactory {
040
041 private static final String KSB_ROOT_RESOURCE_LOACER_NAME = "KSB_ROOT_RESOURCE_LOADER";
042 private static final String KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME = "KSB_REMOTE_RESOURCE_LOADER";
043
044 private static void initialize() {
045 String applicationId = CoreConfigHelper.getApplicationId();
046 if (getRootResourceLoaderName() == null) {
047 setRootResourceLoaderName(new QName(applicationId, KSB_ROOT_RESOURCE_LOACER_NAME));
048 }
049 if (getRemoteResourceLoaderName() == null) {
050 setRemoteResourceLoaderName(new QName(applicationId, KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME));
051 }
052 }
053
054 public static ResourceLoader createRootKSBRemoteResourceLoader() {
055 initialize();
056 ResourceLoader rootResourceLoader = new BaseResourceLoader(getRootResourceLoaderName());
057 ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
058 if (serviceBus == null) {
059 throw new IllegalStateException("Failed to locate the ServiceBus");
060 }
061 rootResourceLoader.addResourceLoader(new ServiceBusResourceLoader(getRemoteResourceLoaderName(), serviceBus));
062 return rootResourceLoader;
063 }
064
065 public static QName getRootResourceLoaderName() {
066 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_ROOT_RESOURCE_LOACER_NAME);
067 }
068
069 public static void setRootResourceLoaderName(QName name) {
070 ConfigContext.getCurrentContextConfig().putObject(KSB_ROOT_RESOURCE_LOACER_NAME, name);
071 }
072
073 public static QName getRemoteResourceLoaderName() {
074 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME);
075 }
076
077 public static void setRemoteResourceLoaderName(QName remoteResourceLoaderName) {
078 ConfigContext.getCurrentContextConfig().putObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME, remoteResourceLoaderName);
079 }
080
081 }