View Javadoc

1   /**
2    * Copyright 2005-2012 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  
17  package org.kuali.rice.kns.web.servlet.dwr;
18  
19  import org.directwebremoting.spring.SpringCreator;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.kew.api.doctype.DocumentTypeService;
23  import org.springframework.beans.factory.BeanFactory;
24  
25  import java.lang.reflect.InvocationHandler;
26  import java.lang.reflect.Method;
27  import java.lang.reflect.Proxy;
28  
29  /**
30   * A {@link SpringCreator} that checks the {@link GlobalResourceLoader} for the
31   * bean name in question if the default {@link BeanFactory} (the applications)
32   * does not have the bean in question.
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   * 
36   */
37  public class GlobalResourceDelegatingSpringCreator extends SpringCreator {
38  
39      public static final String KEW_RUN_MODE_PROPERTY = "kew.mode";
40      public static final String DOCUMENT_TYPE_SERVICE = "enDocumentTypeService";
41  
42  	@Override
43  	public Object getInstance() throws InstantiationException {
44  
45          //KULRICE-7770 enDocumentTypeService isn't supported in remote mode
46          if(ConfigContext.getCurrentContextConfig().getProperty(KEW_RUN_MODE_PROPERTY).equals("REMOTE") &&
47                  this.getBeanName().equals(DOCUMENT_TYPE_SERVICE))
48          {   
49              return Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[]{DocumentTypeService.class},
50                  // trivial invocationHandler
51                  new InvocationHandler() {
52                      @Override
53                      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
54                          return null;
55                      }
56                  }
57              );
58          }
59  
60          Object bean = GlobalResourceLoader.getService(this.getBeanName());
61      
62          if (bean == null) {
63              throw new InstantiationException("Unable to find bean " + this.getBeanName() + " in Rice Global Resource Loader");
64          }
65  
66          return bean;
67  	}
68  
69  }