morten 01/07/13 03:32:37
Modified: java/src/org/apache/xalan/xsltc/compiler XSLTC.java
java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java
TransformerFactoryImpl.java TransformerImpl.java
Log:
A few minor adjustments to yesterdays JAXP/TrAX implementation. These is one
change in the way the compiler (XSLTC) generates bytecode arrays, and the
rest is basically a cleanup of error reporting and a few added comments.
PR: n/a
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.15 +2 -2
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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- XSLTC.java 2001/07/12 15:54:44 1.14
+++ XSLTC.java 2001/07/13 10:32:07 1.15
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.14 2001/07/12 15:54:44 morten Exp $
+ * @(#)$Id: XSLTC.java,v 1.15 2001/07/13 10:32:07 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -315,7 +315,7 @@
setClassName(className);
if (compile(stylesheetURL)) {
final int count = _classes.size();
- final byte[][] result = new byte[1][count];
+ final byte[][] result = new byte[count][1];
for (int i = 0; i < count; i++)
result[i] = (byte[])_classes.elementAt(i);
return result;
1.3 +29 -4
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
Index: TemplatesImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TemplatesImpl.java 2001/07/12 15:54:56 1.2
+++ TemplatesImpl.java 2001/07/13 10:32:20 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TemplatesImpl.java,v 1.2 2001/07/12 15:54:56 morten Exp $
+ * @(#)$Id: TemplatesImpl.java,v 1.3 2001/07/13 10:32:20 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -63,6 +63,8 @@
package org.apache.xalan.xsltc.trax;
+import java.io.Serializable;
+
import javax.xml.transform.*;
import org.apache.xalan.xsltc.Translet;
@@ -71,10 +73,19 @@
import java.util.Properties;
-public final class TemplatesImpl implements Templates {
+public final class TemplatesImpl implements Templates, Serializable {
+ // Contains the name of the main translet class
private String _transletName = null;
+
+ // Contains the actual class definition for the translet class and
+ // any auxiliary classes (representing node sort records, predicates,
etc.)
private byte[][] _bytecodes = null;
+
+ // This error could occur when a compilation inside the
TransformerFactory
+ // failed and when a template has been loaded from stable storage.
+ private final static String TRANSLET_ERR_MSG =
+ "This template does not contain a valid translet class definition.";
// Our own private class loader - builds Class definitions from bytecodes
private class TransletClassLoader extends ClassLoader {
@@ -84,7 +95,9 @@
}
/**
- *
+ * The only way to create an XSLTC emplate object
+ * The bytecodes for the translet and auxiliary classes, plus the name of
+ * the main translet class, must be supplied
*/
public TemplatesImpl(byte[][] bytecodes, String transletName) {
_bytecodes = bytecodes;
@@ -99,6 +112,9 @@
_bytecodes = bytecodes;
}
+ /**
+ * Returns the translet bytecodes stored in this template
+ */
public byte[][] getTransletBytecodes() {
return(_bytecodes);
}
@@ -110,6 +126,9 @@
_transletName = name;
}
+ /**
+ * Returns the name of the main translet class stored in this template
+ */
public String getTransletName() {
return _transletName;
}
@@ -160,6 +179,7 @@
// Create the class definition from the bytecodes if failed
try {
Class transletClass = defineTransletClasses();
+ if (transletClass == null) return null;
return((Translet)transletClass.newInstance());
}
catch (LinkageError e) { return(null); }
@@ -173,6 +193,8 @@
public Transformer newTransformer() throws
TransformerConfigurationException {
Translet translet = getTransletInstance();
+ if (translet == null)
+ throw new TransformerConfigurationException(TRANSLET_ERR_MSG);
TransformerImpl transformer = new TransformerImpl(translet);
return(transformer);
}
@@ -181,7 +203,10 @@
* JAXP interface implementation - UNFINISHED!!!
*/
public Properties getOutputProperties() {
- // TODO
+ // TODO - this method should extract the output properties stored in
+ // a translet instance. This could prove to be pretty tricky as this
+ // class has a reference to a translet class only and not to an
+ // actual instance of a translet
return new Properties();
}
1.6 +4 -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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TransformerFactoryImpl.java 2001/07/12 15:54:59 1.5
+++ TransformerFactoryImpl.java 2001/07/13 10:32:23 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerFactoryImpl.java,v 1.5 2001/07/12 15:54:59 morten Exp
$
+ * @(#)$Id: TransformerFactoryImpl.java,v 1.6 2001/07/13 10:32:23 morten Exp
$
*
* The Apache Software License, Version 1.1
*
@@ -65,6 +65,7 @@
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
@@ -72,6 +73,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.URIResolver;
import javax.xml.transform.TransformerConfigurationException;
+
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;
@@ -93,7 +95,7 @@
/**
* Implementation of a JAXP1.1 SAXTransformerFactory for Translets.
*/
-public class TransformerFactoryImpl extends SAXTransformerFactory {
+public class TransformerFactoryImpl extends TransformerFactory {
public TransformerFactoryImpl() { /* nothing yet */ }
//////////////////////////////////////////////////////
1.3 +42 -43
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TransformerImpl.java 2001/07/12 15:55:00 1.2
+++ TransformerImpl.java 2001/07/13 10:32:25 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransformerImpl.java,v 1.2 2001/07/12 15:55:00 morten Exp $
+ * @(#)$Id: TransformerImpl.java,v 1.3 2001/07/13 10:32:25 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -94,22 +94,39 @@
private String _encoding = null;
private ContentHandler _handler = null;
+ private final static String TRANSLET_ERR_MSG =
+ "The transformer has no encapsulated translet object.";
+ private final static String HANDLER_ERR_MSG =
+ "No defined output handler for transformation result.";
+
+ /**
+ * Our Transformer objects always need a translet to do the actual work
+ */
public TransformerImpl(Translet translet) {
_translet = (AbstractTranslet)translet;
}
+ /**
+ * JAXP interface implementation
+ */
public void transform(Source source, Result result)
throws TransformerException {
- if (_translet == null) return;
+ // Verify the input
+ if (_translet == null) throw new TransformerException(TRANSLET_ERR_MSG);
_handler = getOutputHandler(result);
- if (_handler == null) return;
+ if (_handler == null) throw new TransformerException(HANDLER_ERR_MSG);
- // finally do the transformation...
- doTransform(source.getSystemId(), _handler, _encoding);
+ // Run the transformation
+ transform(source.getSystemId(), _handler, _encoding);
}
- private ContentHandler getOutputHandler(Result result) {
+ /**
+ * Create an output handler, and get the requested output encoding
+ * from the translet instance
+ */
+ private ContentHandler getOutputHandler(Result result)
+ throws TransformerException {
// Try to get the encoding from Translet (may not be set)
_encoding = _translet.getOutputEncoding();
if (_encoding == null) _encoding = "UTF-8";
@@ -135,6 +152,7 @@
ostream = (OutputStream)(new FileOutputStream(systemid));
return(new DefaultSAXOutputHandler(ostream, _encoding));
}
+ return null;
}
catch (java.io.FileNotFoundException e) {
throw new TransformerException(e);
@@ -142,13 +160,14 @@
catch (java.io.IOException e) {
throw new TransformerException(e);
}
- finally {
- return null;
- }
}
- private void doTransform(String source, ContentHandler handler,
- String encoding) {
+ /**
+ * Internal transformation method - uses the internal APIs of XSLTC
+ */
+ private void transform(String source,
+ ContentHandler handler,
+ String encoding) throws TransformerException {
try {
// Create a SAX parser and get the XMLReader object it uses
final SAXParserFactory factory = SAXParserFactory.newInstance();
@@ -181,54 +200,34 @@
_translet.transform(dom, textOutput);
}
catch (TransletException e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener(e.getMessage());
- } else {
- System.err.println("\nTranslet Error: " + e.getMessage());
- }
- System.exit(1);
+ throw new TransformerException(e);
}
catch (RuntimeException e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener("Runtime Error: " + e.getMessage());
- } else {
- System.err.println("\nRuntime Error: " + e.getMessage());
- }
- System.exit(1);
+ throw new TransformerException(e);
}
catch (FileNotFoundException e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener("File not found: " + e.getMessage());
- } else {
- System.err.println("Error: File not found:"+e.getMessage());
- }
- System.exit(1);
+ throw new TransformerException(e);
}
catch (MalformedURLException e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener("Malformed URL: " + e.getMessage());
- } else {
- System.err.println("Error: Malformed URL: "+e.getMessage());
- }
- System.exit(1);
+ throw new TransformerException(e);
}
catch (UnknownHostException e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener("Cannot resolve URI: " + e.getMessage());
- } else {
- System.err.println("Error: Cannot resolve URI: "+
- e.getMessage());
- }
- System.exit(1);
+ throw new TransformerException(e);
}
catch (Exception e) {
- if (_errorListener != null) {
+ if (_errorListener != null)
postErrorToListener("Internal error: " + e.getMessage());
- } else {
- System.err.println("Internal error: "+e.getMessage());
- e.printStackTrace();
- }
- System.exit(1);
+ throw new TransformerException(e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]