⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configparser.java

📁 Java Database connection pool
💻 JAVA
字号:
/* *  PoolMan Java Object Pooling and Caching Library *  Copyright (C) 1999-2001 The Code Studio * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library 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 *  Lesser General Public License for more details. * *  The full license is located at the root of this distribution *  in the LICENSE file. */package com.codestudio.management;import com.codestudio.PoolManConstants;import org.xml.sax.AttributeList;import org.xml.sax.HandlerBase;import java.util.ArrayList;import java.util.Properties;/** * SAXParser used by Configurator to parse the * poolman.xml file. It returns Collections of * generic pool properties, JDBC pool properties, * and admin-agent properties. */public class ConfigParser extends HandlerBase {    private ArrayList dbProps;    private ArrayList genericProps;    private Properties adminProps;    private boolean jmxManagement = PoolManConstants.DEFAULT_USE_JMX;    private String currentSet;    private String currentName;    private StringBuffer currentValue = new StringBuffer();    public ConfigParser() {        this.dbProps = new ArrayList();        this.genericProps = new ArrayList();    }    public ArrayList getDataSourceProperties() {        return this.dbProps;    }    public ArrayList getGenericProperties() {        return this.genericProps;    }    public Properties getAdminProps() {        return this.adminProps;    }    public boolean isManagementJMX() {        return this.jmxManagement;    }    public void startElement(String name, AttributeList attributes) {        currentValue.delete(0, currentValue.length());        this.currentName = name;        if (name.toLowerCase().equals("datasource")) {            this.currentSet = "datasource";            dbProps.add(new Properties());        }        else if (name.toLowerCase().equals("objectpool")) {            this.currentSet = "generic";            genericProps.add(new Properties());        }        else if (name.toLowerCase().equals("admin-agent")) {            this.currentSet = "admin-agent";            this.adminProps = new Properties();        }        else if (name.toLowerCase().equals("management-mode")) {            this.currentSet = "management-mode";        }        else if (name.equals("poolman") || name.equals("MLET")) {            this.currentSet = "ignorable";        }    }    public void characters(char[] ch, int start, int length) {        currentValue.append(ch, start, length);    }    public void endElement(String name) {        if (this.currentSet.equals("datasource")) {            Properties p = (Properties) dbProps.get(dbProps.size() - 1);            p.put(name.toLowerCase(), currentValue.toString().trim());        }        else if (this.currentSet.equals("generic")) {            Properties p = (Properties) genericProps.get(genericProps.size() - 1);            p.put(name.toLowerCase(), currentValue.toString().trim());        }        else if (this.currentSet.equals("admin-agent")) {            adminProps.setProperty(name.toLowerCase(), currentValue.toString().trim());        }        else if (this.currentSet.equals("management-mode")) {            if (currentValue.toString().toLowerCase().trim().equals("jmx"))                this.jmxManagement = true;        }    }    class ConfigElement {        String name;        String value;        String datatype;        ConfigElement parent;        ArrayList children;        ConfigElement(String name, String value, String datatype) {            this.name = name;            this.value = value;            this.datatype = datatype;            this.parent = null;            this.children = new ArrayList();        }        String getValue() {            return this.value;        }        void setValue(String value) {            this.value = value;        }        boolean hasChildren() {            if (this.children.size() > 0)                return true;            return false;        }        ConfigElement getParent() {            return this.parent;        }        ArrayList getChildren() {            return this.children;        }        void addChild(ConfigElement child) {            this.children.add(child);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -