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  package org.kuali.rice.krad.util.spring;
17  
18  import org.springframework.beans.factory.BeanFactory;
19  import org.springframework.beans.factory.BeanFactoryAware;
20  import org.springframework.beans.factory.config.AbstractFactoryBean;
21  
22  
23  
24  /**
25   * This is a description of what this class does - jjhanso don't forget to fill this in.
26   *
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   *
29   */
30  public class IfExistsFactoryBean extends AbstractFactoryBean implements BeanFactoryAware {
31      private BeanFactory beanFactory;
32      private String beanName;
33      private Object customReturnValue;
34  
35      @Override
36      protected Object createInstance() throws Exception {
37          if (beanFactory.containsBean(beanName)) {
38              if (customReturnValue != null) {
39                  return customReturnValue;
40              } else {
41                  return beanFactory.getBean(beanName);
42              }
43          }
44          return null;
45      }
46  
47      /**
48       * This overridden method ...
49       *
50       * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType()
51       */
52      @Override
53      public Class getObjectType() {
54         return null;
55      }
56  
57      public BeanFactory getBeanFactory() {
58          return this.beanFactory;
59      }
60  
61      public String getBeanName() {
62          return this.beanName;
63      }
64  
65      public Object getCustomReturnValue() {
66          return this.customReturnValue;
67      }
68  
69      public void setBeanFactory(BeanFactory beanFactory) {
70          this.beanFactory = beanFactory;
71      }
72  
73      public void setBeanName(String beanName) {
74          this.beanName = beanName;
75      }
76  
77      public void setCustomReturnValue(Object customReturnValue) {
78          this.customReturnValue = customReturnValue;
79      }
80  
81  }