001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kns.web.servlet.dwr; 017 018import org.directwebremoting.spring.SpringCreator; 019import org.kuali.rice.core.api.config.property.ConfigContext; 020import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 021import org.kuali.rice.kew.api.doctype.DocumentTypeService; 022import org.springframework.beans.factory.BeanFactory; 023 024import java.lang.reflect.InvocationHandler; 025import java.lang.reflect.Method; 026import java.lang.reflect.Proxy; 027 028/** 029 * A {@link SpringCreator} that checks the {@link GlobalResourceLoader} for the 030 * bean name in question if the default {@link BeanFactory} (the applications) 031 * does not have the bean in question. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 * 035 */ 036public class GlobalResourceDelegatingSpringCreator extends SpringCreator { 037 038 public static final String KEW_RUN_MODE_PROPERTY = "kew.mode"; 039 public static final String DOCUMENT_TYPE_SERVICE = "enDocumentTypeService"; 040 041 @Override 042 public Object getInstance() throws InstantiationException { 043 044 //KULRICE-7770 enDocumentTypeService isn't supported in remote mode 045 if(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY).equals("REMOTE") && 046 this.getBeanName().equals(DOCUMENT_TYPE_SERVICE)) 047 { 048 return Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{DocumentTypeService.class}, 049 // trivial invocationHandler 050 new InvocationHandler() { 051 @Override 052 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 053 return null; 054 } 055 } 056 ); 057 } 058 059 Object bean = GlobalResourceLoader.getService(this.getBeanName()); 060 061 if (bean == null) { 062 throw new InstantiationException("Unable to find bean " + this.getBeanName() + " in Rice Global Resource Loader"); 063 } 064 065 return bean; 066 } 067 068}