aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: /* aoqi@0: * Licensed Materials - Property of IBM aoqi@0: * RMI-IIOP v1.0 aoqi@0: * Copyright IBM Corp. 1998 1999 All Rights Reserved aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: package sun.rmi.rmic.iiop; aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.io.IOException; aoqi@0: import java.io.OutputStreamWriter; aoqi@0: import sun.tools.java.CompilerError; aoqi@0: import sun.tools.java.ClassDefinition; aoqi@0: import sun.rmi.rmic.IndentingWriter; aoqi@0: import sun.rmi.rmic.Main; aoqi@0: aoqi@0: /** aoqi@0: * An IDL generator for rmic. aoqi@0: * aoqi@0: * @author Bryan Atsatt aoqi@0: */ aoqi@0: public class PrintGenerator implements sun.rmi.rmic.Generator, aoqi@0: sun.rmi.rmic.iiop.Constants { aoqi@0: aoqi@0: private static final int JAVA = 0; aoqi@0: private static final int IDL = 1; aoqi@0: private static final int BOTH = 2; aoqi@0: aoqi@0: private int whatToPrint; // Initialized in parseArgs. aoqi@0: private boolean global = false; aoqi@0: private boolean qualified = false; aoqi@0: private boolean trace = false; aoqi@0: private boolean valueMethods = false; aoqi@0: aoqi@0: private IndentingWriter out; aoqi@0: aoqi@0: /** aoqi@0: * Default constructor for Main to use. aoqi@0: */ aoqi@0: public PrintGenerator() { aoqi@0: OutputStreamWriter writer = new OutputStreamWriter(System.out); aoqi@0: out = new IndentingWriter (writer); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Examine and consume command line arguments. aoqi@0: * @param argv The command line arguments. Ignore null aoqi@0: * @param error Report any errors using the main.error() methods. aoqi@0: * @return true if no errors, false otherwise. aoqi@0: */ aoqi@0: public boolean parseArgs(String argv[], Main main) { aoqi@0: for (int i = 0; i < argv.length; i++) { aoqi@0: if (argv[i] != null) { aoqi@0: String arg = argv[i].toLowerCase(); aoqi@0: if (arg.equals("-xprint")) { aoqi@0: whatToPrint = JAVA; aoqi@0: argv[i] = null; aoqi@0: if (i+1 < argv.length) { aoqi@0: if (argv[i+1].equalsIgnoreCase("idl")) { aoqi@0: argv[++i] = null; aoqi@0: whatToPrint = IDL; aoqi@0: } else if (argv[i+1].equalsIgnoreCase("both")) { aoqi@0: argv[++i] = null; aoqi@0: whatToPrint = BOTH; aoqi@0: } aoqi@0: } aoqi@0: } else if (arg.equals("-xglobal")) { aoqi@0: global = true; aoqi@0: argv[i] = null; aoqi@0: } else if (arg.equals("-xqualified")) { aoqi@0: qualified = true; aoqi@0: argv[i] = null; aoqi@0: } else if (arg.equals("-xtrace")) { aoqi@0: trace = true; aoqi@0: argv[i] = null; aoqi@0: } else if (arg.equals("-xvaluemethods")) { aoqi@0: valueMethods = true; aoqi@0: argv[i] = null; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Generate output. Any source files created which need compilation should aoqi@0: * be added to the compiler environment using the addGeneratedFile(File) aoqi@0: * method. aoqi@0: * aoqi@0: * @param env The compiler environment aoqi@0: * @param cdef The definition for the implementation class or interface from aoqi@0: * which to generate output aoqi@0: * @param destDir The directory for the root of the package hierarchy aoqi@0: * for generated files. May be null. aoqi@0: */ aoqi@0: public void generate(sun.rmi.rmic.BatchEnvironment env, ClassDefinition cdef, File destDir) { aoqi@0: aoqi@0: BatchEnvironment ourEnv = (BatchEnvironment) env; aoqi@0: ContextStack stack = new ContextStack(ourEnv); aoqi@0: stack.setTrace(trace); aoqi@0: aoqi@0: if (valueMethods) { aoqi@0: ourEnv.setParseNonConforming(true); aoqi@0: } aoqi@0: aoqi@0: // Get our top level type... aoqi@0: aoqi@0: CompoundType topType = CompoundType.forCompound(cdef,stack); aoqi@0: aoqi@0: if (topType != null) { aoqi@0: aoqi@0: try { aoqi@0: aoqi@0: // Collect up all the compound types... aoqi@0: aoqi@0: Type[] theTypes = topType.collectMatching(TM_COMPOUND); aoqi@0: aoqi@0: for (int i = 0; i < theTypes.length; i++) { aoqi@0: aoqi@0: out.pln("\n-----------------------------------------------------------\n"); aoqi@0: aoqi@0: Type theType = theTypes[i]; aoqi@0: aoqi@0: switch (whatToPrint) { aoqi@0: case JAVA: theType.println(out,qualified,false,false); aoqi@0: break; aoqi@0: aoqi@0: case IDL: theType.println(out,qualified,true,global); aoqi@0: break; aoqi@0: aoqi@0: case BOTH: theType.println(out,qualified,false,false); aoqi@0: theType.println(out,qualified,true,global); aoqi@0: break; aoqi@0: aoqi@0: default: throw new CompilerError("Unknown type!"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: out.flush(); aoqi@0: aoqi@0: } catch (IOException e) { aoqi@0: throw new CompilerError("PrintGenerator caught " + e); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }