usr/src/java/adr/org/opensolaris/os/adr/adrgen/RadADRGen.java
changeset 809 8a6fba4105d7
parent 808 2122a04679c0
child 810 9907d0f6f03a
--- a/usr/src/java/adr/org/opensolaris/os/adr/adrgen/RadADRGen.java	Wed Mar 14 04:47:00 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,276 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- */
-
-package org.opensolaris.os.adr.adrgen;
-
-import org.opensolaris.os.adr.*;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URL;
-import java.util.*;
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.validation.SchemaFactory;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-public class RadADRGen {
-    private static final String RADADRGEN_USAGE = "Usage: radadrgen [-N]" +
-	" [-c [-r [-m][-s]]] [-j dir [-i]] [-o {docbook | text | none}]" +
-	" [-d baseline.xml] spec.xml";
-
-    static class Option {
-	private char letter_;
-	private String arg_;
-
-	Option(char letter, String arg) {
-	    letter_ = letter;
-	    arg_ = arg;
-	}
-
-	char getLetter() {
-	    return letter_;
-	}
-
-	String getArg() {
-	    return arg_;
-	}
-    }
-
-    static int getOptions(String[] args, String argspec, List<Option> opts) {
-	Map<Character, Boolean> optspecs = new HashMap<Character, Boolean>();
-
-	/* Parse argspec */
-	int length = argspec.length();
-	for (int i = 0; i < length; i++) {
-	    char l = argspec.charAt(i);
-	    boolean hasargs = i + 1 < length && argspec.charAt(i + 1) == ':';
-	    if (hasargs)
-		i++;
-	    optspecs.put(l, hasargs);
-	}
-
-	/* Parse args */
-	boolean inopt = false;
-	char pending = '\0';
-	int i;
-	for (i = 0; i < args.length; i++) {
-	    if (inopt) {
-		opts.add(new Option(pending, args[i]));
-		inopt = false;
-		continue;
-	    }
-
-	    if (args[i].charAt(0) != '-')
-		break;
-
-	    for (int j = 1; j < args[i].length(); j++) {
-		char l = args[i].charAt(j);
-		if (!optspecs.containsKey(l)) {
-		    System.err.format("Invalid option \"%c\"\n", l);
-		    System.exit(2);
-		}
-
-		if (!optspecs.get(l)) {
-		    opts.add(new Option(l, null));
-		    continue;
-		}
-
-		if (j + 1 < args[i].length()) {
-		    opts.add(new Option(l, args[i].substring(j + 1)));
-		    break;
-		}
-
-		inopt = true;
-		pending = l;
-	    }
-	}
-
-	if (inopt) {
-	    System.err.format("Option \"%c\" requires an argument\n", pending);
-	    System.exit(2);
-	}
-
-	return i;
-    }
-
-    /*
-     * -c cname -j jname -s sname
-     */
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String[] args) {
-	boolean generate_c = false;
-	boolean generate_server = false;
-	boolean generate_cstubs = false;
-	boolean generate_java = false;
-	boolean generate_jimpl = false;
-	boolean generate_diff = false;
-	boolean generate_common = false;
-	boolean check_nullable = true;
-	DocGenerator.Format doc_fmt = null;
-	String java_dir = "java";
-	String baseline = "";
-
-	List<Option> opts = new LinkedList<Option>();
-	int operands = getOptions(args, "Ncj:mrsid:o:", opts);
-	for (Option o : opts) {
-	    switch (o.getLetter()) {
-	    case 'N':
-		check_nullable = false;
-		break;
-	    case 'c':
-		generate_c = true;
-		break;
-	    case 'j':
-		generate_java = true;
-		java_dir = o.getArg();
-		break;
-	    case 'r':
-		generate_server = true;
-		break;
-	    case 's':
-		generate_cstubs = true;
-		break;
-	    case 'i':
-		generate_jimpl = true;
-		break;
-	    case 'd':
-		generate_diff = true;
-		baseline = o.getArg();
-		break;
-	    case 'm':
-		generate_common = true;
-		break;
-	    case 'o':
-		try {
-		    doc_fmt =
-			DocGenerator.Format.valueOf(o.getArg().toUpperCase());
-		} catch (IllegalArgumentException ie) {
-		    System.err.format("Invalid documentation format: %s\n",
-			o.getArg());
-		    System.err.println(RADADRGEN_USAGE);
-		    System.exit(2);
-		}
-		break;
-	    }
-	}
-
-	if (operands == args.length) {
-	    System.err.println(RADADRGEN_USAGE);
-	    System.exit(2);
-	}
-
-	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-	factory.setNamespaceAware(true);
-	try {
-	    URL schema = ADRGen.class.getResource("adr.xsd");
-	    if (schema == null) {
-		System.err.println("Unable to find schema");
-		System.exit(1);
-	    }
-	    SchemaFactory schemafactory = SchemaFactory.newInstance(
-		XMLConstants.W3C_XML_SCHEMA_NS_URI);
-	    /* Use SchemaResourceResolver to find included/imported schemas */
-	    schemafactory.setResourceResolver(new SchemaResourceResolver());
-
-	    factory.setSchema(schemafactory.newSchema(schema));
-	} catch (SAXException e) {
-	    System.err.println("Error reading ADR schema: " + e.getMessage());
-	    System.exit(1);
-	}
-
-	DocumentBuilder builder;
-	/* Contrary to the javadoc, the default error handler just drives on */
-	ErrorHandler realHandler = new ErrorHandler() {
-	    public void warning(SAXParseException exception)
-		throws SAXException {
-		throw exception;
-	    }
-
-	    public void error(SAXParseException exception)
-		throws SAXException {
-		throw exception;
-	    }
-
-	    public void fatalError(SAXParseException exception)
-		throws SAXException {
-		throw exception;
-	    }
-	};
-
-	try {
-	    builder = factory.newDocumentBuilder();
-	    builder.setErrorHandler(realHandler);
-	} catch (ParserConfigurationException ex) {
-	    System.err.println("Initialization error");
-	    System.exit(1);
-	    return;
-	}
-
-	for (int i = operands; i < args.length; i++) {
-	    String file = args[i];
-	    try {
-		ADRGen p = new ADRGen(builder, new File(file), check_nullable);
-		if (generate_diff) {
-		    ADRGen pbaseline =
-			new ADRGen(builder, new File(baseline), check_nullable);
-		    APIDiff.diff(pbaseline.iface_.apis_, p.iface_.apis_);
-		}
-		if (generate_c)
-		    CGenerator.generate(p, generate_server, generate_cstubs,
-			generate_common);
-		if (generate_java)
-		    new JGenerator(p, java_dir).generate(false, generate_jimpl);
-		if (doc_fmt != null) {
-		    DocGenerator.generate(p, doc_fmt);
-		}
-	    } catch (ParseException e) {
-		System.err.format("Error parsing file %s: %s\n", file,
-		    e.getMessage());
-		System.exit(1);
-	    } catch (FileNotFoundException e) {
-		System.err.println(e.getMessage());
-		System.exit(1);
-	    } catch (TransformerException e) {
-		/* Display an error and continue other operations */
-		System.err.format("Error transforming file %s: %s\n", file,
-		    e.getMessage());
-		System.exit(1);
-	    }
-	    builder.reset();
-	    /*
-	     * Contrary to the javadoc, the post-reset error handler is *not*
-	     * functionally equal to the pre-reset error handler.
-	     */
-	    builder.setErrorHandler(realHandler);
-	}
-    }
-}