appsettings.java

来自「一个免费wap站」· Java 代码 · 共 72 行

JAVA
72
字号
package com.eline.wap.common.util;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.HashMap;

/**
 * 
 * @author Lucifer
 *
 */

public class AppSettings {

	private static AppSettings _instance = null;
	private HashMap _properties = null;

	synchronized public static AppSettings getInstance()
	{
	    if (_instance == null)
	    	_instance = new AppSettings();
	
	    return _instance;
	}

	public AppSettings() {
		_properties = new HashMap();
	}

	/**
	 * 
	 * @param root
	 */
	public void loadValuesFromConfigurationXml(Element root) {

		Node configSectionNode = root.getElementsByTagName(AppKeys.CONFIG_SECTION).item(0);
		NodeList list = configSectionNode.getChildNodes();
		
		for (int i = 0; i < list.getLength(); i++) {
			Node node = list.item(i);
			if (node != null) {
                // get url attributes
                // need to be a element to get attributes
				if (node instanceof Element) {
					Element element = (Element) node;
					String key = element.getNodeName();
					
					// Prosses for classInstance.
					if (key.equalsIgnoreCase(AppKeys.CLASS_INSTANCE)) {
						// TODO: 添加代码处理classInstance
					} else {
						try {
							this.setProperty(key, element.getFirstChild().getNodeValue());
						} catch (Exception e) {
							System.err.println("AppSettings.loadValuesFromConfigurationXml() : parse element value error...ignored!");
						}
					}
				}
			}
		}
	}

	public synchronized String getProperty(String key) {
		return (String)_properties.get(key);
	}
	
	public synchronized void setProperty(String key, String value) {
		_properties.put(key, value);
	}
}

⌨️ 快捷键说明

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