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 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
036 */
037@Deprecated
038public class GlobalResourceDelegatingSpringCreator extends SpringCreator {
039
040    public static final String KEW_RUN_MODE_PROPERTY = "kew.mode";
041    public static final String DOCUMENT_TYPE_SERVICE = "enDocumentTypeService";
042
043        @Override
044        public Object getInstance() throws InstantiationException {
045
046        //KULRICE-7770 enDocumentTypeService isn't supported in remote mode
047        if(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY).equals("REMOTE") &&
048                this.getBeanName().equals(DOCUMENT_TYPE_SERVICE))
049        {   
050            return Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{DocumentTypeService.class},
051                // trivial invocationHandler
052                new InvocationHandler() {
053                    @Override
054                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
055                        return null;
056                    }
057                }
058            );
059        }
060
061        Object bean = GlobalResourceLoader.getService(this.getBeanName());
062    
063        if (bean == null) {
064            throw new InstantiationException("Unable to find bean " + this.getBeanName() + " in Rice Global Resource Loader");
065        }
066
067        return bean;
068        }
069
070}