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

Mon, 26 Mar 2012 14:01:40 +0100

author
coffeys
date
Mon, 26 Mar 2012 14:01:40 +0100
changeset 370
5222b7d658d4
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7143851: Improve IIOP stub and tie generation in RMIC
7149048: Changes to corba rmic stubGenerator class are not used during jdk build process
Reviewed-by: mschoene, robm

     1 /*
     2  * Copyright (c) 1999, 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  */
    26 /*
    27  * Licensed Materials - Property of IBM
    28  * RMI-IIOP v1.0
    29  * Copyright IBM Corp. 1998 1999  All Rights Reserved
    30  *
    31  */
    33 package sun.rmi.rmic.iiop;
    35 import java.io.File;
    36 import sun.tools.java.Identifier;
    38 import com.sun.corba.se.impl.util.PackagePrefixChecker;
    40 /**
    41  * Util provides static utility methods used by other rmic classes.
    42  * @author Bryan Atsatt
    43  */
    45 public final class Util implements sun.rmi.rmic.Constants {
    48     public static String packagePrefix(){ return PackagePrefixChecker.packagePrefix();}
    51     /**
    52      * Return the directory that should be used for output for a given
    53      * class.
    54      * @param theClass The fully qualified name of the class.
    55      * @param rootDir The directory to use as the root of the
    56      * package heirarchy.  May be null, in which case the current
    57      * working directory is used as the root.
    58      */
    59     private static File getOutputDirectoryFor(Identifier theClass,
    60                                              File rootDir,
    61                                              BatchEnvironment env,
    62                                              boolean idl ) {
    63         File outputDir = null;
    64         String className = theClass.getFlatName().toString().replace('.', SIGC_INNERCLASS);
    65         String qualifiedClassName = className;
    66         String packagePath = null;
    67         String packageName = theClass.getQualifier().toString();
    68         //Shift package names for stubs generated for interfaces.
    69         /*if(type.isInterface())*/
    70         packageName = correctPackageName(packageName, idl, env.getStandardPackage());
    71         //Done.
    72         if (packageName.length() > 0) {
    73             qualifiedClassName = packageName + "." + className;
    74             packagePath = packageName.replace('.', File.separatorChar);
    75         }
    77         // Do we have a root directory?
    79         if (rootDir != null) {
    81             // Yes, do we have a package name?
    83             if (packagePath != null) {
    85                 // Yes, so use it as the root. Open the directory...
    87                 outputDir = new File(rootDir, packagePath);
    89                 // Make sure the directory exists...
    91                 ensureDirectory(outputDir,env);
    93             } else {
    95                 // Default package, so use root as output dir...
    97                 outputDir = rootDir;
    98             }
    99         } else {
   101             // No root directory. Get the current working directory...
   103             String workingDirPath = System.getProperty("user.dir");
   104             File workingDir = new File(workingDirPath);
   106             // Do we have a package name?
   108             if (packagePath == null) {
   110                 // No, so use working directory...
   112                 outputDir = workingDir;
   114             } else {
   116                 // Yes, so use working directory as the root...
   118                 outputDir = new File(workingDir, packagePath);
   120                 // Make sure the directory exists...
   122                 ensureDirectory(outputDir,env);
   123             }
   124         }
   126         // Finally, return the directory...
   128         return outputDir;
   129     }
   131     public static File getOutputDirectoryForIDL(Identifier theClass,
   132                                              File rootDir,
   133                                              BatchEnvironment env) {
   134         return getOutputDirectoryFor(theClass, rootDir, env, true);
   135     }
   137     public static File getOutputDirectoryForStub(Identifier theClass,
   138                                              File rootDir,
   139                                              BatchEnvironment env) {
   140         return getOutputDirectoryFor(theClass, rootDir, env, false);
   141     }
   143     private static void ensureDirectory (File dir, BatchEnvironment env) {
   144         if (!dir.exists()) {
   145             dir.mkdirs();
   146             if (!dir.exists()) {
   147                 env.error(0,"rmic.cannot.create.dir",dir.getAbsolutePath());
   148                 throw new InternalError();
   149             }
   150         }
   151     }
   153     public static String correctPackageName(
   154             String p, boolean idl, boolean standardPackage){
   155         if (idl){
   156             return p;
   157         } else {
   158             if (standardPackage) {
   159                 return p;
   160             } else {
   161               return PackagePrefixChecker.correctPackageName(p);
   162             }
   163         }
   164     }
   166     public static boolean isOffendingPackage(String p){
   167         return PackagePrefixChecker.isOffendingPackage(p);
   168     }
   170     public static boolean hasOffendingPrefix(String p){
   171         return PackagePrefixChecker.hasOffendingPrefix(p);
   172     }
   174 }

mercurial