import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

public class close
{
    public static void main (String argv [])
    {
	if (argv.length == 0)
	    argv = new String [] {

		// both current versions of AElfred2
		"gnu.xml.aelfred2.SAXDriver",
		"gnu.xml.aelfred2.XmlReader",

		// branches off an old fork of AElfred2
		"com.icl.saxon.aelfred.SAXDriver",
		"org.dom4j.io.aelfred.SAXDriver",

		// non-AElfred2 parsers :)
		"org.apache.crimson.parser.XMLReaderImpl",
		"oracle.xml.parser.v2.SAXParser",
		"org.apache.xerces.parsers.SAXParser",
		"com.jclark.xml.sax.SAX2Driver"
		};

	for (int i = 0; i < argv.length; i++)
	    testClose (argv [i]);
    }

    static byte		foo [] = { '<', 'f', 'o', 'o', '/', '>' };

    static boolean	closed;

    private static void testClose (String name)
    {
	XMLReader	parser;
	InputSource	in;

	System.out.print (name);
	System.out.print (" ... ");
	try {
	    parser = XMLReaderFactory.createXMLReader (name);
	} catch (Exception e) {
	    System.out.println ("CAN'T TEST");
	    return;
	}

	try {
	    Reader		r;

	    System.out.print ("char: ");
	    closed = false;
	    in = new InputSource (new StringReader ("<foo/>") {
		    public void close () { closed = true; }
		    });
	    parser.parse (in);

	    if (closed)
		System.out.print ("closed ");
	    else
		System.out.print ("OPEN ");

	} catch (Exception e) {
	    System.out.print ("FAIL ");
	}

	try {
	    Reader		r;

	    System.out.print (", byte: ");
	    closed = false;
	    in = new InputSource (new ByteArrayInputStream (foo) {
		    public void close () { closed = true; }
		    });
	    parser.parse (in);

	    if (closed)
		System.out.print ("closed ");
	    else
		System.out.print ("OPEN ");

	} catch (Exception e) {
	    System.out.print ("FAIL ");
	}

	System.out.println ();
    }
}

