Example usage for org.apache.commons.digester3 Digester addCallParam

List of usage examples for org.apache.commons.digester3 Digester addCallParam

Introduction

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

Prototype

public void addCallParam(String pattern, int paramIndex, int stackIndex) 

Source Link

Document

Add a "call parameter" rule that sets a parameter from the stack.

Usage

From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParser.java

public static GoPluginDescriptor parseXML(InputStream pluginXML, String pluginJarFileLocation,
        File pluginBundleLocation, boolean isBundledPlugin) throws IOException, SAXException {
    Digester digester = initDigester();
    GoPluginDescriptorParser parserForThisXML = new GoPluginDescriptorParser(pluginJarFileLocation,
            pluginBundleLocation, isBundledPlugin);
    digester.push(parserForThisXML);//from  www .  j a  v  a 2  s.  c o m

    digester.addCallMethod("go-plugin", "createPlugin", 2);
    digester.addCallParam("go-plugin", 0, "id");
    digester.addCallParam("go-plugin", 1, "version");

    digester.addCallMethod("go-plugin/about", "createAbout", 4);
    digester.addCallParam("go-plugin/about/name", 0);
    digester.addCallParam("go-plugin/about/version", 1);
    digester.addCallParam("go-plugin/about/target-go-version", 2);
    digester.addCallParam("go-plugin/about/description", 3);

    digester.addCallMethod("go-plugin/about/vendor", "createVendor", 2);
    digester.addCallParam("go-plugin/about/vendor/name", 0);
    digester.addCallParam("go-plugin/about/vendor/url", 1);

    digester.addCallMethod("go-plugin/about/target-os/value", "addTargetOS", 1);
    digester.addCallParam("go-plugin/about/target-os/value", 0);

    digester.parse(pluginXML);

    return parserForThisXML.descriptor;
}

From source file:net.sf.mcf2pdf.mcfglobals.McfProductCatalogue.java

private static McfProductCatalogue readV6(InputStream in) throws IOException, SAXException {
    Digester digester = new Digester();
    digester.addObjectCreate("description", McfProductCatalogueImpl.class);
    digester.addObjectCreate("description/product", McfAlbumTypeImpl.class);
    DigesterUtil.addSetProperties(digester, "description/product", getAlbumSpecialAttributes());
    DigesterUtil.addSetProperties(digester, "description/product/usablesize", getUsableSizeAttributes());
    digester.addCallMethod("description/product/spines/spine", "addSpine", 2,
            new String[] { Integer.class.getName(), Integer.class.getName() });
    digester.addCallParam("description/product/spines/spine", 0, "pages");
    digester.addCallParam("description/product/spines/spine", 1, "width");
    digester.addSetNext("description/product", "addAlbumType");

    return digester.parse(in);
}

From source file:net.sf.mcf2pdf.mcfglobals.McfProductCatalogue.java

public static McfProductCatalogue read(InputStream in, CatalogueVersion version)
        throws IOException, SAXException {
    if (version == CatalogueVersion.V6) {
        return readV6(in);
    }/*www .  j  av  a 2  s  . c  o m*/

    // PRE_V6
    Digester digester = new Digester();
    digester.addObjectCreate("fotobookdefinitions", McfProductCatalogueImpl.class);
    digester.addObjectCreate("fotobookdefinitions/album", McfAlbumTypeImpl.class);
    DigesterUtil.addSetProperties(digester, "fotobookdefinitions/album", getAlbumSpecialAttributes());
    DigesterUtil.addSetProperties(digester, "fotobookdefinitions/album/usablesize", getUsableSizeAttributes());
    digester.addCallMethod("fotobookdefinitions/album/spines/spine", "addSpine", 2,
            new String[] { Integer.class.getName(), Integer.class.getName() });
    digester.addCallParam("fotobookdefinitions/album/spines/spine", 0, "pages");
    digester.addCallParam("fotobookdefinitions/album/spines/spine", 1, "width");
    digester.addSetNext("fotobookdefinitions/album", "addAlbumType");

    return digester.parse(in);
}

From source file:br.univali.celine.scorm.model.cam.ContentPackageReader20043rd.java

protected void addConditionRule(Digester d, String tagCondition, String metodoAdd) {
    d.addObjectCreate(tagCondition, SequencingRule.class);
    d.addSetNext(tagCondition, metodoAdd);

    // <ruleConditions>
    d.addSetProperties(tagCondition + "/ruleConditions");

    d.addObjectCreate(tagCondition + "/ruleConditions/ruleCondition", RuleCondition.class);
    d.addSetNext(tagCondition + "/ruleConditions/ruleCondition", "addRuleCondition");
    d.addSetProperties(tagCondition + "/ruleConditions/ruleCondition");

    // <ruleAction>
    d.addCallMethod(tagCondition + "/ruleAction", "setRuleAction", 1);
    d.addCallParam(tagCondition + "/ruleAction", 0, "action");
}

From source file:br.univali.celine.scorm.model.cam.ContentPackageReader20043rd.java

