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 org.kuali.core.workflow;
017:
018: import java.util.HashSet;
019: import java.util.Set;
020:
021: import javax.xml.namespace.QName;
022:
023: import org.kuali.core.workflow.attribute.WorkflowLookupableImpl;
024: import org.kuali.rice.resourceloader.SpringBeanFactoryResourceLoader;
025:
026: import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
027:
028: /**
029: * A custom {@link edu.iu.uis.eden.plugin.ResourceLoader} which wraps a Spring BeanFactory and delegates certain
030: * service lookups to the BeanFactory.
031: */
032: public class KFSResourceLoader extends SpringBeanFactoryResourceLoader {
033:
034: private static final String CONVERSIONS_DELIMITER = "|";
035: private static final String LOOKUPABLE_REGEX = "workflow-.+-Lookupable(.+)";
036:
037: private Set<String> overridableServices = new HashSet<String>();
038:
039: public KFSResourceLoader() {
040: super (new QName("KFSResourceLoader"));
041: }
042:
043: @Override
044: public Object getService(QName serviceName) {
045: if (overridableServices.contains(serviceName.getLocalPart())) {
046: return super .getService(serviceName);
047: } else if (isKualiLookupable(serviceName)) {
048: return fetchKualiLookupable(serviceName);
049: } else if (serviceName.getLocalPart().indexOf("Lookupable") > -1) {
050: return super .getService(serviceName);
051: }
052: return null;
053: }
054:
055: protected boolean isKualiLookupable(QName serviceName) {
056: return serviceName.getLocalPart().matches(LOOKUPABLE_REGEX);
057: }
058:
059: protected Object fetchKualiLookupable(QName serviceName) {
060: String lookupableName = serviceName.getLocalPart();
061: WorkflowLookupable workflowLookupable = null;
062: if (lookupableName.indexOf(".") > 0) {
063: String lookupableImplName = lookupableName.substring(0,
064: lookupableName.indexOf("("));
065: WorkflowLookupableImpl workflowLookupableImpl = (WorkflowLookupableImpl) getBeanFactory()
066: .getBean(lookupableImplName);
067: String allConversions = lookupableName.substring(
068: lookupableName.indexOf("(") + 1, lookupableName
069: .indexOf(")"));
070: String fieldConversions = null;
071: String lookupParameters = null;
072: if (allConversions.indexOf(CONVERSIONS_DELIMITER) > 0) {
073: fieldConversions = allConversions.substring(0,
074: allConversions.indexOf(CONVERSIONS_DELIMITER));
075: lookupParameters = allConversions
076: .substring(allConversions
077: .indexOf(CONVERSIONS_DELIMITER) + 1);
078: } else {
079: fieldConversions = allConversions;
080: }
081: workflowLookupableImpl
082: .setFieldConversions(fieldConversions);
083: workflowLookupableImpl
084: .setLookupParameters(lookupParameters);
085: workflowLookupable = (WorkflowLookupable) super .wrap(
086: serviceName, workflowLookupableImpl);
087: } else {
088: workflowLookupable = (WorkflowLookupable) super
089: .getService(serviceName);
090: }
091: return workflowLookupable;
092: }
093:
094: public Set<String> getOverridableServices() {
095: return overridableServices;
096: }
097:
098: public void setOverridableServices(Set<String> overridableServices) {
099: this.overridableServices = overridableServices;
100: }
101:
102: }
|