You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by cu...@apache.org on 2001/04/27 22:06:17 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime DefaultRun.java
curcuru 01/04/27 13:06:17
Modified: java/src/org/apache/xalan/xsltc/compiler XSLTC.java
java/src/org/apache/xalan/xsltc/runtime DefaultRun.java
Log:
Contitionalize calls to System.exit to allow running from containing Java programs (-s turns it off, for lack of a better flag)
Revision Changes Path
1.2 +36 -12 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XSLTC.java 2001/04/17 18:51:53 1.1
+++ XSLTC.java 2001/04/27 20:06:12 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.1 2001/04/17 18:51:53 sboag Exp $
+ * @(#)$Id: XSLTC.java,v 1.2 2001/04/27 20:06:12 curcuru Exp $
*
* The Apache Software License, Version 1.1
*
@@ -371,7 +371,7 @@
if (debug()) {
_parser.errorsFound(); // print stack
}
- System.exit(1);
+ doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
}
/**
@@ -384,7 +384,7 @@
if (debug()) {
_parser.errorsFound(); // print stack
}
- System.exit(1);
+ doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
}
/**
@@ -398,7 +398,7 @@
if (debug()) {
_parser.errorsFound(); // print stack
}
- System.exit(1);
+ doSystemExit(1); throw new RuntimeException("System.exit(1) here!");
}
public int nextVariableSerial() {
@@ -517,13 +517,24 @@
setClassName(className);
return compile(stylesheetURL) ? outputToArrays() : null;
}
-
+
+ /**
+ * Command line runnability.
+ * o className
+ * d destDirectory
+ * p packageName
+ * j jarFileName
+ * u (isUriSpecified)
+ * x (isDebugSpecified)
+ * h printUsage()
+ * s (don't allow System.exit)
+ */
public static void main(String[] args) {
try {
- final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxh");
+ final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhs");
if (args.length < 1) {
printUsage();
- System.exit(1);
+ doSystemExit(1); return;
}
boolean isUriSpecified = false;
boolean isDebugSpecified = false;
@@ -554,6 +565,9 @@
case 'x':
isDebugSpecified = true;
break;
+ case 's':
+ allowSystemExit = false;
+ break;
case 'h':
printUsage();
break;
@@ -570,7 +584,7 @@
if (!dir.isDirectory() || (className != null && nStyleSheets > 1)) {
printUsage();
- System.exit(1);
+ doSystemExit(1); return;
}
dir = null;
@@ -610,20 +624,29 @@
}
else {
Util.println("compilation failed");
- System.exit(1);
+ doSystemExit(1); return;
}
}
catch (GetOptsException ex) {
System.err.println(ex);
printUsage();
- System.exit(1);
+ doSystemExit(1); return;
}
catch (Exception e) {
e.printStackTrace();
- System.exit(1);
+ doSystemExit(1); return;
}
}
+ /** If we should call System.exit or not */
+ protected static boolean allowSystemExit = true;
+
+ /** Worker method to call System.exit or not */
+ protected static void doSystemExit(int retVal) {
+ if (allowSystemExit)
+ System.exit(retVal);
+ }
+
private final static String USAGE_STRING =
"Usage:\n" +
" xsltc [-o <output>] [-d <directory>] [-j <jarfile>]\n" +
@@ -634,7 +657,8 @@
" <jarfile> is the name of jar file, do not specify \n" +
" the .jar extension. Example: -j MyJar \n"+
" Note: the -o option should not be used when processing\n"+
- " multiple stylesheets.";
+ " multiple stylesheets. \n"+
+ " also: [-x] (debug), [-s] (don't allow System.exit)";
public static void printUsage() {
System.err.println(USAGE_STRING);
1.2 +31 -11 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/DefaultRun.java
Index: DefaultRun.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/DefaultRun.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultRun.java 2001/04/17 18:52:43 1.1
+++ DefaultRun.java 2001/04/27 20:06:15 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DefaultRun.java,v 1.1 2001/04/17 18:52:43 sboag Exp $
+ * @(#)$Id: DefaultRun.java,v 1.2 2001/04/27 20:06:15 curcuru Exp $
*
* The Apache Software License, Version 1.1
*
@@ -83,7 +83,7 @@
import org.apache.xalan.xsltc.dom.Axis;
import org.apache.xalan.xsltc.dom.DTDMonitor;
-final class DefaultRun {
+public final class DefaultRun {
private TransletOutputHandler _handler;
@@ -182,7 +182,7 @@
System.err.println(e.toString());
e.printStackTrace();
}
- System.exit(1);
+ doSystemExit(1); return;
}
catch (RuntimeException e) {
System.err.println("\nRuntime Error: " + e.getMessage());
@@ -190,29 +190,29 @@
System.err.println(e.toString());
e.printStackTrace();
}
- System.exit(1);
+ doSystemExit(1); return;
}
catch (FileNotFoundException e) {
System.err.println("Error: File or URI '"+_fileName+"' not found.");
- System.exit(1);
+ doSystemExit(1); return;
}
catch (MalformedURLException e) {
System.err.println("Error: Invalid URI '"+_fileName+"'.");
- System.exit(1);
+ doSystemExit(1); return;
}
catch (ClassNotFoundException e) {
System.err.println("Error: Cannot find class '"+_className+"'.");
- System.exit(1);
+ doSystemExit(1); return;
}
catch (UnknownHostException e) {
System.err.println("Error: Can't resolve URI specification '"+
_fileName+"'.");
- System.exit(1);
+ doSystemExit(1); return;
}
catch (Exception e) {
e.printStackTrace();
System.err.println("Error: internal error.");
- System.exit(1);
+ doSystemExit(1); return;
}
}
@@ -228,9 +228,26 @@
public static void printUsage() {
System.err.println(USAGE_STRING);
- System.exit(1);
+ doSystemExit(1); throw new RuntimeException("System.exit(1) would be called");
}
+ /** If we should call System.exit or not */
+ protected static boolean allowSystemExit = true;
+
+ /** Worker method to call System.exit or not */
+ protected static void doSystemExit(int retVal) {
+ if (allowSystemExit)
+ System.exit(retVal);
+ }
+
+ /**
+ * Command line runnability.
+ * j jarFileName
+ * u (isUriSpecified)
+ * x (isDebugSpecified)
+ * h printUsage()
+ * s (don't allow System.exit)
+ */
public static void main(String[] args) {
try {
if (args.length > 0) {
@@ -247,6 +264,9 @@
else if (args[i].equals("-x")) {
debug = true;
}
+ else if (args[i].equals("-s")) {
+ allowSystemExit = false;
+ }
else if (args[i].equals("-j")) {
isJarFileSpecified = true;
jarFile = args[++i];
@@ -285,7 +305,7 @@
if (i == args.length) {
handler.setParameters(params);
handler.doTransform();
- System.exit(0);
+ doSystemExit(0); return;
}
}
printUsage();
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org