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