001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.core;
018:
019: import javax.xml.namespace.QName;
020:
021: import org.kuali.rice.core.Core;
022: import org.kuali.rice.definition.ObjectDefinition;
023: import org.kuali.rice.resourceloader.BaseWrappingResourceLoader;
024: import org.kuali.rice.resourceloader.ServiceLocator;
025:
026: import edu.iu.uis.eden.plugin.Plugin;
027: import edu.iu.uis.eden.plugin.PluginRegistry;
028:
029: /**
030: * A resource loader which is responsible for loading resources from the Workflow Core. It is responsible for
031: * searching for service overrides in the Institutional Plugin before falling back to default services
032: * from the core.
033: *
034: * @author Eric Westfall
035: */
036: public class CoreResourceLoader extends BaseWrappingResourceLoader {
037:
038: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(CoreResourceLoader.class);
040:
041: public static final QName NAME = new QName(Core
042: .getCurrentContextConfig().getMessageEntity(),
043: "KEW_SPRING+PLUGIN_REGISTRY_CONTAINER_RESOURCE_LOADER");
044:
045: private final PluginRegistry registry;
046:
047: public CoreResourceLoader(ServiceLocator serviceLocator,
048: PluginRegistry registry) {
049: super (CoreResourceLoader.NAME, serviceLocator);
050: this .registry = registry;
051: }
052:
053: /**
054: * Overrides the standard getService method to first look in the institutional plugin for the
055: * service with the given name and then fall back to the default implementation in the
056: * core (if it exists).
057: */
058: public Object getService(QName serviceName) {
059: if (getRegistry() != null) {
060: Plugin institutionalPlugin = getRegistry()
061: .getInstitutionalPlugin();
062: if (institutionalPlugin != null) {
063: Object service = institutionalPlugin
064: .getService(serviceName);
065: if (service != null) {
066: if (LOG.isDebugEnabled()) {
067: LOG.info("Retrieved service override for '"
068: + serviceName
069: + "' from the institutional plugin.");
070: }
071: return postProcessService(serviceName, service);
072: }
073: }
074: }
075: Object service = super .getService(serviceName);
076: if (service == null && getRegistry() != null) {
077: service = getRegistry().getService(serviceName);
078: }
079: return service;
080: }
081:
082: @Override
083: public Object getObject(ObjectDefinition objectDefinition) {
084: Object object = super .getObject(objectDefinition);
085: if (object == null && getRegistry() != null) {
086: object = getRegistry().getObject(objectDefinition);
087: }
088: return object;
089: }
090:
091: @Override
092: protected boolean shouldWrapService(QName serviceName,
093: Object service) {
094: // transaction template is not wrappable because it does not implement an interface
095: if (serviceName.getLocalPart().equals("transactionTemplate")) {
096: return false;
097: }
098: return super .shouldWrapService(serviceName, service);
099: }
100:
101: public PluginRegistry getRegistry() {
102: return registry;
103: }
104: }
|