All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qa.framework.library.database.XmlToBean Maven / Gradle / Ivy

There is a newer version: 3.8
Show newest version
package com.qa.framework.library.database;

import com.qa.framework.config.ProjectEnvironment;
import com.qa.framework.library.base.XMLHelper;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * The type Xml to bean.
 */
public class XmlToBean {

    /**
     * Read list.
     *
     * @return the list
     */
    public static List read() {
        return read(ProjectEnvironment.dbConfigFile());
    }

    /**
     * Read list.
     *
     * @param path the path
     * @return the list
     */
    public static List read(String path) {

        List pools = new ArrayList();
        XMLHelper XmlUtil = new XMLHelper();
        XmlUtil.readXMLFile(path);
        List list = XmlUtil.findElementsByXPath("pools/pool");
        Element pool = null;
        Iterator allPool = list.iterator();
        while (allPool.hasNext()) {
            pool = (Element) allPool.next();
            BaseConnBean bcBean = new BaseConnBean();
            bcBean.setName(XmlUtil.getChildText(pool, "name").trim());
            bcBean.setUsername(XmlUtil.getChildText(pool, "username").trim());
            bcBean.setPassword(XmlUtil.getChildText(pool, "password").trim());
            bcBean.setJdbcurl(XmlUtil.getChildText(pool, "jdbcurl").trim());
            try {
                bcBean.setMax(Integer.parseInt(XmlUtil
                        .getChildText(pool, "max").trim()));
            } catch (NumberFormatException e) {
                bcBean.setMax(0);
            }
            try {
                bcBean.setWait(Long.parseLong(XmlUtil
                        .getChildText(pool, "wait").trim()));
            } catch (NumberFormatException e) {
                bcBean.setWait(-1L);
            }
            bcBean.setDriver(XmlUtil.getChildText(pool, "driver").trim());
            pools.add(bcBean);
        }
        return pools;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy