home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons Digester example source code file (TestRule.java)

This example Commons Digester source code file (TestRule.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons Digester tags/keywords

list, list, override, override, rule, sax, string, string, testrule, testrule, util

The Commons Digester TestRule.java source code

/* $Id: TestRule.java 992060 2010-09-02 19:09:47Z simonetripodi $
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package org.apache.commons.digester;


import java.util.List;

import org.xml.sax.Attributes;


/**
 * <p>This rule implementation is intended to help test digester.
 * The idea is that you can test which rule matches by looking
 * at the identifier.</p>
 *
 * @author Robert Burrell Donkin
 */

public class TestRule extends Rule {

    // ----------------------------------------------------- Instance Variables


    /** String identifing this particular <code>TestRule */
    private String identifier;

    /** Used when testing body text */
    private String bodyText;

    /** Used when testing call orders */
    private List<Rule> order;

    // ----------------------------------------------------------- Constructors

    /**
     * Base constructor.
     *
     * @param identifier Used to tell which TestRule is which
     */
    public TestRule(String identifier) {
        
        this.identifier = identifier;
    }

    /**
     * Constructor sets namespace URI.
     *
     * @param identifier Used to tell which TestRule is which
     * @param namespaceURI Set rule namespace
     */
    public TestRule(
                    String identifier,
                    String namespaceURI) {

        this.identifier = identifier;
        setNamespaceURI(namespaceURI);

    }


    // ------------------------------------------------ Rule Implementation


    /**
     * 'Begin' call.
     */
    @Override
    public void begin(Attributes attributes) {
        appendCall();
    }


    /**
     * 'Body' call.
     */
    @Override
    public void body(String text) {
        this.bodyText = text;
        appendCall();
    }


    /**
     * 'End' call.
     */
    @Override
    public void end() {
        appendCall();
    }


    // ------------------------------------------------ Methods


    /**
     * If a list has been set, append this to the list.
     */
    protected void appendCall() {
        if (order != null)
            order.add(this);
    }


    /**
     * Get the body text that was set.
     */
    public String getBodyText() {
        return bodyText;
    }


    /**
     * Get the identifier associated with this test.
     */
    public String getIdentifier() {
        return identifier;
    }


    /**
     * Get call order list.
     */
    public List<Rule> getOrder() {
        return order;
    }


    /**
     * Set call order list
     */
    public void setOrder(List<Rule> order) {
        this.order = order;
    }


    /**
     * Return the identifier.
     */
    @Override
    public String toString() {
        return identifier;
    }


}

Other Commons Digester examples (source code examples)

Here is a short list of links related to this Commons Digester TestRule.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.