/**
* Process the beginning of this element.
*
* @param attributes The attribute list of this element
*/
public void begin(Attributes attributes) throws Exception {
// 识别类名
// Identify the name of the class to instantiate
String realClassName = className;
if (attributeName != null) {
String value = attributes.getValue(attributeName);
if (value != null) {
realClassName = value;
}
}
if (digester.log.isDebugEnabled()) {
digester.log.debug("[ObjectCreateRule]{" + digester.match +
"}New " + realClassName);
}
// 实现类并将实例放到堆栈中
// Instantiate the new object and push it on the context stack
Class clazz = digester.getClassLoader().loadClass(realClassName);
Object instance = clazz.newInstance();
digester.push(instance);
}
end代码
/**
* Process the end of this element.
*/
public void end() throws Exception {
Object top = digester.pop();
if (digester.log.isDebugEnabled()) {
digester.log.debug("[ObjectCreateRule]{" + digester.match +
"} Pop " + top.getClass().getName());
}
}
参考:
1 The Hidden Gems of Jakarta Commons
http://www.onjava.com/pub/a/onjava/2004/12/22/jakarta-gems-1.html?page=2
2 Parsing, indexing, and searching XML with Digester and Lucene
http://www.ibm.com/developerworks/java/library/j-lucene/
3 Learning and Using Jakarta Digester
http://www.onjava.com/pub/a/onjava/2002/10/23/digester.html?page=1