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.krad.util.spring; 017 018import org.springframework.beans.factory.BeanFactory; 019import org.springframework.beans.factory.BeanFactoryAware; 020import org.springframework.beans.factory.config.AbstractFactoryBean; 021 022 023 024/** 025 * This is a description of what this class does - jjhanso don't forget to fill this in. 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 * 029 */ 030public class IfExistsFactoryBean extends AbstractFactoryBean implements BeanFactoryAware { 031 private BeanFactory beanFactory; 032 private String beanName; 033 private Object customReturnValue; 034 035 @Override 036 protected Object createInstance() throws Exception { 037 if (beanFactory.containsBean(beanName)) { 038 if (customReturnValue != null) { 039 return customReturnValue; 040 } else { 041 return beanFactory.getBean(beanName); 042 } 043 } 044 return null; 045 } 046 047 /** 048 * This overridden method ... 049 * 050 * @see org.springframework.beans.factory.config.AbstractFactoryBean#getObjectType() 051 */ 052 @Override 053 public Class getObjectType() { 054 return null; 055 } 056 057 public BeanFactory getBeanFactory() { 058 return this.beanFactory; 059 } 060 061 public String getBeanName() { 062 return this.beanName; 063 } 064 065 public Object getCustomReturnValue() { 066 return this.customReturnValue; 067 } 068 069 public void setBeanFactory(BeanFactory beanFactory) { 070 this.beanFactory = beanFactory; 071 } 072 073 public void setBeanName(String beanName) { 074 this.beanName = beanName; 075 } 076 077 public void setCustomReturnValue(Object customReturnValue) { 078 this.customReturnValue = customReturnValue; 079 } 080 081}