Example usage for org.apache.commons.digester3 NodeCreateRule NodeCreateRule

List of usage examples for org.apache.commons.digester3 NodeCreateRule NodeCreateRule

Introduction

In this page you can find the example usage for org.apache.commons.digester3 NodeCreateRule NodeCreateRule.

Prototype

public NodeCreateRule() throws ParserConfigurationException 

Source Link

Document

Default constructor.

Usage

From source file:eu.scape_project.planning.xml.PlanParser.java

/**
 * Create a rule for parsing an element for the given location
 * <code>pattern</code>, write it the XML as binary data, and use the
 * <code>dataSetterMethod</code> to set the data in the parent.
 * // w w  w  .  j a va 2s.  c o m
 * @param digester
 *            the digester
 * @param pattern
 *            the location pattern
 * @param dataMethod
 *            a method name of the parent object that will be called to set
 *            the binary data or null to use XMLDataWrapper's default
 * @throws ParserConfigurationException
 *             if the digester could not be configured
 */
private static void addCreateXMLData(final Digester digester, final String pattern, String dataMethod,
        String changeLogMethod) throws ParserConfigurationException {

    // 1. Create a XMLDataWrapper
    digester.addObjectCreate(pattern, XMLDataWrapper.class);

    if (changeLogMethod != null) {
        // 6. Finally call setChangeLog on the XMLDataWrapper on top with
        // the object next to top as argument.
        digester.addSetTop(pattern, "setChangeLog");
        // 5. Set change log setter method on XMLDataWrapper
        digester.addCallMethod(pattern, "setChangeLogMethodName", 1);
        digester.addObjectParam(pattern, 0, changeLogMethod);
    }

    // 4. Finally call setData on the XMLDataWrapper on top with the
    // object next to top as argument.
    digester.addSetTop(pattern, "setData");
    // 3. Set data setter method on XMLDataWrapper
    if (dataMethod != null) {
        digester.addCallMethod(pattern, "setMethodName", 1);
        digester.addObjectParam(pattern, 0, dataMethod);
    }
    // 2. Create element from XML and set the element in the XMLDataWrapper
    NodeCreateRule nodeCreateRule = new NodeCreateRule();
    digester.addRule(pattern, nodeCreateRule);
    digester.addSetNext(pattern, "setEncoded");

}