View Javadoc

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.kew.resourceloader;
18  
19  import javax.xml.namespace.QName;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.core.api.config.CoreConfigHelper;
23  import org.kuali.rice.core.api.config.property.ConfigContext;
24  import org.kuali.rice.core.api.reflect.ObjectDefinition;
25  import org.kuali.rice.core.api.resourceloader.ServiceLocator;
26  import org.kuali.rice.core.impl.resourceloader.BaseWrappingResourceLoader;
27  import org.kuali.rice.kew.plugin.PluginRegistry;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.kew.util.KEWConstants;
30  
31  
32  /**
33   * A resource loader which is responsible for loading resources from the Workflow ConfigContext.
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public class CoreResourceLoader extends BaseWrappingResourceLoader {
38  
39  	public static final QName NAME = new QName(CoreConfigHelper.getApplicationId(), "KEW_SPRING+PLUGIN_REGISTRY_CONTAINER_RESOURCE_LOADER");
40  
41  	private final PluginRegistry registry;
42  
43  	public CoreResourceLoader(ServiceLocator serviceLocator, PluginRegistry registry) {
44  		super(CoreResourceLoader.NAME, serviceLocator);
45  		this.registry = registry;
46  	}
47  
48  	/**
49  	 * Overrides the standard getService method to looks for the service in the plugin if it can't find it in the core.
50  	 */
51  	public Object getService(QName serviceName) {
52  		if (isRemoteService(serviceName)) {
53  			return null;
54  		}
55  		Object service = super.getService(serviceName);
56  		if (service == null && getRegistry() != null) {
57  		    service = getRegistry().getService(serviceName);
58  		}
59  		return service;
60  	}
61  
62  
63  
64  	@Override
65  	public Object getObject(ObjectDefinition objectDefinition) {
66  	    Object object = super.getObject(objectDefinition);
67  	    if (object == null && getRegistry() != null) {
68  		object = getRegistry().getObject(objectDefinition);
69  	    }
70  	    return object;
71  	}
72  
73  	@Override
74  	protected boolean shouldWrapService(QName serviceName, Object service) {
75  		// transaction template is not wrappable because it does not implement an interface
76  		if (serviceName.getLocalPart().equals("transactionTemplate")) {
77  			return false;
78  		}
79  		return super.shouldWrapService(serviceName, service);
80  	}
81  	
82  	
83  	
84  	@Override
85  	public void stop() throws Exception {
86  		if (getRegistry() != null) {
87  			registry.stop();
88  		}
89  		super.stop();
90  	}
91  
92  	/**
93  	 * Returns true if the given service name is one which should be loaded from the service bus.  This is used
94  	 * primarily for embedded clients that want to reference the workgroup and user services on a standalone
95  	 * server.
96  	 */
97  	protected boolean isRemoteService(QName serviceName) {
98  	    return (useRemoteEmailServices() &&
99  			    serviceName.getLocalPart().equals(KEWServiceLocator.IMMEDIATE_EMAIL_REMINDER_SERVICE));
100 	}
101 		
102 	protected boolean useRemoteEmailServices() {
103 	    String useRemoteEmailServicesValue = ConfigContext.getCurrentContextConfig().getProperty(KEWConstants.USE_REMOTE_EMAIL_SERVICES);
104 	    if (!StringUtils.isBlank(useRemoteEmailServicesValue)) {
105 	        return new Boolean(useRemoteEmailServicesValue.trim());
106 	    }
107 	    return false;
108 	}
109 
110 	public PluginRegistry getRegistry() {
111 		return registry;
112 	}
113 	
114 }