    1   /*
    2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    3    *
    4    * This software is open source.
    5    * See the bottom of this file for the licence.
    6    */
    7
    8   package org.dom4j.io;
    9
    10  import junit.textui.TestRunner;
    11
    12  import org.dom4j.AbstractTestCase;
    13  import org.dom4j.ElementHandler;
    14
    15  /***
    16   * DOCUMENT ME!
    17   *
    18   * @author Maarten Coene
    19   */
    20  public class DispatchHandlerTest extends AbstractTestCase {
    21      public static void main(String[] args) {
    22          TestRunner.run(DispatchHandlerTest.class);
    23      }
    24
    25      public void testBug611445() throws Exception {
    26          MyHandler handler = new MyHandler();
    27
    28          SAXReader reader = new SAXReader();
    29          reader.addHandler("/products/product/colour", handler);
    30          reader.read(getFile("/xml/test/sample.xml"));
    31
    32          assertEquals(3, handler.getCount());
    33
    34          reader.read(getFile("/xml/test/sample.xml"));
    35          assertEquals(6, handler.getCount());
    36      }
    37
    38      private static class MyHandler implements ElementHandler {
    39          private int count = 0;
    40
    41          public void onEnd(org.dom4j.ElementPath elementPath) {
    42          }
    43
    44          public void onStart(org.dom4j.ElementPath elementPath) {
    45              count++;
    46          }
    47
    48          int getCount() {
    49              return count;
    50          }
    51      }
    52  }
    53
    54  /*
    55   * Redistribution and use of this software and associated documentation
    56   * ("Software"), with or without modification, are permitted provided that the
    57   * following conditions are met:
    58   *
    59   * 1. Redistributions of source code must retain copyright statements and
    60   * notices. Redistributions must also contain a copy of this document.
    61   *
    62   * 2. Redistributions in binary form must reproduce the above copyright notice,
    63   * this list of conditions and the following disclaimer in the documentation
    64   * and/or other materials provided with the distribution.
    65   *
    66   * 3. The name "DOM4J" must not be used to endorse or promote products derived
    67   * from this Software without prior written permission of MetaStuff, Ltd. For
    68   * written permission, please contact dom4j-info@metastuff.com.
    69   *
    70   * 4. Products derived from this Software may not be called "DOM4J" nor may
    71   * "DOM4J" appear in their names without prior written permission of MetaStuff,
    72   * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    73   *
    74   * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    75   *
    76   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    77   * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    78   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    79   * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    80   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    81   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    82   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    83   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    84   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    85   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    86   * POSSIBILITY OF SUCH DAMAGE.
    87   *
    88   * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    89   */