protected void addRollupRules(Digester d, String tagParent) {
    d.addObjectCreate(tagParent + "/sequencing/rollupRules", RollupRules.class);
    d.addSetNext(tagParent + "/sequencing/rollupRules", "setRollupRules");
    d.addSetProperties(tagParent + "/sequencing/rollupRules");

    // <rollupRule>
    d.addObjectCreate(tagParent + "/sequencing/rollupRules/rollupRule", RollupRule.class);
    d.addSetNext(tagParent + "/sequencing/rollupRules/rollupRule", "addRollupRule");
    d.addSetProperties(tagParent + "/sequencing/rollupRules/rollupRule");

    // <rollupCondition>
    d.addObjectCreate(tagParent + "/sequencing/rollupRules/rollupRule/rollupConditions/rollupCondition",
            RollupCondition.class);
    d.addSetProperties(tagParent + "/sequencing/rollupRules/rollupRule/rollupConditions/rollupCondition");
    d.addSetNext(tagParent + "/sequencing/rollupRules/rollupRule/rollupConditions/rollupCondition",
            "addRollupCondition");

    // <rollupAction>
    d.addCallMethod(tagParent + "/sequencing/rollupRules/rollupRule/rollupAction", "setRollupAction", 1);
    d.addCallParam(tagParent + "/sequencing/rollupRules/rollupRule/rollupAction", 0, "action");

    /*/*from ww w  .j a va  2  s .c o m*/
    d.addCallMethod(tagParent+"/sequencing/rollupRules/rollupRule/rollupAction", "set");
    d.addSetNext(tagParent+"/sequencing/rollupRules/rollupRule", "addRollupRule");
    d.addSetProperties(tagParent+"/sequencing/rollupRules/rollupRule");
    */

}

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

/**
 * This method adds rules for name, properties, scales, modes and mappings
 * only! Rules for importing measured values of alternatives are defined
 * seperately in importProjects()! (Refactored to its own method by Kevin)
 * //from   w  w w . ja v  a  2s.c o m
 * @param digester
 *            the digester
 */
private static void addTreeParsingRulesToDigester(final Digester digester) {
    digester.addObjectCreate("*/plan/tree", ObjectiveTree.class);
    digester.addSetProperties("*/plan/tree");
    digester.addSetNext("*/plan/tree", "setTree");

    digester.addObjectCreate("*/node/node", Node.class);
    digester.addSetProperties("*/node/node");
    digester.addSetNext("*/node/node", "addChild");

    digester.addCallMethod("*/node/description", "setDescription", 0);

    digester.addObjectCreate("*/plan/tree/node", Node.class);
    digester.addSetProperties("*/plan/tree/node");
    digester.addSetNext("*/plan/tree/node", "setRoot");

    digester.addObjectCreate("*/leaf", Leaf.class);
    digester.addSetProperties("*/leaf");
    digester.addSetNext("*/leaf", "addChild");
    digester.addFactoryCreate("*/leaf/aggregationMode", SampleAggregationModeFactory.class);
    digester.addSetNext("*/leaf/aggregationMode", "setAggregationMode");

    digester.addCallMethod("*/leaf/description", "setDescription", 0);

    PlanParser.addMeasureRules(digester, "*/measure");

    /*
     * for each scale-type a set of rules
     */
    PlanParser.addCreateScale(digester, BooleanScale.class);
    PlanParser.addCreateScale(digester, FloatRangeScale.class);
    PlanParser.addCreateScale(digester, FloatScale.class);
    PlanParser.addCreateScale(digester, IntegerScale.class);
    PlanParser.addCreateScale(digester, IntRangeScale.class);
    PlanParser.addCreateScale(digester, OrdinalScale.class);
    PlanParser.addCreateScale(digester, PositiveFloatScale.class);
    PlanParser.addCreateScale(digester, PositiveIntegerScale.class);
    PlanParser.addCreateScale(digester, YanScale.class);
    PlanParser.addCreateScale(digester, FreeStringScale.class);

    /*
     * for each transformer type a set of rules
     */
    digester.addObjectCreate("*/leaf/numericTransformer", NumericTransformer.class);
    digester.addSetProperties("*/leaf/numericTransformer");
    digester.addFactoryCreate("*/leaf/numericTransformer/mode", TransformationModeFactory.class);
    digester.addSetNext("*/leaf/numericTransformer/mode", "setMode");
    digester.addBeanPropertySetter("*/leaf/numericTransformer/thresholds/threshold1", "threshold1");
    digester.addBeanPropertySetter("*/leaf/numericTransformer/thresholds/threshold2", "threshold2");
    digester.addBeanPropertySetter("*/leaf/numericTransformer/thresholds/threshold3", "threshold3");
    digester.addBeanPropertySetter("*/leaf/numericTransformer/thresholds/threshold4", "threshold4");
    digester.addBeanPropertySetter("*/leaf/numericTransformer/thresholds/threshold5", "threshold5");
    digester.addSetNext("*/leaf/numericTransformer", "setTransformer");

    // digester.addObjectCreate("*/numericTransformer/thresholds",
    // LinkedHashMap.class);
    // digester.addSetNext("*/numericTransformer/thresholds",
    // "setThresholds");
    // digester.addFactoryCreate("*/thresholds/threshold",
    // NumericTransformerThresholdFactory.class);

    digester.addObjectCreate("*/leaf/ordinalTransformer", OrdinalTransformer.class);
    digester.addSetProperties("*/leaf/ordinalTransformer");
    digester.addSetNext("*/leaf/ordinalTransformer", "setTransformer");

    digester.addObjectCreate("*/ordinalTransformer/mappings", LinkedHashMap.class);
    digester.addSetNext("*/ordinalTransformer/mappings", "setMapping");
    digester.addFactoryCreate("*/mappings/mapping", OrdinalTransformerMappingFactory.class);

    digester.addRule("*/mappings/mapping", new CallMethodRule(1, "put", 2)); // method
                                                                             // with
                                                                             // two
                                                                             // params
    digester.addCallParam("*/mappings/mapping", 0, "ordinal"); // use
                                                               // attribute
                                                               // "ordinal"
                                                               // as first
                                                               // argument
    digester.addCallParam("*/mappings/mapping", 1, true); // and the object
                                                          // on the stack as
                                                          // second
}

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

