santiagopg 2003/03/31 05:13:09
Modified: java/src/org/apache/xalan/xsltc/compiler Parser.java
XSLTC.java
java/src/org/apache/xalan/xsltc/trax
TemplatesHandlerImpl.java
TransformerFactoryImpl.java
Log:
New implementation for TemplatesHandlerImpl that does not extend
xsltc.compiler.Parser. The new implementation has a simpler init()
method. Also, instances of the new class can be re-used (previously,
there were problems with the output method when an instance was
used more than once).
Revision Changes Path
1.58 +8 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- Parser.java 19 Mar 2003 22:14:08 -0000 1.57
+++ Parser.java 31 Mar 2003 13:13:08 -0000 1.58
@@ -117,16 +117,16 @@
private Hashtable _variableScope;
private Stylesheet _currentStylesheet;
private SymbolTable _symbolTable; // Maps QNames to syntax-tree nodes
- private Output _output = null;
+ private Output _output;
private Template _template; // Reference to the template being
parsed.
- private boolean _rootNamespaceDef = false; // Used for validity check
+ private boolean _rootNamespaceDef; // Used for validity check
- private SyntaxTreeNode _root = null;
+ private SyntaxTreeNode _root;
private String _target;
- private int _currentImportPrecedence = 1;
+ private int _currentImportPrecedence;
public Parser(XSLTC xsltc) {
_xsltc = xsltc;
@@ -144,6 +144,9 @@
_symbolTable = new SymbolTable();
_xpathParser = new XPathParser(this);
_currentStylesheet = null;
+ _output = null;
+ _root = null;
+ _rootNamespaceDef = false;
_currentImportPrecedence = 1;
initStdClasses();
1.50 +4 -4
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
Index: XSLTC.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- XSLTC.java 19 Mar 2003 22:14:08 -0000 1.49
+++ XSLTC.java 31 Mar 2003 13:13:08 -0000 1.50
@@ -165,10 +165,10 @@
/**
* Only for user by the internal TrAX implementation.
*/
- public void setParser(Parser parser) {
- _parser = parser;
+ public Parser getParser() {
+ return _parser;
}
-
+
/**
* Only for user by the internal TrAX implementation.
*/
1.20 +109 -36
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java
Index: TemplatesHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesHandlerImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TemplatesHandlerImpl.java 10 Feb 2003 17:35:19 -0000 1.19
+++ TemplatesHandlerImpl.java 31 Mar 2003 13:13:09 -0000 1.20
@@ -76,14 +76,17 @@
import org.apache.xalan.xsltc.compiler.SyntaxTreeNode;
import org.apache.xalan.xsltc.compiler.XSLTC;
+import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.Attributes;
/**
* Implementation of a JAXP1.1 TemplatesHandler
*/
-public class TemplatesHandlerImpl extends Parser
- implements TemplatesHandler, SourceLoader
+public class TemplatesHandlerImpl
+ implements ContentHandler, TemplatesHandler, SourceLoader
{
/**
* System ID for this stylesheet.
@@ -105,6 +108,11 @@
* object belongs to.
*/
private TransformerFactoryImpl _tfactory = null;
+
+ /**
+ * A reference to XSLTC's parser object.
+ */
+ private Parser _parser = null;
/**
* Default constructor
@@ -112,22 +120,14 @@
protected TemplatesHandlerImpl(int indentNumber,
TransformerFactoryImpl tfactory)
{
- super(null);
_indentNumber = indentNumber;
_tfactory = tfactory;
- }
-
- /**
- * Internal initialization
- */
- public void init() {
- // Create and initialize a stylesheet compiler
- final XSLTC xsltc = new XSLTC();
- super.setXSLTC(xsltc);
- xsltc.init();
- super.init();
- xsltc.setParser(this);
- xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
+
+ // Initialize a parser object
+ XSLTC xsltc = new XSLTC();
+ xsltc.init();
+ xsltc.setOutputType(XSLTC.BYTEARRAY_OUTPUT);
+ _parser = xsltc.getParser();
}
/**
@@ -168,7 +168,7 @@
*/
public Templates getTemplates() {
try {
- final XSLTC xsltc = getXSLTC();
+ XSLTC xsltc = _parser.getXSLTC();
// Set a document loader (for xsl:include/import) if defined
if (_uriResolver != null) {
@@ -189,25 +189,25 @@
transletName = xsltc.getClassName();
Stylesheet stylesheet = null;
- SyntaxTreeNode root = getDocumentRoot();
+ SyntaxTreeNode root = _parser.getDocumentRoot();
// Compile the translet - this is where the work is done!
- if (!errorsFound() && root != null) {
+ if (!_parser.errorsFound() && root != null) {
// Create a Stylesheet element from the root node
- stylesheet = makeStylesheet(root);
+ stylesheet = _parser.makeStylesheet(root);
stylesheet.setSystemId(_systemId);
stylesheet.setParentStylesheet(null);
- setCurrentStylesheet(stylesheet);
+ _parser.setCurrentStylesheet(stylesheet);
// Set it as top-level in the XSLTC object
xsltc.setStylesheet(stylesheet);
// Create AST under the Stylesheet element
- createAST(stylesheet);
+ _parser.createAST(stylesheet);
}
// Generate the bytecodes and output the translet class(es)
- if (!errorsFound() && stylesheet != null) {
+ if (!_parser.errorsFound() && stylesheet != null) {
stylesheet.setMultiDocument(xsltc.isMultiDocument());
// Class synchronization is needed for BCEL
@@ -216,13 +216,13 @@
}
}
- if (!errorsFound()) {
+ if (!_parser.errorsFound()) {
// Check that the transformation went well before returning
final byte[][] bytecodes = xsltc.getBytecodes();
if (bytecodes != null) {
final TemplatesImpl templates =
new TemplatesImpl(xsltc.getBytecodes(), transletName,
- getOutputProperties(), _indentNumber, _tfactory);
+ _parser.getOutputProperties(), _indentNumber,
_tfactory);
// Set URIResolver on templates object
if (_uriResolver != null) {
@@ -239,16 +239,6 @@
}
/**
- * Recieve an object for locating the origin of SAX document events.
- * Most SAX parsers will use this method to inform content handler
- * of the location of the parsed document.
- */
- public void setDocumentLocator(Locator locator) {
- super.setDocumentLocator(locator);
- setSystemId(locator.getSystemId());
- }
-
- /**
* This method implements XSLTC's SourceLoader interface. It is used to
* glue a TrAX URIResolver to the XSLTC compiler's Input and Import
classes.
*
@@ -269,6 +259,89 @@
// Falls through
}
return null;
+ }
+
+ // -- ContentHandler --------------------------------------------------
+
+ /**
+ * Re-initialize parser and forward SAX2 event.
+ */
+ public void startDocument() {
+ _parser.init();
+ _parser.startDocument();
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void endDocument() {
+ _parser.endDocument();
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void startPrefixMapping(String prefix, String uri) {
+ _parser.startPrefixMapping(prefix, uri);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void endPrefixMapping(String prefix) {
+ _parser.endPrefixMapping(prefix);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void startElement(String uri, String localname, String qname,
+ Attributes attributes) throws SAXException
+ {
+ _parser.startElement(uri, localname, qname, attributes);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void endElement(String uri, String localname, String qname) {
+ _parser.endElement(uri, localname, qname);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void characters(char[] ch, int start, int length) {
+ _parser.characters(ch, start, length);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void processingInstruction(String name, String value) {
+ _parser.processingInstruction(name, value);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void ignorableWhitespace(char[] ch, int start, int length) {
+ _parser.ignorableWhitespace(ch, start, length);
+ }
+
+ /**
+ * Just forward SAX2 event to parser object.
+ */
+ public void skippedEntity(String name) {
+ _parser.skippedEntity(name);
+ }
+
+ /**
+ * Set internal system Id and forward SAX2 event to parser object.
+ */
+ public void setDocumentLocator(Locator locator) {
+ setSystemId(locator.getSystemId());
+ _parser.setDocumentLocator(locator);
}
}
1.60 +1 -2
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- TransformerFactoryImpl.java 19 Mar 2003 22:14:10 -0000 1.59
+++ TransformerFactoryImpl.java 31 Mar 2003 13:13:09 -0000 1.60
@@ -764,7 +764,6 @@
{
final TemplatesHandlerImpl handler =
new TemplatesHandlerImpl(_indentNumber, this);
- handler.init();
if (_uriResolver != null) {
handler.setURIResolver(_uriResolver);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]