Apache Commons组件聚合
Apache Commons组件集合5. validateObject is invoked in an implementation-specific fashion to determi
Apache Commons组件集合
5. validateObject is invoked in an implementation-specific fashion to determine if an instance is still valid to be returned by the pool. It will only be invoked on an "activated" instance.
二十、Commons Digester?
它能方便地将XML文档所定义的元素转化为JAVA对象,其实它的用法有点象栈(当然内在的原理就是那个古老的东西,只是提供了更高一层的封装)。?
//生成一个digester。主要需要引进commons-logging.jar、commons-collections.jar、commons-?beanutils.jar????Digester?digester?=?new?Digester();? ????//设置对XML文档资料是否进行DTD验证????digester.setValidating(?false?);? ????//当遇见?catalog?元素的时候,产生一个Catalog对象????digester.addObjectCreate(?"catalog",?Catalog.class?);? ????//当遇见?catalog?元素下面的book的时候,产生一个Book对象????digester.addObjectCreate(?"catalog/book",?Book.class?);? ??//?当遇见?catalog?元素下面的book的author时候,调用author属性的Set方法????digester.addBeanPropertySetter(?"catalog/book/author",?"author"?);? ??digester.addBeanPropertySetter(?"catalog/book/title",?"title"?);? ??//当再一次遇见?catalog?元素下面的book的时候,调用catalog类的addBook()方法????digester.addSetNext(?"catalog/book",?"addBook"?);? ????digester.addObjectCreate(?"catalog/magazine",?Magazine.class?);? ??digester.addBeanPropertySetter(?"catalog/magazine/name",?"name"?);? ????digester.addObjectCreate(?"catalog/magazine/article",?Article.class?);? ??//addSetProperties()是将对应元素的属性赋值。????digester.addSetProperties(?"catalog/magazine/article",?"page",?"page"?);? ??digester.addBeanPropertySetter(?"catalog/magazine/article/headline"?);? ??digester.addSetNext(?"catalog/magazine/article",?"addArticle"?);? ????digester.addSetNext(?"catalog/magazine",?"addMagazine"?);? ??\Digester\\catalog.xml"为XML文档????File?input?=?new?File(?"F:\\Digester\\catalog.xml"?);? ??Catalog?c?=?(Catalog)digester.parse(?input?);? ??System.out.println(?c.toString()?);