You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@apache.org on 2001/01/05 10:33:28 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/util SymbolTable.java
andyc 01/01/05 01:33:28
Modified: java/src/org/apache/xerces/impl Tag: xerces_j_2
XMLErrorReporter.java
java/src/org/apache/xerces/impl/validation Tag: xerces_j_2
GrammarPool.java
java/src/org/apache/xerces/parsers Tag: xerces_j_2
CachingParserPool.java XMLDocumentParser.java
XMLParser.java
java/src/org/apache/xerces/util Tag: xerces_j_2
SymbolTable.java
Log:
1) Added lots more comments.
2) Added protected factory methods for parser components. This allows
greater power by subclassers to take advantage of the default
implementation for most components but plug in specialized
versions of certain components. For example: a custom datatype
validator factory or validator component.
3) Implemented CachingParserPool. However, more work needs to be
done before it can be used. First, there's an issue of whether
the symbol table and grammar pool cache should be flushed with
each new parse (yes if single parser instance or shadowed from
parser pool; no if not shadowed from parser pool). Will add a
feature to support this functionality.
Also thinking of adding another feature that will allow the
application to select whether grammars are resolved or if they
*must* come from the grammar pool. This will allow people to
control exactly which grammars are to be used for validation
-- a much requested feature.
Lastly, I want to create a more powerful grammar pool that can
be populated and queried with 2 types of grammars: those keyed
by target namespace (ala Schema); and those keyed by allowed
root element name (ala DTD). The validator would have to be
modified to support this, though.
4) Added another reportError method to XMLErrorReporter to allow
people to report an error at a specific location instead of
only at the current parsing location. We don't currently use
this functionality in the parser but it will allow us to do
things like store the location of each IDREF so that if
there's an error, we report the location at the reference
and not at the end of the document like we do now. Neat!
5) Did I do anything else this time? Can't remember.
Revision Changes Path
No revision
No revision
1.1.2.7 +27 -3 xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLErrorReporter.java
Index: XMLErrorReporter.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Attic/XMLErrorReporter.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- XMLErrorReporter.java 2000/12/20 06:36:29 1.1.2.6
+++ XMLErrorReporter.java 2001/01/05 09:33:27 1.1.2.7
@@ -107,7 +107,7 @@
* @author Eric Ye, IBM
* @author Andy Clark, IBM
*
- * @version $Id: XMLErrorReporter.java,v 1.1.2.6 2000/12/20 06:36:29 andyc Exp $
+ * @version $Id: XMLErrorReporter.java,v 1.1.2.7 2001/01/05 09:33:27 andyc Exp $
*/
public class XMLErrorReporter
implements XMLComponent {
@@ -185,6 +185,10 @@
// there is no associated ID declared, the error
// could report the location information of the
// reference. -Ac
+ //
+ // NOTE: I added another reportError method that allows the
+ // caller to specify the location of the error being
+ // reported. -Ac
fMessageFormatters = new Hashtable();
fLocator = locator;
@@ -257,6 +261,26 @@
*/
public void reportError(String domain, String key, Object[] arguments,
short severity) throws SAXException {
+ reportError(fLocator, domain, key, arguments, severity);
+ } // reportError(String,String,Object[],short)
+
+ /**
+ * Reports an error at a specific location.
+ *
+ * @param location The error location.
+ * @param domain The error domain.
+ * @param key The key of the error message.
+ * @param arguments The replacement arguments for the error message,
+ * if needed.
+ * @param severity The severity of the error.
+ *
+ * @see SEVERITY_WARNING
+ * @see SEVERITY_ERROR
+ * @see SEVERITY_FATAL_ERROR
+ */
+ public void reportError(Locator location,
+ String domain, String key, Object[] arguments,
+ short severity) throws SAXException {
// REVISIT: [Q] Should we do anything about invalid severity
// parameter? -Ac
@@ -264,7 +288,7 @@
// format error message and create parse exception
MessageFormatter messageFormatter = getMessageFormatter(domain);
String message = messageFormatter.formatMessage(fLocale, key, arguments);
- SAXParseException spe = new SAXParseException(message, fLocator);
+ SAXParseException spe = new SAXParseException(message, location);
// get error handler
ErrorHandler errorHandler = fErrorHandler;
@@ -296,7 +320,7 @@
}
}
- } // reportError(String,String,Object,short)
+ } // reportError(Locator,String,String,Object[],short)
//
// XMLComponent methods
No revision
No revision
1.1.2.4 +43 -24 xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/GrammarPool.java
Index: GrammarPool.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/Attic/GrammarPool.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- GrammarPool.java 2000/10/04 11:12:50 1.1.2.3
+++ GrammarPool.java 2001/01/05 09:33:27 1.1.2.4
@@ -60,8 +60,13 @@
import java.util.Hashtable;
/**
+ * A grammar pool.
+ *
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: GrammarPool.java,v 1.1.2.3 2000/10/04 11:12:50 jeffreyr Exp $
+ * @author Jeffrey Rodriguez, IBM
+ * @author Andy Clark, IBM
+ *
+ * @version $Id: GrammarPool.java,v 1.1.2.4 2001/01/05 09:33:27 andyc Exp $
*/
public class GrammarPool {
@@ -69,47 +74,61 @@
// Data
//
- /** fGrammars */
+ /** Grammars. */
protected Hashtable fGrammars = new Hashtable();
- /**
- * Default Constructor
- */
+ //
+ // Constructors
+ //
+
+ /** Default constructor. */
public GrammarPool() {
- }
+ } // <init>()
+ //
+ // Public methods
+ //
+
/**
+ * Puts the specified grammar into the grammar pool.
*
- * @param key Key to associate with Grammar
- * @param grammar Grammar abstraction used by validator
+ * @param key Key to associate with grammar.
+ * @param grammar Grammar object.
*/
public void putGrammar(String key, Grammar grammar) {
- fGrammars.put( key, grammar);
- } // putGrammar
+ fGrammars.put(key, grammar);
+ } // putGrammar(String,Grammar)
/**
- * getGrammar
- *
- * @param key
+ * Returns the grammar associated to the specified key.
*
- * @return
+ * @param key The key of the grammar.
*/
public Grammar getGrammar(String key) {
- return(Grammar) fGrammars.get( key );
- } // getGrammar
+ return (Grammar)fGrammars.get(key);
+ } // getGrammar(String):Grammar
/**
- * removeGrammar - Removes association of key and Grammar from
- * Grammar pool.
- *
- * @param key
+ * Removes the grammar associated to the specified key from the
+ * grammar pool and returns the removed grammar.
*
- * @return
+ * @param key The key of the grammar.
*/
public Grammar removeGrammar(String key) {
- if ( fGrammars.contains( key ) == true )
- fGrammars.remove( key );
+ if (fGrammars.contains(key)) {
+ return (Grammar)fGrammars.remove(key);
+ }
return null;
- } // removeGrammar
+ } // removeGrammar(String):Grammar
+
+ /**
+ * Returns true if the grammar pool contains a grammar associated
+ * to the specified key.
+ *
+ * @param key The key of the grammar.
+ */
+ public boolean containsGrammar(String key) {
+ return fGrammars.containsKey(key);
+ } // containsGrammar(String):boolean
} // class GrammarPool
No revision
No revision
1.1.2.6 +439 -67 xml-xerces/java/src/org/apache/xerces/parsers/Attic/CachingParserPool.java
Index: CachingParserPool.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/CachingParserPool.java,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- CachingParserPool.java 2000/10/02 00:40:12 1.1.2.5
+++ CachingParserPool.java 2001/01/05 09:33:27 1.1.2.6
@@ -57,116 +57,488 @@
package org.apache.xerces.parsers;
-import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.impl.validation.Grammar;
import org.apache.xerces.impl.validation.GrammarPool;
+import org.apache.xerces.util.SymbolTable;
+
/**
+ * A parser pool that enables caching of grammars. The caching parser
+ * pool is constructed with a specific symbol table and grammar pool
+ * that has already been populated with the grammars used by the
+ * application.
+ * <p>
+ * Once the caching parser pool is constructed, specific parser
+ * instances are created by calling the appropriate factory method
+ * on the parser pool.
+ * <p>
+ * <strong>Note:</strong> There is a performance penalty for using
+ * a caching parser pool due to thread safety. Access to the symbol
+ * table and grammar pool must be synchronized to ensure the safe
+ * operation of the symbol table and grammar pool.
+ * <p>
+ * <strong>Note:</strong> If performance is critical, then another
+ * mechanism needs to be used instead of the caching parser pool.
+ * One approach would be to create parser instances that do not
+ * share these structures. Instead, each instance would get its
+ * own copy to use while parsing. This avoids the synchronization
+ * overhead at the expense of more memory and the time required
+ * to copy the structures for each new parser instance. And even
+ * when a parser instance is re-used, there is a potential for a
+ * memory leak due to new symbols being added to the symbol table
+ * over time. In other words, always take caution to make sure
+ * that your application is thread-safe and avoids leaking memory.
+ *
* @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
- * @version $Id: CachingParserPool.java,v 1.1.2.5 2000/10/02 00:40:12 lehors Exp $
+ * @author Andy Clark, IBM
+ *
+ * @version $Id: CachingParserPool.java,v 1.1.2.6 2001/01/05 09:33:27 andyc Exp $
*/
public class CachingParserPool {
//
- // Data
+ // Constants
//
- /** fSymbolTable */
- protected SymbolTable fSymbolTable;
+ /** Default shadow symbol table (false). */
+ public static final boolean DEFAULT_SHADOW_SYMBOL_TABLE = false;
- /** fGrammarPool */
- protected GrammarPool fGrammarPool;
+ /** Default shadow grammar pool (false). */
+ public static final boolean DEFAULT_SHADOW_GRAMMAR_POOL = false;
//
- // Constructors
+ // Data
//
- /**
- *
+ /**
+ * Symbol table. The symbol table that the caching parser pool is
+ * constructed with is automatically wrapped in a synchronized
+ * version for thread-safety.
*/
- public CachingParserPool() {
- }
+ protected SymbolTable fSynchronizedSymbolTable;
- /**
- *
- *
- * @param symbolTable
+ /**
+ * Grammar pool. The grammar pool that the caching parser pool is
+ * constructed with is automatically wrapped in a synchronized
+ * version for thread-safety.
*/
- public CachingParserPool(SymbolTable symbolTable) {
- }
+ protected GrammarPool fSynchronizedGrammarPool;
- /**
- *
- *
- * @param grammarPool
+ /**
+ * Shadow the symbol table for new parser instances. If true,
+ * new parser instances use shadow copies of the main symbol
+ * table and are not allowed to add new symbols to the main
+ * symbol table. New symbols are added to the shadow symbol
+ * table and are local to the parser instance.
*/
- public CachingParserPool(GrammarPool grammarPool) {
- }
+ protected boolean fShadowSymbolTable = DEFAULT_SHADOW_SYMBOL_TABLE;
- /**
- *
- *
- * @param symbolTable
- * @param grammarPool
+ /**
+ * Shadow the grammar pool for new parser instances. If true,
+ * new parser instances use shadow copies of the main grammar
+ * pool and are not allowed to add new grammars to the main
+ * grammar pool. New grammars are added to the shadow grammar
+ * pool and are local to the parser instance.
*/
- public CachingParserPool(SymbolTable symbolTable, GrammarPool grammarPool) {
- }
+ protected boolean fShadowGrammarPool = DEFAULT_SHADOW_GRAMMAR_POOL;
//
- // Methods
+ // Constructors
//
+ /** Default constructor. */
+ public CachingParserPool() {
+ this(new SymbolTable(), new GrammarPool());
+ } // <init>()
+
/**
- * getSymbolTable
+ * Constructs a caching parser pool with the specified symbol table
+ * and grammar pool.
*
- * @return
+ * @param symbolTable The symbol table.
+ * @param grammarPool The grammar pool.
*/
+ public CachingParserPool(SymbolTable symbolTable, GrammarPool grammarPool) {
+ fSynchronizedSymbolTable = new SynchronizedSymbolTable(symbolTable);
+ fSynchronizedGrammarPool = new SynchronizedGrammarPool(grammarPool);
+ } // <init>(SymbolTable,GrammarPool)
+
+ //
+ // Public methods
+ //
+
+ /** Returns the symbol table. */
public SymbolTable getSymbolTable() {
- return null;
- } // getSymbolTable
+ return fSynchronizedSymbolTable;
+ } // getSymbolTable():SymbolTable
- /**
- * getGrammarPool
- *
- * @return
- */
+ /** Returns the grammar pool. */
public GrammarPool getGrammarPool() {
- return null;
- } // getGrammarPool
+ return fSynchronizedGrammarPool;
+ } // getGrammarPool():GrammarPool
- /**
- * createDOMParser
- *
- * @return
+ // setters and getters
+
+ /**
+ * Sets whether new parser instance receive shadow copies of the
+ * main symbol table.
+ *
+ * @param shadow If true, new parser instances use shadow copies
+ * of the main symbol table and are not allowed to
+ * add new symbols to the main symbol table. New
+ * symbols are added to the shadow symbol table and
+ * are local to the parser instance. If false, new
+ * parser instances are allowed to add new symbols
+ * to the main symbol table.
*/
+ public void setShadowSymbolTable(boolean shadow) {
+ fShadowSymbolTable = shadow;
+ } // setShadowSymbolTable(boolean)
+
+ // factory methods
+
+ /** Creates a new DOM parser. */
public DOMParser createDOMParser() {
- return null;
- } // createDOMParser
+ SymbolTable symbolTable = fShadowSymbolTable
+ ? new ShadowedSymbolTable(fSynchronizedSymbolTable)
+ : fSynchronizedSymbolTable;
+ GrammarPool grammarPool = fShadowGrammarPool
+ ? new ShadowedGrammarPool(fSynchronizedGrammarPool)
+ : fSynchronizedGrammarPool;
+ return new DOMParser(symbolTable, grammarPool);
+ } // createDOMParser():DOMParser
+
+ /** Creates a new SAX parser. */
+ public SAXParser createSAXParser() {
+ SymbolTable symbolTable = fShadowSymbolTable
+ ? new ShadowedSymbolTable(fSynchronizedSymbolTable)
+ : fSynchronizedSymbolTable;
+ GrammarPool grammarPool = fShadowGrammarPool
+ ? new ShadowedGrammarPool(fSynchronizedGrammarPool)
+ : fSynchronizedGrammarPool;
+ return new SAXParser(symbolTable, grammarPool);
+ } // createSAXParser():SAXParser
+ //
+ // Classes
+ //
+
/**
- * createSAXParser
- *
- * @return
+ * Synchronized symbol table.
+ *
+ * @author Andy Clark, IBM
*/
- public SAXParser createSAXParser() {
- return null;
- } // createSAXParser
+ public static final class SynchronizedSymbolTable
+ extends SymbolTable {
+
+ //
+ // Data
+ //
+
+ /** Main symbol table. */
+ protected SymbolTable fSymbolTable;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs a synchronized symbol table. */
+ public SynchronizedSymbolTable(SymbolTable symbolTable) {
+ fSymbolTable = symbolTable;
+ } // <init>(SymbolTable)
+
+ //
+ // SymbolTable methods
+ //
+
+ /**
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
+ *
+ * @param symbol The new symbol.
+ */
+ public String addSymbol(String symbol) {
+
+ synchronized (fSymbolTable) {
+ return fSymbolTable.addSymbol(symbol);
+ }
+
+ } // addSymbol(String)
+
+ /**
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
+ *
+ * @param buffer The buffer containing the new symbol.
+ * @param offset The offset into the buffer of the new symbol.
+ * @param length The length of the new symbol in the buffer.
+ */
+ public String addSymbol(char[] buffer, int offset, int length) {
+
+ synchronized (fSymbolTable) {
+ return fSymbolTable.addSymbol(buffer, offset, length);
+ }
+
+ } // addSymbol(char[],int,int):String
+
+ /**
+ * Returns true if the symbol table already contains the specified
+ * symbol.
+ *
+ * @param symbol The symbol to look for.
+ */
+ public boolean containsSymbol(String symbol) {
+
+ synchronized (fSymbolTable) {
+ return fSymbolTable.containsSymbol(symbol);
+ }
+
+ } // containsSymbol(String):boolean
+
+ /**
+ * Returns true if the symbol table already contains the specified
+ * symbol.
+ *
+ * @param buffer The buffer containing the symbol to look for.
+ * @param offset The offset into the buffer.
+ * @param length The length of the symbol in the buffer.
+ */
+ public boolean containsSymbol(char[] buffer, int offset, int length) {
+
+ synchronized (fSymbolTable) {
+ return fSymbolTable.containsSymbol(buffer, offset, length);
+ }
+
+ } // containsSymbol(char[],int,int):boolean
+ } // class SynchronizedSymbolTable
+
/**
- * createDTDParser
- *
- * @return
+ * Shadowed symbol table.
+ *
+ * @author Andy Clark, IBM
*/
- public DTDParser createDTDParser() {
- return null;
- } // createDTDParser
+ public static final class ShadowedSymbolTable
+ extends SymbolTable {
+
+ //
+ // Data
+ //
+
+ /** Main symbol table. */
+ protected SymbolTable fSymbolTable;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs a shadow of the specified symbol table. */
+ public ShadowedSymbolTable(SymbolTable symbolTable) {
+ fSymbolTable = symbolTable;
+ } // <init>(SymbolTable)
+
+ //
+ // SymbolTable methods
+ //
+
+ /**
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
+ *
+ * @param symbol The new symbol.
+ */
+ public String addSymbol(String symbol) {
+
+ if (fSymbolTable.containsSymbol(symbol)) {
+ return fSymbolTable.addSymbol(symbol);
+ }
+ return super.addSymbol(symbol);
+
+ } // addSymbol(String)
+
+ /**
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
+ *
+ * @param buffer The buffer containing the new symbol.
+ * @param offset The offset into the buffer of the new symbol.
+ * @param length The length of the new symbol in the buffer.
+ */
+ public String addSymbol(char[] buffer, int offset, int length) {
+
+ if (fSymbolTable.containsSymbol(buffer, offset, length)) {
+ return fSymbolTable.addSymbol(buffer, offset, length);
+ }
+ return super.addSymbol(buffer, offset, length);
+
+ } // addSymbol(char[],int,int):String
+
+ /**
+ * Returns a hashcode value for the specified symbol. The value
+ * returned by this method must be identical to the value returned
+ * by the <code>hash(char[],int,int)</code> method when called
+ * with the character array that comprises the symbol string.
+ *
+ * @param symbol The symbol to hash.
+ */
+ public int hash(String symbol) {
+ return fSymbolTable.hash(symbol);
+ } // hash(String):int
+
+ /**
+ * Returns a hashcode value for the specified symbol information.
+ * The value returned by this method must be identical to the value
+ * returned by the <code>hash(String)</code> method when called
+ * with the string object created from the symbol information.
+ *
+ * @param buffer The character buffer containing the symbol.
+ * @param offset The offset into the character buffer of the start
+ * of the symbol.
+ * @param length The length of the symbol.
+ */
+ public int hash(char[] buffer, int offset, int length) {
+ return fSymbolTable.hash(buffer, offset, length);
+ } // hash(char[],int,int):int
+ } // class ShadowedSymbolTable
+
/**
- * createSchemaParser
- *
- * @return
+ * Synchronized grammar pool.
+ *
+ * @author Andy Clark, IBM
*/
- public SchemaParser createSchemaParser() {
- return null;
- } // createSchemaParser
+ public static final class SynchronizedGrammarPool
+ extends GrammarPool {
+
+ //
+ // Data
+ //
+
+ /** Main grammar pool. */
+ private GrammarPool fGrammarPool;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs a synchronized grammar pool. */
+ public SynchronizedGrammarPool(GrammarPool grammarPool) {
+ fGrammarPool = grammarPool;
+ } // <init>(GrammarPool)
+
+ //
+ // GrammarPool methods
+ //
+
+ /**
+ * Puts the specified grammar into the grammar pool.
+ *
+ * @param key Key to associate with grammar.
+ * @param grammar Grammar object.
+ */
+ public void putGrammar(String key, Grammar grammar) {
+ synchronized (fGrammarPool) {
+ fGrammarPool.putGrammar(key, grammar);
+ }
+ } // putGrammar(String,Grammar)
+
+ /**
+ * Returns the grammar associated to the specified key.
+ *
+ * @param key The key of the grammar.
+ */
+ public Grammar getGrammar(String key) {
+ synchronized (fGrammarPool) {
+ return fGrammarPool.getGrammar(key);
+ }
+ } // getGrammar(String):Grammar
+
+ /**
+ * Removes the grammar associated to the specified key from the
+ * grammar pool and returns the removed grammar.
+ *
+ * @param key The key of the grammar.
+ */
+ public Grammar removeGrammar(String key) {
+ synchronized (fGrammarPool) {
+ return fGrammarPool.removeGrammar(key);
+ }
+ } // removeGrammar(String):Grammar
+
+ /**
+ * Returns true if the grammar pool contains a grammar associated
+ * to the specified key.
+ *
+ * @param key The key of the grammar.
+ */
+ public boolean containsGrammar(String key) {
+ synchronized (fGrammarPool) {
+ return fGrammarPool.containsGrammar(key);
+ }
+ } // containsGrammar(String):boolean
+
+ } // class SynchronizedGrammarPool
+
+ /**
+ * Shadowed grammar pool.
+ *
+ * @author Andy Clark, IBM
+ */
+ public static final class ShadowedGrammarPool
+ extends GrammarPool {
+
+ //
+ // Data
+ //
+
+ /** Main grammar pool. */
+ private GrammarPool fGrammarPool;
+
+ //
+ // Constructors
+ //
+
+ /** Constructs a shadowed grammar pool. */
+ public ShadowedGrammarPool(GrammarPool grammarPool) {
+ fGrammarPool = grammarPool;
+ } // <init>(GrammarPool)
+
+ //
+ // GrammarPool methods
+ //
+
+ /**
+ * Returns the grammar associated to the specified key.
+ *
+ * @param key The key of the grammar.
+ */
+ public Grammar getGrammar(String key) {
+
+ if (super.containsGrammar(key)) {
+ return super.getGrammar(key);
+ }
+ return fGrammarPool.getGrammar(key);
+
+ } // getGrammar(String):Grammar
+
+ /**
+ * Returns true if the grammar pool contains a grammar associated
+ * to the specified key.
+ *
+ * @param key The key of the grammar.
+ */
+ public boolean containsGrammar(String key) {
+ return super.containsGrammar(key) || fGrammarPool.containsGrammar(key);
+ } // containsGrammar(String):boolean
+
+ } // class ShadowedGrammarPool
} // class CachingParserPool
1.1.2.29 +83 -42 xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java
Index: XMLDocumentParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLDocumentParser.java,v
retrieving revision 1.1.2.28
retrieving revision 1.1.2.29
diff -u -r1.1.2.28 -r1.1.2.29
--- XMLDocumentParser.java 2001/01/04 08:17:04 1.1.2.28
+++ XMLDocumentParser.java 2001/01/05 09:33:27 1.1.2.29
@@ -68,8 +68,9 @@
import org.apache.xerces.impl.validation.DatatypeValidatorFactory;
import org.apache.xerces.impl.validation.GrammarPool;
import org.apache.xerces.impl.validation.datatypes.DatatypeValidatorFactoryImpl;
-//import org.apache.xerces.impl.validation.validators.XMLDTDValidator;
+
import org.apache.xerces.util.SymbolTable;
+
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLDocumentHandler;
@@ -93,7 +94,7 @@
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
- * @version $Id: XMLDocumentParser.java,v 1.1.2.28 2001/01/04 08:17:04 andyc Exp $
+ * @version $Id: XMLDocumentParser.java,v 1.1.2.29 2001/01/05 09:33:27 andyc Exp $
*/
public abstract class XMLDocumentParser
extends XMLParser
@@ -145,18 +146,21 @@
//
/**
- * Default Constructor.
- * Creates an XMLDocumentParser with its own SymbolTable and GrammarPool.
+ * Constructs a document parser using the default symbol table
+ * and grammar pool.
*/
protected XMLDocumentParser() {
this(new SymbolTable(), new GrammarPool());
} // <init>()
/**
- * Constructor allowing to specify the SymbolTable and GrammarPool to use
+ * Constructor allowing to specify the symbol table and grammar pool
+ * to use. The symbol table and grammar pool are specified together
+ * because the grammars contained in the grammar pool must use the
+ * symbols from the specified symbol table.
*
- * @param symbolTable
- * @param grammarPool
+ * @param symbolTable The symbol table.
+ * @param grammarPool The grammar pool.
*/
protected XMLDocumentParser(SymbolTable symbolTable,
GrammarPool grammarPool) {
@@ -180,11 +184,11 @@
final String GRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.GRAMMAR_POOL_PROPERTY;
fProperties.put(GRAMMAR_POOL, fGrammarPool);
- fScanner = new XMLDocumentScanner();
+ fScanner = createDocumentScanner();
final String DOCUMENT_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_SCANNER_PROPERTY;
fProperties.put(DOCUMENT_SCANNER, fScanner);
- fDTDScanner = new XMLDTDScanner();
+ fDTDScanner = createDTDScanner();
final String DTD_SCANNER = Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_SCANNER_PROPERTY;
fProperties.put(DTD_SCANNER, fDTDScanner);
@@ -196,12 +200,6 @@
final String DATATYPE_VALIDATOR_FACTORY = Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY;
fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
- /***
- fDatatypeValidatorFactory = new DatatypeValidatorFactory();
- final String DATATYE_VALIDATOR_FACTORY = Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYE_VALIDATOR_FACTORY_PROPERTY;
- fProperties.put(DATATYE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);
- /***/
-
} // <init>(SymbolTable,GrammarPool)
//
@@ -218,28 +216,17 @@
// setup document pipeline
- /***/
fScanner.setDocumentHandler(fValidator);
fValidator.setDocumentHandler(this);
- /***
- fScanner.setDocumentHandler(this);
- /***/
// setup dtd pipeline
- /***/
fDTDScanner.setDTDHandler(fValidator);
fValidator.setDTDHandler(this);
- /***
- fDTDScanner.setDTDHandler(this);
- /***/
// setup dtd content model pipeline
/***/
fDTDScanner.setDTDContentModelHandler(fValidator);
fValidator.setDTDContentModelHandler(this);
- /***
- fDTDScanner.setDTDContentModelHandler(this);
- /***/
// reset every component
fScanner.reset(this);
@@ -249,14 +236,33 @@
} // reset()
//
- // XMLComponentManager methods
+ // XMLReader methods
//
/**
- * setFeature
- *
- * @param featureId
- * @param state
+ * Set the state of a feature.
+ * <p>
+ * The feature name is any fully-qualified URI. It is
+ * possible for an XMLReader to recognize a feature name but
+ * to be unable to set its value; this is especially true
+ * in the case of an adapter for a SAX1 {@link org.xml.sax.Parser Parser},
+ * which has no way of affecting whether the underlying parser is
+ * validating, for example.
+ * <p>
+ * Some feature values may be immutable or mutable only
+ * in specific contexts, such as before, during, or after
+ * a parse.
+ *
+ * @param name The feature name, which is a fully-qualified URI.
+ * @param state The requested state of the feature (true or false).
+ *
+ * @exception org.xml.sax.SAXNotRecognizedException When the
+ * XMLReader does not recognize the feature name.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the feature name but
+ * cannot set the requested value.
+ *
+ * @see #getFeature
*/
public void setFeature(String featureId, boolean state)
throws SAXNotRecognizedException, SAXNotSupportedException {
@@ -268,13 +274,34 @@
fDTDScanner.setFeature(featureId, state);
fValidator.setFeature(featureId, state);
- } // setFeature
+ } // setFeature(String,boolean)
/**
- * setProperty
- *
- * @param propertyId
- * @param value
+ * Set the value of a property.
+ * <p>
+ * The property name is any fully-qualified URI. It is
+ * possible for an XMLReader to recognize a property name but
+ * to be unable to set its value; this is especially true
+ * in the case of an adapter for a SAX1 {@link org.xml.sax.Parser
+ * Parser}.
+ * <p>
+ * Some property values may be immutable or mutable only
+ * in specific contexts, such as before, during, or after
+ * a parse.
+ * <p>
+ * This method is also the standard mechanism for setting
+ * extended handlers.
+ *
+ * @param name The property name, which is a fully-qualified URI.
+ * @param state The requested value for the property.
+ *
+ * @exception org.xml.sax.SAXNotRecognizedException When the
+ * XMLReader does not recognize the property name.
+ * @exception org.xml.sax.SAXNotSupportedException When the
+ * XMLReader recognizes the property name but
+ * cannot set the requested value.
+ *
+ * @see #getProperty
*/
public void setProperty(String propertyId, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
@@ -286,7 +313,7 @@
fDTDScanner.setProperty(propertyId, value);
fValidator.setProperty(propertyId, value);
- } // setProperty
+ } // setProperty(String,Object)
/**
* Parses the specified input source.
@@ -301,8 +328,7 @@
if (fParseInProgress) {
// REVISIT - need to add new error message
- throw new SAXException(
- "FWK005 parse may not be called while parsing.");
+ throw new SAXException("FWK005 parse may not be called while parsing.");
}
try {
@@ -311,17 +337,20 @@
fEntityManager.startDocumentEntity(new XMLInputSource(source));
fScanner.scanDocument(true);
fParseInProgress = false;
- } catch (SAXException ex) {
+ }
+ catch (SAXException ex) {
fParseInProgress = false;
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
fParseInProgress = false;
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
- } catch (Exception ex) {
+ }
+ catch (Exception ex) {
fParseInProgress = false;
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
@@ -999,6 +1028,18 @@
//
// Protected methods
//
+
+ // factory methods
+
+ /** Create a document scanner. */
+ protected XMLDocumentScanner createDocumentScanner() {
+ return new XMLDocumentScanner();
+ } // createDocumentScanner():XMLDocumentScanner
+
+ /** Create a DTD scanner. */
+ protected XMLDTDScanner createDTDScanner() {
+ return new XMLDTDScanner();
+ } // createDTDScanner():XMLDTDScanner
/** Create a validator. */
protected XMLValidator createValidator() {
1.1.2.18 +17 -5 xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLParser.java
Index: XMLParser.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/Attic/XMLParser.java,v
retrieving revision 1.1.2.17
retrieving revision 1.1.2.18
diff -u -r1.1.2.17 -r1.1.2.18
--- XMLParser.java 2000/12/13 01:15:13 1.1.2.17
+++ XMLParser.java 2001/01/05 09:33:27 1.1.2.18
@@ -106,7 +106,7 @@
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
- * @version $Id: XMLParser.java,v 1.1.2.17 2000/12/13 01:15:13 lehors Exp $
+ * @version $Id: XMLParser.java,v 1.1.2.18 2001/01/05 09:33:27 andyc Exp $
*/
public abstract class XMLParser
implements XMLComponentManager {
@@ -186,11 +186,11 @@
final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;
fProperties.put(SYMBOL_TABLE, fSymbolTable);
- fEntityManager = new XMLEntityManager();
+ fEntityManager = createEntityManager();
final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
fProperties.put(ENTITY_MANAGER, fEntityManager);
- fErrorReporter = new XMLErrorReporter( fEntityManager.getEntityScanner() );
+ fErrorReporter = createErrorReporter( fEntityManager.getEntityScanner() );
final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
fProperties.put(ERROR_REPORTER, fErrorReporter);
@@ -445,7 +445,7 @@
} // reset()
/**
- * Check a feature. If feature is know and supported, this method simply
+ * Check a feature. If feature is known and supported, this method simply
* returns. Otherwise, the appropriate exception is thrown.
*
* @param featureId The unique identifier (URI) of the feature.
@@ -555,7 +555,7 @@
} // checkFeature(String)
/**
- * Check a property. If the property is know and supported, this method
+ * Check a property. If the property is known and supported, this method
* simply returns. Otherwise, the appropriate exception is thrown.
*
* @param propertyId The unique identifier (URI) of the property
@@ -653,5 +653,17 @@
throw new SAXNotRecognizedException(propertyId);
} // checkProperty(String)
+
+ // factory methods
+
+ /** Creates an entity manager. */
+ protected XMLEntityManager createEntityManager() {
+ return new XMLEntityManager();
+ } // createEntityManager():XMLEntityManager
+
+ /** Creates an error reporter. */
+ protected XMLErrorReporter createErrorReporter(Locator locator) {
+ return new XMLErrorReporter(locator);
+ } // createErrorReporter(Locator):XMLErrorReporter
} // class XMLParser
No revision
No revision
1.1.2.3 +74 -16 xml-xerces/java/src/org/apache/xerces/util/Attic/SymbolTable.java
Index: SymbolTable.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/Attic/SymbolTable.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- SymbolTable.java 2000/10/02 00:40:14 1.1.2.2
+++ SymbolTable.java 2001/01/05 09:33:28 1.1.2.3
@@ -85,7 +85,7 @@
* @author Stubs generated by DesignDoc on Wed Jun 07 11:58:44 PDT 2000
* @author Andy Clark
*
- * @version $Id: SymbolTable.java,v 1.1.2.2 2000/10/02 00:40:14 lehors Exp $
+ * @version $Id: SymbolTable.java,v 1.1.2.3 2001/01/05 09:33:28 andyc Exp $
*/
public class SymbolTable {
@@ -112,22 +112,23 @@
}
//
- // Methods
+ // Public methods
//
/**
- * addSymbol
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
*
- * @param symbol
- *
- * @return
+ * @param symbol The new symbol.
*/
public String addSymbol(String symbol) {
// search for identical symbol
int bucket = hash(symbol) % TABLE_SIZE;
+ int length = symbol.length();
OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = entry.next) {
- int length = symbol.length();
if (length == entry.characters.length) {
for (int i = 0; i < length; i++) {
if (symbol.charAt(i) != entry.characters[i]) {
@@ -146,13 +147,14 @@
} // addSymbol(String):String
/**
- * addSymbol
- *
- * @param buffer
- * @param offset
- * @param length
- *
- * @return
+ * Adds the specified symbol to the symbol table and returns a
+ * reference to the unique symbol. If the symbol already exists,
+ * the previous symbol reference is returned instead, in order
+ * guarantee that symbol references remain unique.
+ *
+ * @param buffer The buffer containing the new symbol.
+ * @param offset The offset into the buffer of the new symbol.
+ * @param length The length of the new symbol in the buffer.
*/
public String addSymbol(char[] buffer, int offset, int length) {
@@ -185,14 +187,15 @@
* @param symbol The symbol to hash.
*/
public int hash(String symbol) {
+
int code = 0;
int length = symbol.length();
for (int i = 0; i < length; i++) {
code = code * 37 + symbol.charAt(i);
}
return code & 0x7FFFFFF;
- }
+ } // hash(String):int
/**
* Returns a hashcode value for the specified symbol information.
@@ -206,12 +209,67 @@
* @param length The length of the symbol.
*/
public int hash(char[] buffer, int offset, int length) {
+
int code = 0;
for (int i = 0; i < length; i++) {
code = code * 37 + buffer[offset + i];
}
return code & 0x7FFFFFF;
- }
+
+ } // hash(char[],int,int):int
+
+ /**
+ * Returns true if the symbol table already contains the specified
+ * symbol.
+ *
+ * @param symbol The symbol to look for.
+ */
+ public boolean containsSymbol(String symbol) {
+
+ // search for identical symbol
+ int bucket = hash(symbol) % TABLE_SIZE;
+ int length = symbol.length();
+ OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = entry.next) {
+ if (length == entry.characters.length) {
+ for (int i = 0; i < length; i++) {
+ if (symbol.charAt(i) != entry.characters[i]) {
+ continue OUTER;
+ }
+ }
+ return true;
+ }
+ }
+
+ return false;
+
+ } // containsSymbol(String):boolean
+
+ /**
+ * Returns true if the symbol table already contains the specified
+ * symbol.
+ *
+ * @param buffer The buffer containing the symbol to look for.
+ * @param offset The offset into the buffer.
+ * @param length The length of the symbol in the buffer.
+ */
+ public boolean containsSymbol(char[] buffer, int offset, int length) {
+
+ // search for identical symbol
+ int bucket = hash(buffer, offset, length) % TABLE_SIZE;
+ OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = entry.next) {
+ if (length == entry.characters.length) {
+ for (int i = 0; i < length; i++) {
+ if (buffer[offset + i] != entry.characters[i]) {
+ continue OUTER;
+ }
+ }
+ return true;
+ }
+ }
+
+ return false;
+
+ } // containsSymbol(char[],int,int):boolean
//
// Classes