View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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.config.ConfigContext;
23  import org.kuali.rice.core.reflect.ObjectDefinition;
24  import org.kuali.rice.core.resourceloader.BaseWrappingResourceLoader;
25  import org.kuali.rice.core.resourceloader.ServiceLocator;
26  import org.kuali.rice.kew.plugin.PluginRegistry;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  import org.kuali.rice.kew.util.KEWConstants;
29  
30  
31  /**
32   * A resource loader which is responsible for loading resources from the Workflow ConfigContext.
33   *
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class CoreResourceLoader extends BaseWrappingResourceLoader {
37  
38  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
39  			.getLogger(CoreResourceLoader.class);
40  
41  	public static final QName NAME = new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), "KEW_SPRING+PLUGIN_REGISTRY_CONTAINER_RESOURCE_LOADER");
42  
43  	private final PluginRegistry registry;
44  
45  	public CoreResourceLoader(ServiceLocator serviceLocator, PluginRegistry registry) {
46  		super(CoreResourceLoader.NAME, serviceLocator);
47  		this.registry = registry;
48  	}
49  
50  	/**
51  	 * Overrides the standard getService method to looks for the service in the plugin if it can't find it in the core.
52  	 */
53  	public Object getService(QName serviceName) {
54  		if (isRemoteService(serviceName)) {
55  			return null;
56  		}
57  		Object service = super.getService(serviceName);
58  		if (service == null && getRegistry() != null) {
59  		    service = getRegistry().getService(serviceName);
60  		}
61  		return service;
62  	}
63  
64  
65  
66  	@Override
67  	public Object getObject(ObjectDefinition objectDefinition) {
68  	    Object object = super.getObject(objectDefinition);
69  	    if (object == null && getRegistry() != null) {
70  		object = getRegistry().getObject(objectDefinition);
71  	    }
72  	    return object;
73  	}
74  
75  	@Override
76  	protected boolean shouldWrapService(QName serviceName, Object service) {
77  		// transaction template is not wrappable because it does not implement an interface
78  		if (serviceName.getLocalPart().equals("transactionTemplate")) {
79  			return false;
80  		}
81  		return super.shouldWrapService(serviceName, service);
82  	}
83  	
84  	
85  	
86  	@Override
87  	public void stop() throws Exception {
88  		if (getRegistry() != null) {
89  			registry.stop();
90  		}
91  		super.stop();
92  	}
93  
94  	/**
95  	 * Returns true if the given service name is one which should be loaded from the service bus.  This is used
96  	 * primarily for embedded clients that want to reference the workgroup and user services on a standalone
97  	 * server.
98  	 */
99  	protected boolean isRemoteService(QName serviceName) {
100 	    return (useRemoteEmailServices() &&
101 			    serviceName.getLocalPart().equals(KEWServiceLocator.IMMEDIATE_EMAIL_REMINDER_SERVICE));
102 	}
103 		
104 	protected boolean useRemoteEmailServices() {
105 	    String useRemoteEmailServicesValue = ConfigContext.getCurrentContextConfig().getProperty(KEWConstants.USE_REMOTE_EMAIL_SERVICES);
106 	    if (!StringUtils.isBlank(useRemoteEmailServicesValue)) {
107 	        return new Boolean(useRemoteEmailServicesValue.trim());
108 	    }
109 	    return false;
110 	}
111 
112 	public PluginRegistry getRegistry() {
113 		return registry;
114 	}
115 	
116 }