Package org.apache.commons.digester

Examples of org.apache.commons.digester.Rule


     * working.
     */
    private void addOldArgRules(Digester digester) {

        // Create a new rule to process args elements
        Rule rule = new Rule() {
            public void begin(String namespace, String name,
                               Attributes attributes) throws Exception {
                // Create the Arg
                Arg arg = new Arg();
                arg.setKey(attributes.getValue("key"));
View Full Code Here


    // Handle cases where the key is specified as an attribute on the entry
    digester.addCallParam("*/map/entry", 0, "key");

    // Handle casses where the key is specified as a child value element on
    // the entry
    Rule createValueObject = new CreateValueObjectRule("type");
    digester.addRule("*/map/entry/key/value", createValueObject);
    // Since our createValueObject rule runs processing at the very end,
    // and since the default CallParamRule processes at the beginning
    // tag, we need to use a custom "CallParamAtEnd" rule.
    Rule callParamAtEnd = new CallParamAtEndRule(0, true);
    digester.addRule("*/map/entry/key/value", callParamAtEnd);

    // Override some of the bean rules, as we want to do something different
    // here
    digester.addObjectCreate("*/map/entry/key/bean", "java.lang.Object",
View Full Code Here

    digester.addSetProperty("*/bean/property", "name", "value");

    // Add an object set previously with the CallParamRule to the bean
    // property. This rule is used by the collections as well as properties
    // that expect beans
    Rule setPropertyWithObject = new SetPropertyWithParameterRule("name");
    digester.addRule("*/bean/property", setPropertyWithObject);

    // Add the bean to the parameter set (or to a <list>)
    digester.addSetNext("*/bean", "add");

View Full Code Here

    // added to the properties of a parent bean
    digester.addCallParam("*/bean/property/bean", 0, true);
  }

  private void registerValueObjectRules(Digester digester) {
    Rule createValueObject = new CreateValueObjectRule("type");
    digester.addRule("tests/test/value", createValueObject);
    digester.addSetNext("tests/test/value", "add", Object.class.getName());

    // Handle nulls for all value elements
    Rule flagNull = new FlagValueObjectIsNullRule();
    digester.addRule("*/value/null", flagNull);

    // Also allow setting bean properties using value elements
    // This is exactly like the Spring "long" property syntax
    // We do it this way so that we have full support of the "type"
    // attribute on the value object.
    digester.addRule("*/bean/property/value", createValueObject);

    // Since our createValueObject rule runs processing at the very end,
    // and since the default CallParamRule processes at the beginning
    // tag, we need to use a custom "CallParamAtEnd" rule.
    Rule callParamAtEnd = new CallParamAtEndRule(0, true);
    digester.addRule("*/bean/property/value", callParamAtEnd);
  }
View Full Code Here

    // added to the properties of the parent bean (or added to another
    // collection)
    digester.addCallParam("*/list", 0, true);

    // -- Rules for basic values nested under lists
    Rule createValueObject = new CreateValueObjectRule("type");
    digester.addRule("*/list/value", createValueObject);
    digester.addSetNext("*/list/value", "add", Object.class.getName());

    // -- Rules for lists nested under lists
    // Create an ArrayList for each nested <list> element
View Full Code Here

    // added to the properties of the parent bean (or added to another
    // collection)
    digester.addCallParam("*/set", 0, true);

    // -- Rules for basic values nested under sets
    Rule createValueObject = new CreateValueObjectRule("type");
    digester.addRule("*/set/value", createValueObject);
    digester.addSetNext("*/set/value", "add", Object.class.getName());

    // -- Rules for sets nested under sets
    // Create a HashSet for each nested <set> element
View Full Code Here

        // <binding> inside <component>

        pattern = rootElementName + "/component/binding";

        Rule createBindingSpecificationRule = new CreateBindingSpecificationRule();

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.DYNAMIC);
        digester.addSetExtendedProperty(pattern, "expression", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <field-binding> inside <component>
        // For compatibility with 1.3 DTD only, removed in 3.0 DTD

        pattern = rootElementName + "/component/field-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.FIELD);
        digester.addSetExtendedProperty(pattern, "field-name", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <inherited-binding> inside <component>

        pattern = rootElementName + "/component/inherited-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.INHERITED);
        digester.addSetLimitedProperties(pattern, "parameter-name", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <static-binding> inside <component>

        pattern = rootElementName + "/component/static-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STATIC);
        digester.addSetExtendedProperty(pattern, "value", "value", true);
        digester.addConnectChild(pattern, "setBinding", "name");

        // <string-binding> inside <component>
        // Maintained just for 1.3 DTD compatibility

        pattern = rootElementName + "/component/string-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STRING);
        digester.addSetLimitedProperties(pattern, "key", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // Renamed to <message-binding> in the 3.0 DTD

        pattern = rootElementName + "/component/message-binding";

        digester.addRule(pattern, createBindingSpecificationRule);
        digester.addInitializeProperty(pattern, "type", BindingType.STRING);
        digester.addSetLimitedProperties(pattern, "key", "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <listener-binding> inside <component>

        pattern = rootElementName + "/component/listener-binding";

        digester.addRule(pattern, new CreateListenerBindingSpecificationRule());
        digester.addSetLimitedProperties(pattern, "language", "language");
        digester.addBody(pattern, "value");
        digester.addConnectChild(pattern, "setBinding", "name");

        // <external-asset>

        pattern = rootElementName + "/external-asset";

        Rule createAssetSpecificationRule = new CreateAssetSpecificationRule();

        digester.addRule(pattern, createAssetSpecificationRule);
        digester.addInitializeProperty(pattern, "type", AssetType.EXTERNAL);
        digester.addValidate(
            pattern,
View Full Code Here

    /**
     * Factory for creating a BeanPropertySetterRule.
     */
    private class BeanPropertySetterRuleFactory extends AbstractObjectCreationFactory {
        public Object createObject(Attributes attributes) throws Exception {
            Rule beanPropertySetterRule = null;
            String propertyname = attributes.getValue("propertyname");
               
            if (propertyname == null) {
                // call the setter method corresponding to the element name.
                beanPropertySetterRule = new BeanPropertySetterRule();
View Full Code Here

    /**
     * Factory for creating a CallMethodRule.
     */
    protected class CallMethodRuleFactory extends AbstractObjectCreationFactory {
        public Object createObject(Attributes attributes) {
            Rule callMethodRule = null;
            String methodName = attributes.getValue("methodname");

            // Select which element is to be the target. Default to zero,
            // ie the top object on the stack.
            int targetOffset = 0;
View Full Code Here

            // create callparamrule
            int paramIndex = Integer.parseInt(attributes.getValue("paramnumber"));
            String attributeName = attributes.getValue("attrname");
            String fromStack = attributes.getValue("from-stack");
            String stackIndex = attributes.getValue("stack-index");
            Rule callParamRule = null;

            if (attributeName == null) {
                if (stackIndex != null) {                   
                    callParamRule = new CallParamRule(
                        paramIndex, Integer.parseInt(stackIndex));               
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.