org.investovator.agentsimulation.InvestovatorSimulationController.java Source code

Java tutorial

Introduction

Here is the source code for org.investovator.agentsimulation.InvestovatorSimulationController.java

Source

/*
 * investovator, Stock Market Gaming framework
 * Copyright (C) 2013  investovator
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.investovator.agentsimulation;

import net.sourceforge.jabm.Simulation;
import net.sourceforge.jabm.SpringSimulationController;
import net.sourceforge.jabm.init.SpringSimulationFactory;
import net.sourceforge.jabm.spring.SimulationScope;
import net.sourceforge.jasa.market.MarketSimulation;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author Amila Surendra
 * @version $Revision
 */
public class InvestovatorSimulationController extends SpringSimulationController {

    private static boolean isPropSet = false;

    @Override
    public void afterPropertiesSet() throws Exception {

        //if(!isPropSet){
        Object configurer = beanFactory.getBean("configurer");

        if (configurer != null) {
            PropertyPlaceholderConfigurer test = (PropertyPlaceholderConfigurer) configurer;
            test.postProcessBeanFactory((ConfigurableListableBeanFactory) beanFactory);
            isPropSet = true;
        }
        // }

        this.simulation = (Simulation) beanFactory.getBean(simulationBeanName);
        this.simulationScope = SimulationScope.getSingletonInstance();
        if (this.simulationFactory == null) {
            this.simulationFactory = new SpringSimulationFactory();
        }
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = (DefaultListableBeanFactory) beanFactory;
    }
}