/**
 * Adds rules to the digester to parse the a plan XML.
 * /*from   w  ww .  j a v a2  s  .c o  m*/
 * @param digester
 *            the digester
 * @throws ParserConfigurationException
 *             if an error occurred
 */
private static void addRules(Digester digester) throws ParserConfigurationException {

    ConvertUtils.register(new EnumConverter<EvaluationScope>(EvaluationScope.class), EvaluationScope.class);
    // start with a new file
    digester.addObjectCreate("*/plan", Plan.class);
    digester.addSetProperties("*/plan");
    digester.addSetRoot("*/plan", "setProject");

    digester.addFactoryCreate("*/changelog", ChangeLogFactory.class);
    digester.addSetNext("*/changelog", "setChangeLog");

    digester.addObjectCreate("*/plan/properties", PlanProperties.class);
    digester.addSetProperties("*/plan/properties");
    digester.addSetNext("*/plan/properties", "setPlanProperties");
    digester.addCallMethod("*/plan/properties/description", "setDescription", 0);
    digester.addCallMethod("*/plan/properties/owner", "setOwner", 0);

    digester.addFactoryCreate("*/plan/properties/state", PlanStateFactory.class);
    digester.addSetNext("*/plan/properties/state", "setState");

    PlanParser.addCreateUpload(digester, "*/plan/properties/report", "setReportUpload", DigitalObject.class);

    digester.addObjectCreate("*/plan/basis", ProjectBasis.class);
    digester.addSetProperties("*/plan/basis");
    digester.addSetNext("*/plan/basis", "setProjectBasis");
    digester.addCallMethod("*/plan/basis/applyingPolicies", "setApplyingPolicies", 0);
    digester.addCallMethod("*/plan/basis/designatedCommunity", "setDesignatedCommunity", 0);
    digester.addCallMethod("*/plan/basis/mandate", "setMandate", 0);

    digester.addCallMethod("*/plan/basis/documentTypes", "setDocumentTypes", 0);
    digester.addCallMethod("*/plan/basis/identificationCode", "setIdentificationCode", 0);
    digester.addCallMethod("*/plan/basis/organisationalProcedures", "setOrganisationalProcedures", 0);
    digester.addCallMethod("*/plan/basis/planningPurpose", "setPlanningPurpose", 0);
    digester.addCallMethod("*/plan/basis/planRelations", "setPlanRelations", 0);
    digester.addCallMethod("*/plan/basis/preservationRights", "setPreservationRights", 0);
    digester.addCallMethod("*/plan/basis/referenceToAgreements", "setReferenceToAgreements", 0);

    // define common rule for triggers, for all */triggers/...!
    // also used for PlanDefinition
    digester.addObjectCreate("*/triggers", TriggerDefinition.class);
    digester.addSetNext("*/triggers", "setTriggers");
    // every time a */triggers/trigger is encountered:
    digester.addFactoryCreate("*/triggers/trigger", TriggerFactory.class);
    digester.addSetNext("*/triggers/trigger", "setTrigger");

    //
    // Policy Tree
    //
    digester.addObjectCreate("*/plan/basis/policyTree", PolicyTree.class);
    digester.addSetProperties("*/plan/basis/policyTree");
    digester.addSetNext("*/plan/basis/policyTree", "setPolicyTree");

    digester.addObjectCreate("*/plan/basis/policyTree/policyNode", PolicyNode.class);
    digester.addSetProperties("*/plan/basis/policyTree/policyNode");
    digester.addSetNext("*/plan/basis/policyTree/policyNode", "setRoot");

    digester.addObjectCreate("*/policyNode/policyNode", PolicyNode.class);
    digester.addSetProperties("*/policyNode/policyNode");
    digester.addSetNext("*/policyNode/policyNode", "addChild");

    digester.addObjectCreate("*/policyNode/policy", Policy.class);
    digester.addSetProperties("*/policyNode/policy");
    digester.addSetNext("*/policyNode/policy", "addChild");

    //
    // Sample Records
    //

    digester.addObjectCreate("*/plan/sampleRecords", SampleRecordsDefinition.class);
    digester.addSetProperties("*/plan/sampleRecords");
    digester.addSetNext("*/plan/sampleRecords", "setSampleRecordsDefinition");

    digester.addCallMethod("*/plan/sampleRecords/samplesDescription", "setSamplesDescription", 0);

    // - records
    digester.addObjectCreate("*/record", SampleObject.class);
    digester.addSetProperties("*/record");
    digester.addSetNext("*/record", "addRecord");

    digester.addCallMethod("*/record/description", "setDescription", 0);
    digester.addCallMethod("*/record/originalTechnicalEnvironment", "setOriginalTechnicalEnvironment", 0);

    digester.addObjectCreate("*/record/data", BinaryDataWrapper.class);
    digester.addSetTop("*/record/data", "setData");
    digester.addCallMethod("*/record/data", "setFromBase64Encoded", 0);

    // set up an general rule for all jhove strings!
    digester.addObjectCreate("*/jhoveXML", BinaryDataWrapper.class);
    digester.addSetTop("*/jhoveXML", "setString");
    digester.addCallMethod("*/jhoveXML", "setFromBase64Encoded", 0);
    digester.addCallMethod("*/jhoveXML", "setMethodName", 1, new String[] { "java.lang.String" });
    digester.addObjectParam("*/jhoveXML", 0, "setJhoveXMLString");

    // set up general rule for all fitsXMLs
    digester.addObjectCreate("*/fitsXML", BinaryDataWrapper.class);
    digester.addSetTop("*/fitsXML", "setString");
    digester.addCallMethod("*/fitsXML", "setFromBase64Encoded", 0);
    digester.addCallMethod("*/fitsXML", "setMethodName", 1, new String[] { "java.lang.String" });
    digester.addObjectParam("*/fitsXML", 0, "setFitsXMLString");

    digester.addObjectCreate("*/formatInfo", FormatInfo.class);
    digester.addSetProperties("*/formatInfo");
    digester.addSetNext("*/formatInfo", "setFormatInfo");

    PlanParser.addCreateUpload(digester, "*/record/xcdlDescription", "setXcdlDescription",
            XcdlDescription.class);

    // - collection profile
    digester.addObjectCreate("*/plan/sampleRecords/collectionProfile", CollectionProfile.class);
    digester.addSetProperties("*/plan/sampleRecords/collectionProfile");
    digester.addSetNext("*/plan/sampleRecords/collectionProfile", "setCollectionProfile");

    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/collectionID", "setCollectionID", 0);
    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/description", "setDescription", 0);
    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/numberOfObjects", "setNumberOfObjects", 0);
    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/typeOfObjects", "setTypeOfObjects", 0);
    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/expectedGrowthRate", "setExpectedGrowthRate",
            0);
    digester.addCallMethod("*/plan/sampleRecords/collectionProfile/retentionPeriod", "setRetentionPeriod", 0);
    PlanParser.addCreateUpload(digester, "*/plan/sampleRecords/collectionProfile/profile", "setProfile",
            DigitalObject.class);

    // requirements definition
    digester.addObjectCreate("*/plan/requirementsDefinition", RequirementsDefinition.class);
    digester.addSetProperties("*/plan/requirementsDefinition");
    digester.addSetNext("*/plan/requirementsDefinition", "setRequirementsDefinition");

    digester.addCallMethod("*/plan/requirementsDefinition/description", "setDescription", 0);

    // - uploads
    digester.addObjectCreate("*/plan/requirementsDefinition/uploads", ArrayList.class);
    digester.addSetNext("*/plan/requirementsDefinition/uploads", "setUploads");
    PlanParser.addCreateUpload(digester, "*/plan/requirementsDefinition/uploads/upload", "add",
            DigitalObject.class);

    // alternatives
    digester.addObjectCreate("*/plan/alternatives", AlternativesDefinition.class);
    digester.addSetProperties("*/plan/alternatives");
    digester.addCallMethod("*/plan/alternatives/description", "setDescription", 0);
    digester.addSetNext("*/plan/alternatives", "setAlternativesDefinition");

    digester.addObjectCreate("*/plan/alternatives/alternative", Alternative.class);
    digester.addSetProperties("*/plan/alternatives/alternative");
    digester.addSetNext("*/plan/alternatives/alternative", "addAlternative");
    // - action
    digester.addObjectCreate("*/plan/alternatives/alternative/action", PreservationActionDefinition.class);
    digester.addSetProperties("*/plan/alternatives/alternative/action");
    digester.addBeanPropertySetter("*/plan/alternatives/alternative/action/descriptor");
    digester.addBeanPropertySetter("*/plan/alternatives/alternative/action/parameterInfo");

    digester.addSetNext("*/plan/alternatives/alternative/action", "setAction");

    digester.addCallMethod("*/plan/alternatives/alternative/description", "setDescription", 0);

    // - - params
    digester.addObjectCreate("*/plan/alternatives/alternative/action/params", LinkedList.class);
    digester.addSetNext("*/plan/alternatives/alternative/action/params", "setParams");

    digester.addObjectCreate("*/plan/alternatives/alternative/action/params/param", Parameter.class);
    digester.addSetProperties("*/plan/alternatives/alternative/action/params/param");
    digester.addSetNext("*/plan/alternatives/alternative/action/params/param", "add");
    // - resource description
    digester.addObjectCreate("*/resourceDescription", ResourceDescription.class);
    digester.addSetProperties("*/resourceDescription");
    digester.addSetNext("*/resourceDescription", "setResourceDescription");

    digester.addCallMethod("*/resourceDescription/configSettings", "setConfigSettings", 0);
    digester.addCallMethod("*/resourceDescription/necessaryResources", "setNecessaryResources", 0);
    digester.addCallMethod("*/resourceDescription/reasonForConsidering", "setReasonForConsidering", 0);

    // - experiment
    digester.addObjectCreate("*/experiment", ExperimentWrapper.class);
    digester.addSetProperties("*/experiment");
    digester.addSetNext("*/experiment", "setExperiment");
    digester.addCallMethod("*/experiment/description", "setDescription", 0);
    digester.addCallMethod("*/experiment/settings", "setSettings", 0);
    PlanParser.addCreateUpload(digester, "*/experiment/workflow", "setWorkflow", DigitalObject.class);

    PlanParser.addCreateUpload(digester, "*/experiment/results/result", null, DigitalObject.class);
    PlanParser.addCreateUpload(digester, "*/result/xcdlDescription", "setXcdlDescription",
            XcdlDescription.class);

    // call function addUpload of ExperimentWrapper
    CallMethodRule r = new CallMethodRule(1, "addResult", 2); // method
                                                              // with
                                                              // two
                                                              // params
                                                              // every time */experiment/uploads/upload is encountered
    digester.addRule("*/experiment/results/result", r);
    // use attribute "key" as first param
    digester.addCallParam("*/experiment/results/result", 0, "key");
    // and the object on stack (DigitalObject) as the second
    digester.addCallParam("*/experiment/results/result", 1, true);

    // addCreateUpload(digester,
    // "*/experiment/xcdlDescriptions/xcdlDescription", null,
    // XcdlDescription.class);
    // // call function addXcdlDescription of ExperimentWrapper
    // r = new CallMethodRule(1, "addXcdlDescription", 2); //method with
    // two
    // params
    // // every time */experiment/xcdlDescriptions/xcdlDescription is
    // encountered
    // digester.addRule("*/experiment/xcdlDescriptions/xcdlDescription",
    // r);
    // // use attribute "key" as first param
    // digester.addCallParam("*/experiment/xcdlDescriptions/xcdlDescription",
    // 0 , "key");http://fue.onb.ac.at/abo/data
    // // and the object on stack (DigitalObject) as the second
    // digester.addCallParam("*/experiment/xcdlDescriptions/xcdlDescription",1,true);

    digester.addObjectCreate("*/experiment/detailedInfos/detailedInfo", DetailedExperimentInfo.class);
    digester.addSetProperties("*/experiment/detailedInfos/detailedInfo");
    digester.addBeanPropertySetter("*/experiment/detailedInfos/detailedInfo/programOutput");
    digester.addBeanPropertySetter("*/experiment/detailedInfos/detailedInfo/cpr");

    // call function "addDetailedInfo" of ExperimentWrapper
    r = new CallMethodRule(1, "addDetailedInfo", 2); // method with two
                                                     // params
                                                     // every time */experiment/detailedInfos/detailedInfo is encountered
    digester.addRule("*/experiment/detailedInfos/detailedInfo", r);
    // use attribute "key" as first param
    digester.addCallParam("*/experiment/detailedInfos/detailedInfo", 0, "key");
    // and the object on stack as second parameter
    digester.addCallParam("*/experiment/detailedInfos/detailedInfo", 1, true);

    // read contained measurements:
    digester.addObjectCreate("*/detailedInfo/measurements/measurement", Measurement.class);
    digester.addSetProperties("*/detailedInfo/measurements/measurement");
    digester.addSetNext("*/detailedInfo/measurements/measurement", "put");
    // values are defined with wild-cards, and therefore set
    // automatically

    /*
     * for each value type a set of rules because of FreeStringValue we need
     * to store the value as XML-element instead of an attribute naming them
     * "ResultValues" wasn't nice too
     */
    PlanParser.addCreateValue(digester, BooleanValue.class, "setValue");
    PlanParser.addCreateValue(digester, FloatRangeValue.class, "setValue");
    PlanParser.addCreateValue(digester, IntegerValue.class, "setValue");
    PlanParser.addCreateValue(digester, IntRangeValue.class, "setValue");
    PlanParser.addCreateValue(digester, OrdinalValue.class, "setValue");
    PlanParser.addCreateValue(digester, PositiveFloatValue.class, "setValue");
    PlanParser.addCreateValue(digester, PositiveIntegerValue.class, "setValue");
    PlanParser.addCreateValue(digester, YanValue.class, "setValue");
    PlanParser.addCreateValue(digester, FreeStringValue.class, "setValue");

    // go no go decision
    digester.addObjectCreate("*/plan/decision", Decision.class);
    digester.addSetProperties("*/plan/decision");
    digester.addSetNext("*/plan/decision", "setDecision");

    digester.addCallMethod("*/plan/decision/actionNeeded", "setActionNeeded", 0);
    digester.addCallMethod("*/plan/decision/reason", "setReason", 0);

    digester.addFactoryCreate("*/plan/decision/goDecision", GoDecisionFactory.class);
    digester.addSetNext("*/plan/decision/goDecision", "setDecision");

    // evaluation
    digester.addObjectCreate("*/plan/evaluation", Evaluation.class);
    digester.addSetProperties("*/plan/evaluation");
    digester.addSetNext("*/plan/evaluation", "setEvaluation");

    digester.addCallMethod("*/plan/evaluation/comment", "setComment", 0);

    // importance weighting
    digester.addObjectCreate("*/plan/importanceWeighting", ImportanceWeighting.class);
    digester.addSetProperties("*/plan/importanceWeighting");
    digester.addSetNext("*/plan/importanceWeighting", "setImportanceWeighting");

    digester.addCallMethod("*/plan/importanceWeighting/comment", "setComment", 0);

    // recommendation
    digester.addObjectCreate("*/plan/recommendation", RecommendationWrapper.class);
    digester.addSetProperties("*/plan/recommendation");
    digester.addSetNext("*/plan/recommendation", "setRecommendation");

    digester.addCallMethod("*/plan/recommendation/reasoning", "setReasoning", 0);
    digester.addCallMethod("*/plan/recommendation/effects", "setEffects", 0);

    // transformation
    digester.addObjectCreate("*/plan/transformation", Transformation.class);
    digester.addSetProperties("*/plan/transformation");
    digester.addSetNext("*/plan/transformation", "setTransformation");

    digester.addCallMethod("*/plan/transformation/comment", "setComment", 0);

    // Tree
    /*
     * Some rules for tree parsing are necessary for importing templates
     * too, that's why they are added by this static method.
     */
    PlanParser.addTreeParsingRulesToDigester(digester);

    digester.addObjectCreate("*/leaf/evaluation", HashMap.class);
    digester.addSetNext("*/leaf/evaluation", "setValueMap");
    /*
     * The valueMap has an entry for each (considered) alternative ... and
     * for each alternative there is a list of values, one per SampleObject.
     * Note: The digester uses a stack, therefore the rule to put the list
     * of values to the valueMap must be added after the rule for adding the
     * values to the list.
     */

    /*
     * 2. and for each alternative there is a list of values, one per
     * SampleObject
     */
    digester.addObjectCreate("*/leaf/evaluation/alternative", Values.class);
    digester.addCallMethod("*/leaf/evaluation/alternative/comment", "setComment", 0);

    /*
     * for each result-type a set of rules they are added to the valueMap by
     * the rules above
     */
    PlanParser.addCreateResultValue(digester, BooleanValue.class);
    PlanParser.addCreateResultValue(digester, FloatValue.class);
    PlanParser.addCreateResultValue(digester, FloatRangeValue.class);
    PlanParser.addCreateResultValue(digester, IntegerValue.class);
    PlanParser.addCreateResultValue(digester, IntRangeValue.class);
    PlanParser.addCreateResultValue(digester, OrdinalValue.class);
    PlanParser.addCreateResultValue(digester, PositiveFloatValue.class);
    PlanParser.addCreateResultValue(digester, PositiveIntegerValue.class);
    PlanParser.addCreateResultValue(digester, YanValue.class);
    PlanParser.addCreateResultValue(digester, FreeStringValue.class);

    /*
     * 1. The valueMap has an entry for each (considered) alternative ...
     */
    // call put of the ValueMap (HashMap)
    r = new CallMethodRule(1, "put", 2);
    digester.addRule("*/leaf/evaluation/alternative", r);
    digester.addCallParam("*/leaf/evaluation/alternative", 0, "key");
    digester.addCallParam("*/leaf/evaluation/alternative", 1, true);

    // digester.addObjectCreate("*/plan/executablePlan/planWorkflow",
    // ExecutablePlanContentWrapper.class);
    // digester.addSetProperties("*/plan/executablePlan/planWorkflow");
    // digester.addSetNext("*/plan/executablePlan/planWorkflow",
    // "setRecommendation");

    // Executable plan definition
    digester.addObjectCreate("*/plan/executablePlan", ExecutablePlanDefinition.class);
    digester.addSetProperties("*/plan/executablePlan");
    digester.addCallMethod("*/plan/executablePlan/objectPath", "setObjectPath", 0);
    digester.addCallMethod("*/plan/executablePlan/toolParameters", "setToolParameters", 0);
    digester.addCallMethod("*/plan/executablePlan/triggersConditions", "setTriggersConditions", 0);
    digester.addCallMethod("*/plan/executablePlan/validateQA", "setValidateQA", 0);
    PlanParser.addCreateUpload(digester, "*/plan/executablePlan/workflow", "setT2flowExecutablePlan",
            DigitalObject.class);

    digester.addSetNext("*/plan/executablePlan", "setExecutablePlanDefinition");

    // Preservation action plan
    digester.addObjectCreate("*/plan/preservationActionPlan", DigitalObject.class);
    digester.addSetNext("*/plan/preservationActionPlan", "setPreservationActionPlan");

    digester.addCallMethod("*/plan/preservationActionPlan", "setContentType", 1);
    digester.addObjectParam("*/plan/preservationActionPlan", 0, "application/xml");
    digester.addCallMethod("*/plan/preservationActionPlan", "setFullname", 1);
    digester.addObjectParam("*/plan/preservationActionPlan", 0, PreservationActionPlanGenerator.FULL_NAME);
    digester.addSetNext("*/plan/preservationActionPlan", "setPreservationActionPlan");

    PlanParser.addCreateXMLData(digester, "*/plan/preservationActionPlan", "setData", "setChangeLog");

    //
    // Import Planets executable plan if present
    //
    // object-create rules are called at the beginning element-tags, in
    // the
    // same order as defined
    // first create the wrapper
    // digester.addObjectCreate("*/plan/executablePlan/planWorkflow",
    // NodeContentWrapper.class);
    // // then an element for workflowConf
    // digester.addRule("*/plan/executablePlan/planWorkflow/workflowConf",
    // new NodeCreateRule());
    //
    // // CallMethod and SetNext rules are called at closing element-tags,
    // // (last
    // // in - first out!)
    //
    // CallMethodRule rr = new CallMethodRule(1, "setNodeContent", 2);
    // digester.addRule("*/plan/executablePlan/planWorkflow/workflowConf",
    // rr);
    // // right below the wrapper is an instance of
    // // ExecutablePlanDefinition
    // digester.addCallParam("*/plan/executablePlan/planWorkflow/workflowConf",
    // 0, 1);
    // // provide the name of the setter method
    // digester.addObjectParam("*/plan/executablePlan/planWorkflow/workflowConf",
    // 1, "setExecutablePlan");
    //
    // // the generated node is not accessible as CallParam (why?!?), but
    // // available for addSetNext
    // digester.addSetNext("*/plan/executablePlan/planWorkflow/workflowConf",
    // "setNode");
    //
    // //
    // // Import EPrints executable plan if present
    // //
    // digester.addObjectCreate("*/plan/executablePlan/eprintsPlan",
    // NodeContentWrapper.class);
    // // then an element for workflowConf
    // digester.addRule("*/plan/executablePlan/eprintsPlan", new
    // NodeCreateRule());
    //
    // CallMethodRule rr2 = new CallMethodRule(1,
    // "setNodeContentEPrintsPlan", 2);
    // digester.addRule("*/plan/executablePlan/eprintsPlan", rr2);
    // // right below the wrapper is an instance of
    // // ExecutablePlanDefinition
    // digester.addCallParam("*/plan/executablePlan/eprintsPlan", 0, 1);
    // // provide the name of the setter method
    // digester.addObjectParam("*/plan/executablePlan/eprintsPlan", 1,
    // "setEprintsExecutablePlan");

    // digester.addSetNext("*/plan/executablePlan/eprintsPlan", "setNode");

    // Plan definition
    digester.addObjectCreate("*/plan/planDefinition", PlanDefinition.class);
    digester.addSetProperties("*/plan/planDefinition");
    digester.addSetNext("*/plan/planDefinition", "setPlanDefinition");

    digester.addCallMethod("*/plan/planDefinition/costsIG", "setCostsIG", 0);
    digester.addCallMethod("*/plan/planDefinition/costsPA", "setCostsPA", 0);
    digester.addCallMethod("*/plan/planDefinition/costsPE", "setCostsPE", 0);
    digester.addCallMethod("*/plan/planDefinition/costsQA", "setCostsQA", 0);
    digester.addCallMethod("*/plan/planDefinition/costsREI", "setCostsREI", 0);
    digester.addCallMethod("*/plan/planDefinition/costsRemarks", "setCostsRemarks", 0);
    digester.addCallMethod("*/plan/planDefinition/costsRM", "setCostsRM", 0);
    digester.addCallMethod("*/plan/planDefinition/costsTCO", "setCostsTCO", 0);
    digester.addCallMethod("*/plan/planDefinition/responsibleExecution", "setResponsibleExecution", 0);
    digester.addCallMethod("*/plan/planDefinition/responsibleMonitoring", "setResponsibleMonitoring", 0);

    digester.addObjectCreate("*/plan/planDefinition/triggers", TriggerDefinition.class);
    digester.addSetNext("*/plan/planDefinition/triggers", "setTriggers");
    // every time a */plan/basis/triggers/trigger is encountered:
    digester.addFactoryCreate("*/plan/planDefinition/triggers/trigger", TriggerFactory.class);
    digester.addSetNext("*/plan/planDefinition/triggers/trigger", "setTrigger");
}

