View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.servlet.dwr;
17  
18  import org.directwebremoting.spring.SpringCreator;
19  import org.kuali.rice.core.api.config.property.ConfigContext;
20  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
21  import org.kuali.rice.kew.api.doctype.DocumentTypeService;
22  import org.springframework.beans.factory.BeanFactory;
23  
24  import java.lang.reflect.InvocationHandler;
25  import java.lang.reflect.Method;
26  import java.lang.reflect.Proxy;
27  
28  /**
29   * A {@link SpringCreator} that checks the {@link GlobalResourceLoader} for the
30   * bean name in question if the default {@link BeanFactory} (the applications)
31   * does not have the bean in question.
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
36   */
37  @Deprecated
38  public class GlobalResourceDelegatingSpringCreator extends SpringCreator {
39  
40      public static final String KEW_RUN_MODE_PROPERTY = "kew.mode";
41      public static final String DOCUMENT_TYPE_SERVICE = "enDocumentTypeService";
42  
43  	@Override
44  	public Object getInstance() throws InstantiationException {
45  
46          //KULRICE-7770 enDocumentTypeService isn't supported in remote mode
47          if(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY).equals("REMOTE") &&
48                  this.getBeanName().equals(DOCUMENT_TYPE_SERVICE))
49          {   
50              return Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{DocumentTypeService.class},
51                  // trivial invocationHandler
52                  new InvocationHandler() {
53                      @Override
54                      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
55                          return null;
56                      }
57                  }
58              );
59          }
60  
61          Object bean = GlobalResourceLoader.getService(this.getBeanName());
62      
63          if (bean == null) {
64              throw new InstantiationException("Unable to find bean " + this.getBeanName() + " in Rice Global Resource Loader");
65          }
66  
67          return bean;
68  	}
69  
70  }