From 81bcd5c1f677de9c79155c87bcfbfc5896920403 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 20 Apr 2010 14:16:25 -0700 Subject: Fixing reset() on SAXParser and DocumentBuilder, and cleaning up nearby tests. Also fixing vogar to support a directory of test expectations, so we can group them by file rather than colocating failures we want to fix with those that we don't. --- xml/src/main/java/javax/xml/parsers/SAXParser.java | 2 +- .../java/org/apache/harmony/xml/ExpatReader.java | 2 +- .../harmony/xml/parsers/DocumentBuilderImpl.java | 17 +++++----- .../apache/harmony/xml/parsers/SAXParserImpl.java | 37 +++++++++++++++++----- 4 files changed, 40 insertions(+), 18 deletions(-) (limited to 'xml') diff --git a/xml/src/main/java/javax/xml/parsers/SAXParser.java b/xml/src/main/java/javax/xml/parsers/SAXParser.java index cd020ab..8c52461 100644 --- a/xml/src/main/java/javax/xml/parsers/SAXParser.java +++ b/xml/src/main/java/javax/xml/parsers/SAXParser.java @@ -63,7 +63,7 @@ import org.xml.sax.helpers.DefaultHandler; * given {@link org.xml.sax.HandlerBase} or the * {@link org.xml.sax.helpers.DefaultHandler} are called.

* - * Implementors of this class which wrap an underlaying implementation + * Implementations of this class which wrap an underlying implementation * can consider using the {@link org.xml.sax.helpers.ParserAdapter} * class to initially adapt their SAX1 implementation to work under * this revised class. diff --git a/xml/src/main/java/org/apache/harmony/xml/ExpatReader.java b/xml/src/main/java/org/apache/harmony/xml/ExpatReader.java index d187456..3bf5d07 100644 --- a/xml/src/main/java/org/apache/harmony/xml/ExpatReader.java +++ b/xml/src/main/java/org/apache/harmony/xml/ExpatReader.java @@ -148,7 +148,7 @@ public class ExpatReader implements XMLReader { if (name.equals(LEXICAL_HANDLER_PROPERTY)) { // The object must implement LexicalHandler - if (value instanceof LexicalHandler) { + if (value instanceof LexicalHandler || value == null) { this.lexicalHandler = (LexicalHandler) value; return; } diff --git a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java index 8bce9aa..31384a0 100644 --- a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java @@ -57,19 +57,20 @@ class DocumentBuilderImpl extends DocumentBuilder { private static DOMImplementationImpl dom = DOMImplementationImpl.getInstance(); private boolean coalescing; - private EntityResolver entityResolver; - private ErrorHandler errorHandler; - private boolean ignoreComments; - private boolean ignoreElementContentWhitespace; - private boolean namespaceAware; - - DocumentBuilderImpl() { - // Do nothing. + // adding a new field? don't forget to update reset(). + + @Override public void reset() { + coalescing = false; + entityResolver = null; + errorHandler = null; + ignoreComments = false; + ignoreElementContentWhitespace = false; + namespaceAware = false; } @Override diff --git a/xml/src/main/java/org/apache/harmony/xml/parsers/SAXParserImpl.java b/xml/src/main/java/org/apache/harmony/xml/parsers/SAXParserImpl.java index b3af61f..55de4b3 100644 --- a/xml/src/main/java/org/apache/harmony/xml/parsers/SAXParserImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/parsers/SAXParserImpl.java @@ -16,6 +16,8 @@ package org.apache.harmony.xml.parsers; +import java.util.Collections; +import java.util.HashMap; import org.apache.harmony.xml.ExpatReader; import java.util.Map; @@ -30,25 +32,44 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderAdapter; /** - * Provides a straightforward SAXParser implementation based on ExpatReader. - * The class is used internally only, thus only notable members that are not - * already in the abstract superclass are documented. Hope that's ok. + * A SAX parser based on Expat. */ -class SAXParserImpl extends SAXParser { +final class SAXParserImpl extends SAXParser { + private Map initialFeatures; private XMLReader reader; - private Parser parser; - SAXParserImpl(Map features) + SAXParserImpl(Map initialFeatures) throws SAXNotRecognizedException, SAXNotSupportedException { - reader = new ExpatReader(); + this.initialFeatures = initialFeatures.isEmpty() + ? Collections.emptyMap() + : new HashMap(initialFeatures); + resetInternal(); + } - for (Map.Entry entry : features.entrySet()) { + private void resetInternal() + throws SAXNotSupportedException, SAXNotRecognizedException { + reader = new ExpatReader(); + for (Map.Entry entry : initialFeatures.entrySet()) { reader.setFeature(entry.getKey(), entry.getValue()); } } + @Override public void reset() { + /* + * The exceptions are impossible. If any features are unrecognized or + * unsupported, construction of this instance would have failed. + */ + try { + resetInternal(); + } catch (SAXNotRecognizedException e) { + throw new AssertionError(); + } catch (SAXNotSupportedException e) { + throw new AssertionError(); + } + } + @Override public Parser getParser() { if (parser == null) { -- cgit v1.1