PropertySet教程 2.Memory、map、XML方式
inkfish原创,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish
)。
PropertySet(来源:http://blog.csdn.net/inkfish)
是由opensymphony组织开发的的一个开源项目,但是那个项目文档少,长时间没有更新,官方文档错误奇多,所以现在在项目中使用并不广泛。但这并不妨碍PropertySet成为一个优秀的key-value持久化模块,当前,PropertySet可以说已经够用。这里我整理书写了PropertySet的文档。(来源:http://blog.csdn.net/inkfish)
PropertySet最容易使用和上手的是memory方式,最常用的是xml、JDBC,另外Hibernate、EJB是较常用的方式。这里选择介绍memory、map、XML方式。(来源:http://blog.csdn.net/inkfish)
1.Demo
PropertySetDemo.java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.module.propertyset.PropertySetManager;
import com.opensymphony.module.propertyset.xml.XMLPropertySet;
public class PropertySetDemo {
public static void main(String[] args) throws Exception {
PropertySetDemo demo = new PropertySetDemo();
demo.mapPsDemo();
demo.memoryPsDemo();
demo.xmlPsDemo();
}
public void memoryPsDemo() {
System.out.println(StringUtils.center("Memory PropertySet Demo", 80, '*'));
//memory是配置文件中定义的:<propertyset name="memory" class="com.opensymphony.module.propertyset.memory.MemoryPropertySet"/>
PropertySet ps = PropertySetManager.getInstance("memory", null);
ps.setBoolean("BooleanPS", true);
ps.setString("name", "Tom");
System.out.println(ps.getBoolean("BooleanPS"));
System.out.println(ps.getString("name"));
System.out.println(StringUtils.repeat("*", 80));
}
public void mapPsDemo() {
System.out.println(StringUtils.center("Map PropertySet Demo", 80, '*'));
@Sup
相关文档:
XML Schema import 元素
定义和用法
import 元素用于向一个文档添加带有不同目标命名空间的多个 schema。
元素信息
出现次数
无限制
父元素
schema
内容
annotation
语法
<import
id=ID
namespace=anyURI
schemaLocation=anyURI
any attributes
>
(annotation?)
< ......
XML Schema union 元素
定义和用法
union 元素定义多个 simpleType 定义的集合。
元素信息
出现次数
一次
父元素
simpleType
内容
annotation、simpleType
语法
<union
id=ID
memberTypes="list of QNames"
any attributes
>
(annotation?,(simpleType ......
范例如下:
var xml:XML=
<body>
text1
<bar>barText1</bar>
& ......
/// <summary>
/// 支持XML序列化的泛型 Dictionary
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
[XmlRoot("SerializableDictionary")]
public class SerializableDictionary<TKey, TValue& ......
var createXML = function (str) {
if (typeof DOMParser !== "undefined") {
return (new DOMParser()).parsefromString(str, "application/xml");
}else if (typeof ActiveXObject != "undefined") {
if (typeof arguments.callee.activeXString !== "string" ......