View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.context;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  import javax.xml.namespace.QName;
25  
26  import org.kuali.rice.core.impl.resourceloader.SpringBeanFactoryResourceLoader;
27  
28  /**
29   * A custom {@link org.kuali.rice.kew.plugin.ResourceLoader} which wraps a Spring BeanFactory and delegates certain service lookups to
30   * the BeanFactory.
31   */
32  public class FinancialSystemResourceLoader extends SpringBeanFactoryResourceLoader {
33  
34      private static final String CONVERSIONS_DELIMITER = "|";
35      //private static final String LOOKUPABLE_REGEX = "workflow-.+-Lookupable(.+)";
36  
37      private Set<String> overridableServices = new HashSet<String>();
38  
39      public FinancialSystemResourceLoader() {
40          super(new QName("FinancialSystemResourceLoader"));
41      }
42  
43      @Override
44      public Object getService(QName serviceName) {
45          if (overridableServices.contains(serviceName.getLocalPart())) {
46              return super.getService(serviceName);
47          }
48  //        else if (isKualiLookupable(serviceName)) {
49  //            return fetchKualiLookupable(serviceName);
50  //        }
51          else if (serviceName.getLocalPart().indexOf("Lookupable") > -1) {
52              return super.getService(serviceName);
53          }
54          else if (serviceName.getLocalPart().contains("InactivationBlockingDetectionService")) {
55              return super.getService(serviceName);
56          }
57          return null;
58      }
59  
60  //    protected boolean isKualiLookupable(QName serviceName) {
61  //        return serviceName.getLocalPart().matches(LOOKUPABLE_REGEX);
62  //    }
63  //
64  //    protected Object fetchKualiLookupable(QName serviceName) {
65  //        String lookupableName = serviceName.getLocalPart();
66  //        WorkflowLookupable workflowLookupable = null;
67  //        if (lookupableName.indexOf(".") > 0) {
68  //            String lookupableImplName = lookupableName.substring(0, lookupableName.indexOf("("));
69  //            WorkflowLookupableImpl workflowLookupableImpl = (WorkflowLookupableImpl) getBeanFactory().getBean(lookupableImplName);
70  //            String allConversions = lookupableName.substring(lookupableName.indexOf("(") + 1, lookupableName.indexOf(")"));
71  //            String fieldConversions = null;
72  //            String lookupParameters = null;
73  //            if (allConversions.indexOf(CONVERSIONS_DELIMITER) > 0) {
74  //                fieldConversions = allConversions.substring(0, allConversions.indexOf(CONVERSIONS_DELIMITER));
75  //                lookupParameters = allConversions.substring(allConversions.indexOf(CONVERSIONS_DELIMITER) + 1);
76  //            }
77  //            else {
78  //                fieldConversions = allConversions;
79  //            }
80  //            workflowLookupableImpl.setFieldConversions(fieldConversions);
81  //            workflowLookupableImpl.setLookupParameters(lookupParameters);
82  //            workflowLookupable = (WorkflowLookupable) super.wrap(serviceName, workflowLookupableImpl);
83  //        }
84  //        else {
85  //            workflowLookupable = (WorkflowLookupable) super.getService(serviceName);
86  //        }
87  //        return workflowLookupable;
88  //    }
89  
90      public Set<String> getOverridableServices() {
91          return overridableServices;
92      }
93  
94      public void setOverridableServices(Set<String> overridableServices) {
95          this.overridableServices = overridableServices;
96      }
97  
98  }