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