001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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 edu.iu.uis.eden.messaging.resourceloading;
017:
018: import javax.xml.namespace.QName;
019:
020: import org.kuali.rice.config.Config;
021: import org.kuali.rice.config.ConfigurationException;
022: import org.kuali.rice.core.Core;
023: import org.kuali.rice.resourceloader.BaseResourceLoader;
024: import org.kuali.rice.resourceloader.GlobalResourceLoader;
025: import org.kuali.rice.resourceloader.ResourceLoader;
026: import org.kuali.rice.resourceloader.SimpleServiceLocator;
027: import org.kuali.rice.resourceloader.SpringResourceLoader;
028:
029: import edu.iu.uis.eden.messaging.RemoteResourceServiceLocator;
030: import edu.iu.uis.eden.messaging.RemoteResourceServiceLocatorImpl;
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 (kuali-rice@googlegroups.com)
040: *
041: */
042: public class KSBResourceLoaderFactory {
043:
044: private static final String KSB_ROOT_RESOURCE_LOACER_NAME = "KSB_ROOT_RESOURCE_LOADER";
045: private static final String KSB_SPRING_RESOURCE_LOADER_LOCAL_NAME = "KSB_SPRING_RESOURCE_LOADER";
046: private static final String KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME = "KSB_REMOTE_RESOURCE_LOADER";
047:
048: private static void initialize() {
049: Config config = Core.getCurrentContextConfig();
050: if (config.getMessageEntity() == null) {
051: throw new ConfigurationException(
052: "No message entity available at this time");
053: }
054: if (getRootResourceLoaderName() == null) {
055: setRootResourceLoaderName(new QName(Core
056: .getCurrentContextConfig().getMessageEntity(),
057: KSB_ROOT_RESOURCE_LOACER_NAME));
058: }
059: if (getSpringResourceLoaderName() == null) {
060: setSpringResourceLoaderName(new QName(Core
061: .getCurrentContextConfig().getMessageEntity(),
062: KSB_SPRING_RESOURCE_LOADER_LOCAL_NAME));
063: }
064: if (getRemoteResourceLoaderName() == null) {
065: setRemoteResourceLoaderName(new QName(Core
066: .getCurrentContextConfig().getMessageEntity(),
067: KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME));
068: }
069: }
070:
071: public static ResourceLoader createRootKSBResourceLoader() {
072: initialize();
073: ResourceLoader rootResourceLoader = new BaseResourceLoader(
074: getRootResourceLoaderName(), new SimpleServiceLocator());
075: ResourceLoader springResourceLoader = new SpringResourceLoader(
076: getSpringResourceLoaderName(), "KSBSpringBeans.xml");
077: GlobalResourceLoader.addResourceLoader(rootResourceLoader);
078: rootResourceLoader.addResourceLoader(springResourceLoader);
079: rootResourceLoader
080: .addResourceLoader(new RemoteResourceServiceLocatorImpl(
081: getRemoteResourceLoaderName()));
082: return rootResourceLoader;
083: }
084:
085: public static BaseResourceLoader getRootResourceLoader() {
086: return (BaseResourceLoader) GlobalResourceLoader
087: .getResourceLoader(getRootResourceLoaderName());
088: }
089:
090: public static SpringResourceLoader getSpringResourceLoader() {
091: return (SpringResourceLoader) GlobalResourceLoader
092: .getResourceLoader(getSpringResourceLoaderName());
093: }
094:
095: public static RemoteResourceServiceLocator getRemoteResourceLocator() {
096: return (RemoteResourceServiceLocator) GlobalResourceLoader
097: .getResourceLoader(getRemoteResourceLoaderName());
098: }
099:
100: public static QName getRootResourceLoaderName() {
101: return (QName) Core.getCurrentContextConfig().getObject(
102: KSB_ROOT_RESOURCE_LOACER_NAME);
103: }
104:
105: public static void setRootResourceLoaderName(QName name) {
106: Core.getCurrentContextConfig().getObjects().put(
107: KSB_ROOT_RESOURCE_LOACER_NAME, name);
108: }
109:
110: public static QName getSpringResourceLoaderName() {
111: return (QName) Core.getCurrentContextConfig().getObject(
112: KSB_SPRING_RESOURCE_LOADER_LOCAL_NAME);
113: }
114:
115: public static void setSpringResourceLoaderName(
116: QName ksbRsourceLoaderName) {
117: Core.getCurrentContextConfig().getObjects().put(
118: KSB_SPRING_RESOURCE_LOADER_LOCAL_NAME,
119: ksbRsourceLoaderName);
120: }
121:
122: public static QName getRemoteResourceLoaderName() {
123: return (QName) Core.getCurrentContextConfig().getObject(
124: KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME);
125: }
126:
127: public static void setRemoteResourceLoaderName(
128: QName remoteResourceLoaderName) {
129: Core.getCurrentContextConfig().getObjects().put(
130: KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME,
131: remoteResourceLoaderName);
132: }
133:
134: }
|