From source file:org.apache.commons.digester3.examples.api.addressbook.Main.java

private static void addRules(Digester d) {

    // --------------------------------------------------
    // when we encounter a "person" tag, do the following:

    // create a new instance of class Person, and push that
    // object onto the digester stack of objects
    d.addObjectCreate("address-book/person", Person.class);

    // map *any* attributes on the tag to appropriate
    // setter-methods on the top object on the stack (the Person
    // instance created by the preceeding rule).
    ////  w  w w . jav  a 2 s .c  o m
    // For example:
    // if attribute "id" exists on the xml tag, and method setId
    // with one parameter exists on the object that is on top of
    // the digester object stack, then a call will be made to that
    // method. The value will be type-converted from string to
    // whatever type the target method declares (where possible),
    // using the commons ConvertUtils functionality.
    //
    // Attributes on the xml tag for which no setter methods exist
    // on the top object on the stack are just ignored.
    d.addSetProperties("address-book/person");

    // call the addPerson method on the second-to-top object on
    // the stack (the AddressBook object), passing the top object
    // on the stack (the recently created Person object).
    d.addSetNext("address-book/person", "addPerson");

    // --------------------------------------------------
    // when we encounter a "name" tag, call setName on the top
    // object on the stack, passing the text contained within the
    // body of that name element [specifying a zero parameter count
    // implies one actual parameter, being the body text].
    // The top object on the stack will be a person object, because
    // the pattern address-book/person always triggers the
    // ObjectCreateRule we added previously.
    d.addCallMethod("address-book/person/name", "setName", 0);

    // --------------------------------------------------
    // when we encounter an "email" tag, call addEmail on the top
    // object on the stack, passing two parameters: the "type"
    // attribute, and the text within the tag body.
    d.addCallMethod("address-book/person/email", "addEmail", 2);
    d.addCallParam("address-book/person/email", 0, "type");
    d.addCallParam("address-book/person/email", 1);

    // --------------------------------------------------
    // When we encounter an "address" tag, create an instance of class
    // Address and push it on the digester stack of objects. After
    // doing that, call addAddress on the second-to-top object on the
    // digester stack (a "Person" object), passing the top object on
    // the digester stack (the "Address" object). And also set things
    // up so that for each child xml element encountered between the start
    // of the address tag and the end of the address tag, the text
    // contained in that element is passed to a setXXX method on the
    // Address object where XXX is the name of the xml element found.
    d.addObjectCreate("address-book/person/address", Address.class);
    d.addSetNext("address-book/person/address", "addAddress");
    d.addSetNestedProperties("address-book/person/address");
}

