001/**
002 * Copyright 2005-2014 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.core;
017
018import org.springframework.beans.factory.FactoryBean;
019
020/**
021 * The entire purpose of this class is to wrap an otherwise normal bean
022 * whose class is dynamically set at runtime through the PropertyPlaceholderConfigurer
023 * because the <bean> element attributes themselves are not parameterizable,
024 * only the property values. 
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class BeanHolder implements FactoryBean {
028    private Class clazz;
029    private Object instance;
030
031    public synchronized Object getObject() throws Exception {
032        if (this.instance == null) {
033            this.instance = this.clazz.newInstance();
034        }
035        return this.instance;
036    }
037
038    public Class getObjectType() {
039        return this.clazz;
040    }
041
042    public void setObjectType(Class clazz) {
043        this.clazz = clazz;
044    }
045
046    public boolean isSingleton() {
047        return true;
048    }
049}