You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mk...@apache.org on 2002/09/30 21:30:12 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler XSLTC.java
mkwan 2002/09/30 12:30:11
Modified: java/src/org/apache/xalan/xsltc/compiler XSLTC.java
Log:
XSLTC support in the Process command line - phase 2
Add two new output types:
- BYTEARRAY_AND_FILE_OUTPUT: return a byte array and generate the translet class
- BYTEARRAY_AND_JAR_OUTPUT: return a byte array and generate the jar file
Add a new compile() interface which accepts the output type as the third
parameter. Use different Vectors to store bytecodes and JavaClass objects.
Revision Changes Path
1.45 +45 -6 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.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- XSLTC.java 17 Sep 2002 22:01:25 -0000 1.44
+++ XSLTC.java 30 Sep 2002 19:30:11 -0000 1.45
@@ -130,6 +130,9 @@
public static final int JAR_OUTPUT = 1;
public static final int BYTEARRAY_OUTPUT = 2;
public static final int CLASSLOADER_OUTPUT = 3;
+ public static final int BYTEARRAY_AND_FILE_OUTPUT = 4;
+ public static final int BYTEARRAY_AND_JAR_OUTPUT = 5;
+
// Compiler options (passed from command line or XSLTC client)
private boolean _debug = false; // -x
@@ -140,6 +143,7 @@
private int _outputType = FILE_OUTPUT; // by default
private Vector _classes;
+ private Vector _bcelClasses;
private boolean _callsNodeset = false;
private boolean _multiDocument = false;
@@ -186,6 +190,7 @@
reset();
_reader = null;
_classes = new Vector();
+ _bcelClasses = new Vector();
}
/**
@@ -421,15 +426,27 @@
* set of byte arrays. One byte array for each generated class.
* @param name The name of the translet class to generate
* @param input An InputSource that will pass in the stylesheet contents
+ * @param outputType The output type
* @return JVM bytecodes that represent translet class definition
*/
- public byte[][] compile(String name, InputSource input) {
- _outputType = BYTEARRAY_OUTPUT;
+ public byte[][] compile(String name, InputSource input, int outputType) {
+ _outputType = outputType;
if (compile(input, name))
return getBytecodes();
else
return null;
}
+
+ /**
+ * Compiles a stylesheet pointed to by a URL. The result is put in a
+ * set of byte arrays. One byte array for each generated class.
+ * @param name The name of the translet class to generate
+ * @param input An InputSource that will pass in the stylesheet contents
+ * @return JVM bytecodes that represent translet class definition
+ */
+ public byte[][] compile(String name, InputSource input) {
+ return compile(name, input, BYTEARRAY_OUTPUT);
+ }
/**
* Set the XMLReader to use for parsing the next input stylesheet
@@ -696,6 +713,19 @@
}
public void dumpClass(JavaClass clazz) {
+
+ if (_outputType == FILE_OUTPUT ||
+ _outputType == BYTEARRAY_AND_FILE_OUTPUT)
+ {
+ File outFile = getOutputFile(clazz.getClassName());
+ String parentDir = outFile.getParent();
+ if (parentDir != null) {
+ File parentFile = new File(parentDir);
+ if (!parentFile.exists())
+ parentFile.mkdirs();
+ }
+ }
+
try {
switch (_outputType) {
case FILE_OUTPUT:
@@ -705,13 +735,22 @@
getOutputFile(clazz.getClassName()))));
break;
case JAR_OUTPUT:
- _classes.addElement(clazz);
+ _bcelClasses.addElement(clazz);
break;
case BYTEARRAY_OUTPUT:
+ case BYTEARRAY_AND_FILE_OUTPUT:
+ case BYTEARRAY_AND_JAR_OUTPUT:
case CLASSLOADER_OUTPUT:
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
clazz.dump(out);
_classes.addElement(out.toByteArray());
+
+ if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)
+ clazz.dump(new BufferedOutputStream(
+ new FileOutputStream(getOutputFile(clazz.getClassName()))));
+ else if (_outputType == BYTEARRAY_AND_JAR_OUTPUT)
+ _bcelClasses.addElement(clazz);
+
break;
}
}
@@ -738,7 +777,7 @@
final Map map = manifest.getEntries();
// create manifest
- Enumeration classes = _classes.elements();
+ Enumeration classes = _bcelClasses.elements();
final String now = (new Date()).toString();
final java.util.jar.Attributes.Name dateAttr =
new java.util.jar.Attributes.Name("Date");
@@ -753,7 +792,7 @@
final File jarFile = new File(_destDir, _jarFileName);
final JarOutputStream jos =
new JarOutputStream(new FileOutputStream(jarFile), manifest);
- classes = _classes.elements();
+ classes = _bcelClasses.elements();
while (classes.hasMoreElements()) {
final JavaClass clazz = (JavaClass)classes.nextElement();
final String className = clazz.getClassName().replace('.','/');
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org