Package com.kylietech.oaj.context

Source Code of com.kylietech.oaj.context.OAJContext

package com.kylietech.oaj.context;

import net.javalib.util.vl.ValueList;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.kylietech.oaj.common.util.OAServiceUtil;

/**
* @author Hani Naguib
*/
public class OAJContext implements InitializingBean, BeanFactoryAware  {
    private static Logger logger = Logger.getLogger(OAJContext.class);

    private static Object INIT_OBJ = null;
    private static BeanFactory BEAN_FACTORY;

    public static  synchronized void init(Object initObject) {
        if (INIT_OBJ == null) {
            INIT_OBJ = initObject;
            logger.info("OAJ Server context loading...");
            loadBeans();
        }
        else
            logger.warn("Attempting to initialise OAJ Server more than once.");
    }
   
    private static void loadBeans() {
        if (INIT_OBJ instanceof String)
            new FileSystemXmlApplicationContext(INIT_OBJ.toString());
    }

    /**
     * Method afterPropertiesSet
     */
    public void afterPropertiesSet() {
        logger.info("OAJ Server Initialized.");
    }   
   
    /**
     * Method setBeanFactory
     * @param beanFactory BeanFactory
     */
    public void setBeanFactory(BeanFactory beanFactory) {
        if (INIT_OBJ == null)
            INIT_OBJ = new Object();
        BEAN_FACTORY = beanFactory;
        ValueList.beanFactory = beanFactory;
        OAServiceUtil.context = beanFactory;
    }
   
    /**
     * Method getBean
     * @param beanName String
     * @return Object
     */
    public static Object getBean(String beanName) {
        if (BEAN_FACTORY == null) {
            return null;
        }
        return BEAN_FACTORY.getBean(beanName);
    }
   
   
}
TOP

Related Classes of com.kylietech.oaj.context.OAJContext

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.