一个自写的XML读写/存取属性的Java工具类库
2008-02-23 09:25:25来源:互联网 阅读 ()
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Comment</comment>
<entry key="windowLocation">400,400</entry>
<entry key="windowSize">456,300</entry>
</properties>
* @(#)XmlElement.java
* Created on 2005-8-12
*/
package com.allenstudio.ir.util;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;
import java.util.Vector;
* The XmlElement is a generic containment class for elements within an XML
* file.
* <p>
*
* It extends Observable which should be used for gui elements which are
* interested in configuration changes.
* <p>
*
* Show interested in:
*
* <pre>
* xmlElement.addObserver(yourObserver);
* </pre>
*
* <p>
* When making bigger changes on XmlElement and probably its subnodes and/or a
* greater number of attributes at once, you should just change XmlElement
* directly and manually notify the Observers by calling:
* <p>
*
* <pre>
* xmlElement.setChanged();
* xmlElement.notifyObservers();
* </pre>
*
* <p>
* There a good introduction for the Observable/Observer pattern in
* Model/View/Controller based applications at www.javaworld.com: -
* {@link http://www.javaworld.com/javaworld/jw-10-1996/jw-10-howto.html}
*
* @author fdietz
*/
public class XmlElement extends Observable implements Cloneable {
String name;
*
*
* Constructor
*
*/
public XmlElement() {
subElements = new Vector<XmlElement>();
this.attributes = new Hashtable<String, String>(10);
}
* **
*
* Constructor
*
* @param String
* Name
*
*/
public XmlElement(String name) {
this.name = name;
this.attributes = new Hashtable<String, String>(10);
subElements = new Vector<XmlElement>();
data = "";
}
* **
*
* Constructor
*
* @param String
* Name
* @param Hashtable
* Attributes
*
*/
public XmlElement(String name, Hashtable<String, String> attributes) {
this.name = name;
this.attributes = attributes;
subElements = new Vector<XmlElement>();
}
* **
*
* Constructor
*
* @param Name
* String
* @param Data
* String
*
*/
public XmlElement(String name, String data) {
this.name = name;
this.data = data;
subElements = new Vector<XmlElement>();
this.attributes = new Hashtable<String, String>(10);
}
* Add attribute to this xml element.
*
* @param name
* name of key
* @param value
* new attribute value
* @return old attribute value
*
*/
public Object addAttribute(String name, String value) {
if ((value != null) && (name != null)) {
Object returnValue = attributes.put(name, value);
}
}
* **
*
* @return String
* @param String
* Name
*
*/
public String getAttribute(String name) {
return ((String) attributes.get(name));
}
if (getAttribute(name) == null) {
addAttribute(name, defaultValue);
}
}
* **
*
* @return String
* @param String
* Name
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:让Java程序带着JRE一起上路
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash