com.love320.templateparser.factory.AppFactory.java Source code

Java tutorial

Introduction

Here is the source code for com.love320.templateparser.factory.AppFactory.java

Source

/**
 * Copyright (c) 2010-2011 love320.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 
 * Founder admin@love320.com
 */
package com.love320.templateparser.factory;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.love320.templateparser.factory.entity.BeanString;
import com.love320.templateparser.factory.impl.FactoryBeanImpl;
import com.love320.templateparser.util.ConfigBeanXML;
import com.love320.templateparser.util.FileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AppFactory {

    private final static Logger logger = LoggerFactory.getLogger(AppFactory.class);

    /*?
     * */
    private AppFactory() {
    };//?

    private static class AppFactorySing {
        private static AppFactory appFactory = new AppFactory();
    }

    public static AppFactory getAppFactory() {
        return AppFactorySing.appFactory;
    }

    //? end
    private Factory factory;
    private String[] conPath;
    private static Element DOCROOT;

    public void setConPath(String... pathS) {
        this.conPath = pathS;
    }

    private void xmlStr() {
        SAXReader sax = new SAXReader();
        try {
            Document document = sax.read(FileUtil.get(conPath[0]));
            DOCROOT = document.getRootElement();
        } catch (DocumentException e) {
            logger.error("DocumentException", e);
        }
    }

    public synchronized Factory getFactory() {
        if (factory == null) {
            //
            //factory = new FactoryImpl(DOCROOT).factoryInit();//?

            //
            BeanString bs = new BeanString();
            bs.setName("beanfactory");
            bs.setClassName("com.love320.templateparser.factory.impl.BeanFactoryImpl");

            //
            /*
            if(conPath != null){
               factory = new FactoryBeanImpl().factoryInit(bs,DOCROOT);//?
            }else{//?
               conPath = AppFactory.class.getResource("factoryconfig.xml").toString();//
               xmlStr();//?? Element DOCROOT
               factory = new FactoryBeanImpl().factoryInit(bs,DOCROOT);//?
            }
            */

            //
            DOCROOT = ConfigBeanXML.action("factoryConfig.xml", conPath);
            factory = new FactoryBeanImpl().factoryInit(bs, DOCROOT);//?

        }
        return factory;
    }

}