001 /**
002 * Copyright 2005-2012 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.kew.resourceloader;
017
018 import javax.xml.namespace.QName;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.rice.core.api.config.CoreConfigHelper;
022 import org.kuali.rice.core.api.config.property.ConfigContext;
023 import org.kuali.rice.core.api.reflect.ObjectDefinition;
024 import org.kuali.rice.core.api.resourceloader.ServiceLocator;
025 import org.kuali.rice.core.impl.resourceloader.BaseWrappingResourceLoader;
026 import org.kuali.rice.kew.api.KewApiServiceLocator;
027 import org.kuali.rice.kew.plugin.PluginRegistry;
028 import org.kuali.rice.kew.api.KewApiConstants;
029
030
031 /**
032 * A resource loader which is responsible for loading resources from the Workflow ConfigContext.
033 *
034 * @author Kuali Rice Team (rice.collab@kuali.org)
035 */
036 public class CoreResourceLoader extends BaseWrappingResourceLoader {
037
038 public static final QName NAME = new QName(CoreConfigHelper.getApplicationId(), "KEW_SPRING+PLUGIN_REGISTRY_CONTAINER_RESOURCE_LOADER");
039
040 private final PluginRegistry registry;
041
042 public CoreResourceLoader(ServiceLocator serviceLocator, PluginRegistry registry) {
043 super(CoreResourceLoader.NAME, serviceLocator);
044 this.registry = registry;
045 }
046
047 /**
048 * Overrides the standard getService method to looks for the service in the plugin if it can't find it in the core.
049 */
050 public Object getService(QName serviceName) {
051 if (isRemoteService(serviceName)) {
052 return null;
053 }
054 Object service = super.getService(serviceName);
055 if (service == null && getRegistry() != null) {
056 service = getRegistry().getService(serviceName);
057 }
058 return service;
059 }
060
061
062
063 @Override
064 public Object getObject(ObjectDefinition objectDefinition) {
065 Object object = super.getObject(objectDefinition);
066 if (object == null && getRegistry() != null) {
067 object = getRegistry().getObject(objectDefinition);
068 }
069 return object;
070 }
071
072 @Override
073 protected boolean shouldWrapService(QName serviceName, Object service) {
074 // transaction template is not wrappable because it does not implement an interface
075 if (serviceName.getLocalPart().equals("transactionTemplate")) {
076 return false;
077 }
078 return super.shouldWrapService(serviceName, service);
079 }
080
081
082
083 @Override
084 public void stop() throws Exception {
085 if (getRegistry() != null) {
086 registry.stop();
087 }
088 super.stop();
089 }
090
091 /**
092 * Returns true if the given service name is one which should be loaded from the service bus. This is used
093 * primarily for embedded clients that want to reference the workgroup and user services on a standalone
094 * server.
095 */
096 protected boolean isRemoteService(QName serviceName) {
097 return (useRemoteEmailServices() &&
098 serviceName.getLocalPart().equals(KewApiServiceLocator.IMMEDIATE_EMAIL_REMINDER_QUEUE.getLocalPart()));
099 }
100
101 protected boolean useRemoteEmailServices() {
102 String useRemoteEmailServicesValue = ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.USE_REMOTE_EMAIL_SERVICES);
103 if (!StringUtils.isBlank(useRemoteEmailServicesValue)) {
104 return new Boolean(useRemoteEmailServicesValue.trim());
105 }
106 return false;
107 }
108
109 public PluginRegistry getRegistry() {
110 return registry;
111 }
112
113 }