|
|
9f2d24 |
diff -Naur txw2-20110809/compiler/src/main/java/com/sun/tools/txw2/Main.java txw2-20110809-work/compiler/src/main/java/com/sun/tools/txw2/Main.java
|
|
|
9f2d24 |
--- txw2-20110809/compiler/src/main/java/com/sun/tools/txw2/Main.java 2011-03-29 02:59:19.000000000 -0400
|
|
|
9f2d24 |
+++ txw2-20110809-work/compiler/src/main/java/com/sun/tools/txw2/Main.java 2012-01-19 13:06:40.049998255 -0500
|
|
|
9f2d24 |
@@ -43,10 +43,10 @@
|
|
|
9f2d24 |
import com.sun.codemodel.writer.FileCodeWriter;
|
|
|
9f2d24 |
import com.sun.codemodel.writer.SingleStreamCodeWriter;
|
|
|
9f2d24 |
import com.sun.tools.txw2.model.NodeSet;
|
|
|
9f2d24 |
+import org.kohsuke.args4j.Argument;
|
|
|
9f2d24 |
+import org.kohsuke.args4j.Option;
|
|
|
9f2d24 |
import org.kohsuke.args4j.CmdLineException;
|
|
|
9f2d24 |
import org.kohsuke.args4j.CmdLineParser;
|
|
|
9f2d24 |
-import org.kohsuke.args4j.opts.BooleanOption;
|
|
|
9f2d24 |
-import org.kohsuke.args4j.opts.StringOption;
|
|
|
9f2d24 |
import org.kohsuke.rngom.parse.IllegalSchemaException;
|
|
|
9f2d24 |
import org.kohsuke.rngom.parse.Parseable;
|
|
|
9f2d24 |
import org.kohsuke.rngom.parse.compact.CompactParseable;
|
|
|
9f2d24 |
@@ -60,6 +60,8 @@
|
|
|
9f2d24 |
import java.io.IOException;
|
|
|
9f2d24 |
import java.net.MalformedURLException;
|
|
|
9f2d24 |
import java.util.Properties;
|
|
|
9f2d24 |
+import java.util.List;
|
|
|
9f2d24 |
+import java.util.ArrayList;
|
|
|
9f2d24 |
|
|
|
9f2d24 |
/**
|
|
|
9f2d24 |
* Programatic entry point to the TXW compiler.
|
|
|
9f2d24 |
@@ -73,26 +75,39 @@
|
|
|
9f2d24 |
this.opts = opts;
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- public static void main(String[] args) {
|
|
|
9f2d24 |
- System.exit(run(args));
|
|
|
9f2d24 |
+ public static class Options {
|
|
|
9f2d24 |
+ @Argument
|
|
|
9f2d24 |
+ public List<String> arguments = new ArrayList<String>();
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-o")
|
|
|
9f2d24 |
+ public String output;
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-p")
|
|
|
9f2d24 |
+ public String pkg;
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-c")
|
|
|
9f2d24 |
+ public boolean compact;
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-x")
|
|
|
9f2d24 |
+ public boolean xml;
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-xsd")
|
|
|
9f2d24 |
+ public boolean xsd;
|
|
|
9f2d24 |
+
|
|
|
9f2d24 |
+ @Option(name="-h")
|
|
|
9f2d24 |
+ public boolean chain;
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- public static class Options {
|
|
|
9f2d24 |
- public StringOption output = new StringOption("-o");
|
|
|
9f2d24 |
- public StringOption pkg = new StringOption("-p");
|
|
|
9f2d24 |
- public BooleanOption compact = new BooleanOption("-c");
|
|
|
9f2d24 |
- public BooleanOption xml = new BooleanOption("-x");
|
|
|
9f2d24 |
- public BooleanOption xsd = new BooleanOption("-xsd");
|
|
|
9f2d24 |
- public BooleanOption chain = new BooleanOption("-h");
|
|
|
9f2d24 |
+ public static void main(String[] args) {
|
|
|
9f2d24 |
+ System.exit(run(args));
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
public static int run(String[] args) {
|
|
|
9f2d24 |
Options opts = new Options();
|
|
|
9f2d24 |
- CmdLineParser parser = new CmdLineParser();
|
|
|
9f2d24 |
- parser.addOptionClass(opts);
|
|
|
9f2d24 |
+ CmdLineParser parser = new CmdLineParser(opts);
|
|
|
9f2d24 |
|
|
|
9f2d24 |
try {
|
|
|
9f2d24 |
- parser.parse(args);
|
|
|
9f2d24 |
+ parser.parseArgument(args);
|
|
|
9f2d24 |
} catch (CmdLineException e) {
|
|
|
9f2d24 |
System.out.println(e.getMessage());
|
|
|
9f2d24 |
printUsage();
|
|
|
9f2d24 |
@@ -102,9 +117,9 @@
|
|
|
9f2d24 |
TxwOptions topts = new TxwOptions();
|
|
|
9f2d24 |
topts.errorListener = new ConsoleErrorReporter(System.out);
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.output.value!=null) {
|
|
|
9f2d24 |
+ if(opts.output != null) {
|
|
|
9f2d24 |
try {
|
|
|
9f2d24 |
- topts.codeWriter = new FileCodeWriter(new File(opts.output.value));
|
|
|
9f2d24 |
+ topts.codeWriter = new FileCodeWriter(new File(opts.output));
|
|
|
9f2d24 |
} catch( IOException e ) {
|
|
|
9f2d24 |
System.out.println(e.getMessage());
|
|
|
9f2d24 |
printUsage();
|
|
|
9f2d24 |
@@ -114,12 +129,12 @@
|
|
|
9f2d24 |
topts.codeWriter = new SingleStreamCodeWriter(System.out);
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.chain.isOn()) {
|
|
|
9f2d24 |
+ if(opts.chain) {
|
|
|
9f2d24 |
topts.chainMethod = true;
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.pkg.value!=null) {
|
|
|
9f2d24 |
- topts._package = topts.codeModel._package(opts.pkg.value);
|
|
|
9f2d24 |
+ if(opts.pkg != null) {
|
|
|
9f2d24 |
+ topts._package = topts.codeModel._package(opts.pkg);
|
|
|
9f2d24 |
} else {
|
|
|
9f2d24 |
topts._package = topts.codeModel.rootPackage();
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
@@ -146,21 +161,21 @@
|
|
|
9f2d24 |
* out of the specified schema file.
|
|
|
9f2d24 |
*/
|
|
|
9f2d24 |
private static SchemaBuilder makeSourceSchema(CmdLineParser parser, Options opts, ErrorHandler eh) throws MalformedURLException {
|
|
|
9f2d24 |
- File f = new File((String)parser.getArguments().get(0));
|
|
|
9f2d24 |
+ File f = new File(opts.arguments.get(0));
|
|
|
9f2d24 |
final InputSource in = new InputSource(f.toURL().toExternalForm());
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.xsd.isOff() && opts.xml.isOff() && opts.compact.isOff()) {
|
|
|
9f2d24 |
+ if(!opts.xsd && !opts.xml && !opts.compact) {
|
|
|
9f2d24 |
// auto detect
|
|
|
9f2d24 |
if(in.getSystemId().endsWith(".rnc"))
|
|
|
9f2d24 |
- opts.compact.value=true;
|
|
|
9f2d24 |
+ opts.compact = true;
|
|
|
9f2d24 |
else
|
|
|
9f2d24 |
if(in.getSystemId().endsWith(".rng"))
|
|
|
9f2d24 |
- opts.xml.value=true;
|
|
|
9f2d24 |
+ opts.xml = true;
|
|
|
9f2d24 |
else
|
|
|
9f2d24 |
- opts.xsd.value=true;
|
|
|
9f2d24 |
+ opts.xsd = true;
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.xsd.isOn())
|
|
|
9f2d24 |
+ if(opts.xsd)
|
|
|
9f2d24 |
return new XmlSchemaLoader(in);
|
|
|
9f2d24 |
|
|
|
9f2d24 |
final Parseable parseable = makeRELAXNGSource(opts, in, eh, f);
|
|
|
9f2d24 |
@@ -169,10 +184,10 @@
|
|
|
9f2d24 |
}
|
|
|
9f2d24 |
|
|
|
9f2d24 |
private static Parseable makeRELAXNGSource(Options opts, final InputSource in, ErrorHandler eh, File f) {
|
|
|
9f2d24 |
- if(opts.compact.isOn())
|
|
|
9f2d24 |
+ if(opts.compact)
|
|
|
9f2d24 |
return new CompactParseable(in,eh);
|
|
|
9f2d24 |
|
|
|
9f2d24 |
- if(opts.xml.isOn())
|
|
|
9f2d24 |
+ if(opts.xml)
|
|
|
9f2d24 |
return new SAXParseable(in,eh);
|
|
|
9f2d24 |
|
|
|
9f2d24 |
// otherwise sniff from the file extension
|