Top


定義場所(file name)

hotspot/src/share/vm/prims/jvmtiGen.java

名前(function name)

    public static void main (String argv [])
    {

本体部(body)

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

            String inFileName=null;
            String xslFileName=null;
            String outFileName=null;
            java.util.Vector<String> params=new java.util.Vector<String>();

  {- -------------------------------------------
  (1) コマンドラインオプションのパース
      ---------------------------------------- -}

            for (int ii = 0; ii < argv.length; ii++) {
                if (argv[ii].equals("-IN")) {
                    inFileName = argv[++ii];
                } else if (argv[ii].equals("-XSL")) {
                    xslFileName = argv[++ii];
                } else if (argv[ii].equals("-OUT")) {
                    outFileName = argv[++ii];
                } else if (argv[ii].equals("-PARAM")) {
                    if (ii + 2 < argv.length) {
                        String name = argv[++ii];
                        params.addElement(name);
                        String expression = argv[++ii];
                        params.addElement(expression);
                    } else {
                        showUsage();
                    }
                } else {
                    showUsage();
                }
            }
            if (inFileName==null || xslFileName==null || outFileName==null){
                showUsage();
            }

  {- -------------------------------------------
  (1) Tiger のいくつかのバージョンで JAXP にバグがあったので, 
      可能なら org.apache.xalan.processor.TransformerFactoryImpl を使用する.
      ---------------------------------------- -}

            /*
             * Due to JAXP breakage in some intermediate Tiger builds, the
             * com.sun.org.apache..... parser may throw an exception:
             *   com.sun.org.apache.xml.internal.utils.WrappedRuntimeException:
             *     org.apache.xalan.serialize.SerializerToText
             *
             * To work around the problem, this program uses the
             * org.apache.xalan....  version if it is available.  It is
             * available in J2SE 1.4.x and early builds of 1.5 (Tiger).
             * It was removed at the same time the thrown exception issue
             * above was fixed, so if the class is not found we can proceed
             * and use the default parser.
             */
            final String parserProperty =
                "javax.xml.transform.TransformerFactory";
            final String workaroundParser =
                "org.apache.xalan.processor.TransformerFactoryImpl";

            try {
                java.lang.Class cls = java.lang.Class.forName(workaroundParser);
                /*
                 * If we get here, we found the class.  Use it.
                 */
                System.setProperty(parserProperty, workaroundParser);
                System.out.println("Info: jvmtiGen using " + parserProperty +
                                   " = " + workaroundParser);

    {- -------------------------------------------
  (1.1) (org.apache.xalan.processor.TransformerFactoryImpl が見つからない場合は, デフォルトのままで実行を継続)
        ---------------------------------------- -}

            } catch (ClassNotFoundException cnfex) {
                /*
                 * We didn't find workaroundParser.  Ignore the
                 * exception and proceed with default settings.
                 */
            }

            DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();

            factory.setNamespaceAware(true);
            factory.setValidating(true);

  {- -------------------------------------------
  (1) 入力の XML ファイルと XSLT ファイル, および出力先のファイルを開き, 
      Transformer::transform() で, XSLT 処理を行って結果を出力させる.
      ---------------------------------------- -}

            try {
                File datafile   = new File(inFileName);
                File stylesheet = new File(xslFileName);

                DocumentBuilder builder = factory.newDocumentBuilder();
                document = builder.parse(datafile);

                // Use a Transformer for output
                TransformerFactory tFactory =
                    TransformerFactory.newInstance();
                StreamSource stylesource = new StreamSource(stylesheet);
                Transformer transformer = tFactory.newTransformer(stylesource);
                for (int ii = 0; ii < params.size(); ii += 2){
                    transformer.setParameter((String) params.elementAt(ii),
                                             (String) params.elementAt(ii + 1));
                }
                DOMSource source = new DOMSource(document);

                PrintStream ps = new PrintStream( new FileOutputStream(outFileName));
                StreamResult result = new StreamResult(ps);
                transformer.transform(source, result);

  {- -------------------------------------------
  (1) ファイルの処理や XSLT 処理で例外が起きた場合のエラー処理
      ---------------------------------------- -}

            } catch (TransformerConfigurationException tce) {
               // Error generated by the parser
               System.out.println ("\n** Transformer Factory error");
               System.out.println("   " + tce.getMessage() );

               // Use the contained exception, if any
               Throwable x = tce;
               if (tce.getException() != null)
                   x = tce.getException();
               x.printStackTrace();

            } catch (TransformerException te) {
               // Error generated by the parser
               System.out.println ("\n** Transformation error");
               System.out.println("   " + te.getMessage() );

               // Use the contained exception, if any
               Throwable x = te;
               if (te.getException() != null)
                   x = te.getException();
               x.printStackTrace();

             } catch (SAXException sxe) {
               // Error generated by this application
               // (or a parser-initialization error)
               Exception  x = sxe;
               if (sxe.getException() != null)
                   x = sxe.getException();
               x.printStackTrace();

            } catch (ParserConfigurationException pce) {
                // Parser with specified options can't be built
                pce.printStackTrace();

            } catch (IOException ioe) {
               // I/O error
               ioe.printStackTrace();
            }
        } // main

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.