import org.xml.sax.*;
import org.xml.sax.helpers.*;

/**
 * Handles accident-reports contained in an incidents file
 *
 * Note: This class both contains logic and performs I/O.  It would
 * be better to use the Observer pattern.  The current approach is used
 * for simplicity.
 *
 * @version  1.0
 * @author   Prof. David Bernstein, James Madison University
 */
public class AccidentReportHandler extends DefaultHandler
{


    /**
     * Receive notification of the start of an element
     *
     * @param uri        The namespace URI 
     * @param localName  The local name or the empty string (if no namespace)
     * @param qName      The qualified name (with prefix)
     * @param attributes The specified or default attributes
     */
    public void startElement(String uri, String localName, String qName,
			     Attributes attributes)
    {
       String       size, type;


       if (qName.equals("accident-report")) 
       {
          size = attributes.getValue("size");
          type = attributes.getValue("type");

          System.out.println("\n\nAccident Report: ");
          System.out.println("    Description:     " + type);
          System.out.println("    No. of vehicles: " + size);
       }
    }

}

