src/share/classes/sun/rmi/rmic/iiop/Util.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

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

mercurial