src/share/classes/sun/rmi/rmic/iiop/PrintGenerator.java

Wed, 28 Mar 2012 02:50:50 -0700

author
mbankal
date
Wed, 28 Mar 2012 02:50:50 -0700
changeset 371
e324dfb90c9e
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7079902: Refine CORBA data models
Reviewed-by: coffeys

     1 /*
     2  * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 /*
    26  * Licensed Materials - Property of IBM
    27  * RMI-IIOP v1.0
    28  * Copyright IBM Corp. 1998 1999  All Rights Reserved
    29  *
    30  */
    32 package sun.rmi.rmic.iiop;
    34 import java.io.File;
    35 import java.io.IOException;
    36 import java.io.OutputStreamWriter;
    37 import sun.tools.java.CompilerError;
    38 import sun.tools.java.ClassDefinition;
    39 import sun.rmi.rmic.IndentingWriter;
    40 import sun.rmi.rmic.Main;
    42 /**
    43  * An IDL generator for rmic.
    44  *
    45  * @author      Bryan Atsatt
    46  */
    47 public class PrintGenerator implements sun.rmi.rmic.Generator,
    48                                        sun.rmi.rmic.iiop.Constants {
    50     private static final int JAVA = 0;
    51     private static final int IDL = 1;
    52     private static final int BOTH = 2;
    54     private int whatToPrint; // Initialized in parseArgs.
    55     private boolean global = false;
    56     private boolean qualified = false;
    57     private boolean trace = false;
    58     private boolean valueMethods = false;
    60     private IndentingWriter out;
    62     /**
    63      * Default constructor for Main to use.
    64      */
    65     public PrintGenerator() {
    66         OutputStreamWriter writer = new OutputStreamWriter(System.out);
    67         out = new IndentingWriter (writer);
    68     }
    70     /**
    71      * Examine and consume command line arguments.
    72      * @param argv The command line arguments. Ignore null
    73      * @param error Report any errors using the main.error() methods.
    74      * @return true if no errors, false otherwise.
    75      */
    76     public boolean parseArgs(String argv[], Main main) {
    77         for (int i = 0; i < argv.length; i++) {
    78             if (argv[i] != null) {
    79                 String arg = argv[i].toLowerCase();
    80                 if (arg.equals("-xprint")) {
    81                     whatToPrint = JAVA;
    82                     argv[i] = null;
    83                     if (i+1 < argv.length) {
    84                         if (argv[i+1].equalsIgnoreCase("idl")) {
    85                             argv[++i] = null;
    86                             whatToPrint = IDL;
    87                         } else if (argv[i+1].equalsIgnoreCase("both")) {
    88                             argv[++i] = null;
    89                             whatToPrint = BOTH;
    90                         }
    91                     }
    92                 } else if (arg.equals("-xglobal")) {
    93                     global = true;
    94                     argv[i] = null;
    95                 } else if (arg.equals("-xqualified")) {
    96                     qualified = true;
    97                     argv[i] = null;
    98                 } else if (arg.equals("-xtrace")) {
    99                     trace = true;
   100                     argv[i] = null;
   101                 } else if (arg.equals("-xvaluemethods")) {
   102                     valueMethods = true;
   103                     argv[i] = null;
   104                 }
   105             }
   106         }
   107         return true;
   108     }
   110     /**
   111      * Generate output. Any source files created which need compilation should
   112      * be added to the compiler environment using the addGeneratedFile(File)
   113      * method.
   114      *
   115      * @param env       The compiler environment
   116      * @param cdef      The definition for the implementation class or interface from
   117      *              which to generate output
   118      * @param destDir   The directory for the root of the package hierarchy
   119      *                          for generated files. May be null.
   120      */
   121     public void generate(sun.rmi.rmic.BatchEnvironment env, ClassDefinition cdef, File destDir) {
   123         BatchEnvironment ourEnv = (BatchEnvironment) env;
   124         ContextStack stack = new ContextStack(ourEnv);
   125         stack.setTrace(trace);
   127         if (valueMethods) {
   128             ourEnv.setParseNonConforming(true);
   129         }
   131         // Get our top level type...
   133         CompoundType topType = CompoundType.forCompound(cdef,stack);
   135         if (topType != null) {
   137             try {
   139                                 // Collect up all the compound types...
   141                 Type[] theTypes = topType.collectMatching(TM_COMPOUND);
   143                 for (int i = 0; i < theTypes.length; i++) {
   145                     out.pln("\n-----------------------------------------------------------\n");
   147                     Type theType = theTypes[i];
   149                     switch (whatToPrint) {
   150                     case JAVA:  theType.println(out,qualified,false,false);
   151                         break;
   153                     case IDL:   theType.println(out,qualified,true,global);
   154                         break;
   156                     case BOTH:  theType.println(out,qualified,false,false);
   157                         theType.println(out,qualified,true,global);
   158                         break;
   160                     default:    throw new CompilerError("Unknown type!");
   161                     }
   162                 }
   164                 out.flush();
   166             } catch (IOException e) {
   167                 throw new CompilerError("PrintGenerator caught " + e);
   168             }
   169         }
   170     }
   171 }

mercurial