From source file:org.apache.commons.digester3.examples.api.dbinsert.Main.java

private static void addRules(Digester d, java.sql.Connection conn) {

    // --------------------------------------------------
    // when we encounter a "table" tag, do the following:

    // Create a new instance of class Table, and push that
    // object onto the digester stack of objects. We only need
    // this so that when a row is inserted, it can find out what
    // the enclosing tablename was.
    ///*from w  w  w.  j  a  v  a  2  s. c  om*/
    // Note that the object is popped off the stack at the end of the
    // "table" tag (normal behaviour for ObjectCreateRule). Because we
    // never added the table object to some parent object, when it is
    // popped off the digester stack it becomes garbage-collected. That
    // is fine in this situation; we've done all the necessary work and
    // don't need the table object any more.
    d.addObjectCreate("database/table", Table.class);

    // Map *any* attributes on the table tag to appropriate
    // setter-methods on the top object on the stack (the Table
    // instance created by the preceeding rule). We only expect one
    // attribute, though: a 'name' attribute specifying what table
    // we are inserting rows into.
    d.addSetProperties("database/table");

    // --------------------------------------------------
    // When we encounter a "row" tag, invoke methods on the provided
    // RowInserterRule instance.
    //
    // This rule creates a Row instance and pushes it on the digester
    // object stack, rather like ObjectCreateRule, so that the column
    // tags have somewhere to store their information. And when the
    // </row> end tag is found, the rule will trigger to remove this
    // object from the stack, and also do an actual database insert.
    //
    // Note that the rule instance we are passing to the digester has
    // been initialised with some useful data (the SQL connection).
    //
    // Note also that in this case we are not using the digester's
    // factory methods to create the rule instance; that's just a
    // convenience - and obviously not an option for Rule classes
    // that are not part of the digester core implementation.
    RowInserterRule rowInserterRule = new RowInserterRule(conn);
    d.addRule("database/table/row", rowInserterRule);

    // --------------------------------------------------
    // when we encounter a "column" tag, call setColumn on the top
    // object on the stack, passing two parameters: the "name"
    // attribute, and the text within the tag body.
    d.addCallMethod("database/table/row/column", "addColumn", 2);
    d.addCallParam("database/table/row/column", 0, "name");
    d.addCallParam("database/table/row/column", 1);
}

