Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/prims/jvmtiGen.java
32285 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import javax.xml.parsers.DocumentBuilder;25import javax.xml.parsers.DocumentBuilderFactory;26import javax.xml.parsers.FactoryConfigurationError;27import javax.xml.parsers.ParserConfigurationException;2829import org.xml.sax.SAXException;30import org.xml.sax.SAXParseException;31import org.w3c.dom.Document;32import org.w3c.dom.DOMException;33// For write operation34import javax.xml.transform.Transformer;35import javax.xml.transform.TransformerException;36import javax.xml.transform.TransformerFactory;37import javax.xml.transform.TransformerConfigurationException;38import javax.xml.transform.dom.DOMSource;39import javax.xml.transform.stream.StreamSource;40import javax.xml.transform.stream.StreamResult;4142import java.io.*;4344public class jvmtiGen45{46/**47* Write out usage and exit.48*/49private static void showUsage() {50System.err.println("usage:");51System.err.println(" java jvmtiGen " +52"-IN <input XML file name> " +53"-XSL <XSL file> " +54"-OUT <output file name> " +55"[-PARAM <name> <expression> ...]");56System.exit(0); // There is no returning from showUsage()57}5859// Global value so it can be ref'd by the tree-adapter60static Document document;6162public static void main (String argv [])63{64String inFileName=null;65String xslFileName=null;66String outFileName=null;67java.util.Vector<String> params=new java.util.Vector<String>();68for (int ii = 0; ii < argv.length; ii++) {69if (argv[ii].equals("-IN")) {70inFileName = argv[++ii];71} else if (argv[ii].equals("-XSL")) {72xslFileName = argv[++ii];73} else if (argv[ii].equals("-OUT")) {74outFileName = argv[++ii];75} else if (argv[ii].equals("-PARAM")) {76if (ii + 2 < argv.length) {77String name = argv[++ii];78params.addElement(name);79String expression = argv[++ii];80params.addElement(expression);81} else {82showUsage();83}84} else {85showUsage();86}87}88if (inFileName==null || xslFileName==null || outFileName==null){89showUsage();90}9192/*93* Due to JAXP breakage in some intermediate Tiger builds, the94* com.sun.org.apache..... parser may throw an exception:95* com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:96* org.apache.xalan.serialize.SerializerToText97*98* To work around the problem, this program uses the99* org.apache.xalan.... version if it is available. It is100* available in J2SE 1.4.x and early builds of 1.5 (Tiger).101* It was removed at the same time the thrown exception issue102* above was fixed, so if the class is not found we can proceed103* and use the default parser.104*/105final String parserProperty =106"javax.xml.transform.TransformerFactory";107final String workaroundParser =108"org.apache.xalan.processor.TransformerFactoryImpl";109110try {111java.lang.Class cls = java.lang.Class.forName(workaroundParser);112/*113* If we get here, we found the class. Use it.114*/115System.setProperty(parserProperty, workaroundParser);116System.out.println("Info: jvmtiGen using " + parserProperty +117" = " + workaroundParser);118} catch (ClassNotFoundException cnfex) {119/*120* We didn't find workaroundParser. Ignore the121* exception and proceed with default settings.122*/123}124125DocumentBuilderFactory factory =126DocumentBuilderFactory.newInstance();127128factory.setNamespaceAware(true);129factory.setValidating(true);130factory.setXIncludeAware(true);131132try {133File datafile = new File(inFileName);134File stylesheet = new File(xslFileName);135136DocumentBuilder builder = factory.newDocumentBuilder();137document = builder.parse(datafile);138139// Use a Transformer for output140TransformerFactory tFactory =141TransformerFactory.newInstance();142StreamSource stylesource = new StreamSource(stylesheet);143Transformer transformer = tFactory.newTransformer(stylesource);144for (int ii = 0; ii < params.size(); ii += 2){145transformer.setParameter((String) params.elementAt(ii),146(String) params.elementAt(ii + 1));147}148DOMSource source = new DOMSource(document);149150PrintStream ps = new PrintStream( new FileOutputStream(outFileName));151StreamResult result = new StreamResult(ps);152transformer.transform(source, result);153154} catch (TransformerConfigurationException tce) {155// Error generated by the parser156System.out.println ("\n** Transformer Factory error");157System.out.println(" " + tce.getMessage() );158159// Use the contained exception, if any160Throwable x = tce;161if (tce.getException() != null)162x = tce.getException();163x.printStackTrace();164165} catch (TransformerException te) {166// Error generated by the parser167System.out.println ("\n** Transformation error");168System.out.println(" " + te.getMessage() );169170// Use the contained exception, if any171Throwable x = te;172if (te.getException() != null)173x = te.getException();174x.printStackTrace();175176} catch (SAXException sxe) {177// Error generated by this application178// (or a parser-initialization error)179Exception x = sxe;180if (sxe.getException() != null)181x = sxe.getException();182x.printStackTrace();183184} catch (ParserConfigurationException pce) {185// Parser with specified options can't be built186pce.printStackTrace();187188} catch (IOException ioe) {189// I/O error190ioe.printStackTrace();191}192} // main193}194195196