From source file:org.apache.commons.digester3.examples.plugins.pipeline.Pipeline.java

public static void main(String[] args) {
    if (args.length != 1) {
        System.err.println("usage: pipeline config-file");
        System.exit(-1);/*www.  ja v  a  2 s. c  o m*/
    }
    String configFile = args[0];

    Digester digester = new Digester();
    PluginRules rc = new PluginRules();
    digester.setRules(rc);

    digester.addObjectCreate("pipeline", Pipeline.class);

    digester.addCallMethod("pipeline/source", "setSource", 1);
    digester.addCallParam("pipeline/source", 0, "file");

    PluginCreateRule pcr = new PluginCreateRule(Transform.class);
    digester.addRule("pipeline/transform", pcr);
    digester.addSetNext("pipeline/transform", "setTransform");

    digester.addCallMethod("pipeline/destination", "setDest", 1);
    digester.addCallParam("pipeline/destination", 0, "file");

    Pipeline pipeline = null;
    try {
        pipeline = digester.parse(configFile);
    } catch (Exception e) {
        System.err.println("oops exception occurred during parse.");
        e.printStackTrace();
        System.exit(-1);
    }

    try {
        pipeline.execute();
    } catch (Exception e) {
        System.err.println("oops exception occurred during pipeline execution.");
        e.printStackTrace();
        System.exit(-1);
    }
}