Mon, 26 Mar 2012 14:01:40 +0100
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
duke@1 | 1 | /* |
ohair@158 | 2 | * Copyright (c) 2000, 2004, 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 | package sun.rmi.rmic.iiop; |
duke@1 | 26 | |
duke@1 | 27 | import java.io.*; |
duke@1 | 28 | import sun.tools.java.ClassPath ; |
duke@1 | 29 | import sun.tools.java.ClassFile ; |
duke@1 | 30 | |
duke@1 | 31 | /** |
duke@1 | 32 | * A ClassLoader that will ultimately use a given sun.tools.java.ClassPath to |
duke@1 | 33 | * find the desired file. This works for any JAR files specified in the given |
duke@1 | 34 | * ClassPath as well -- reusing all of that wonderful sun.tools.java code. |
duke@1 | 35 | * |
duke@1 | 36 | *@author Everett Anderson |
duke@1 | 37 | */ |
duke@1 | 38 | public class ClassPathLoader extends ClassLoader |
duke@1 | 39 | { |
duke@1 | 40 | private ClassPath classPath; |
duke@1 | 41 | |
duke@1 | 42 | public ClassPathLoader(ClassPath classPath) { |
duke@1 | 43 | this.classPath = classPath; |
duke@1 | 44 | } |
duke@1 | 45 | |
duke@1 | 46 | // Called by the super class |
duke@1 | 47 | protected Class findClass(String name) throws ClassNotFoundException |
duke@1 | 48 | { |
duke@1 | 49 | byte[] b = loadClassData(name); |
duke@1 | 50 | return defineClass(name, b, 0, b.length); |
duke@1 | 51 | } |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * Load the class with the given fully qualified name from the ClassPath. |
duke@1 | 55 | */ |
duke@1 | 56 | private byte[] loadClassData(String className) |
duke@1 | 57 | throws ClassNotFoundException |
duke@1 | 58 | { |
duke@1 | 59 | // Build the file name and subdirectory from the |
duke@1 | 60 | // class name |
duke@1 | 61 | String filename = className.replace('.', File.separatorChar) |
duke@1 | 62 | + ".class"; |
duke@1 | 63 | |
duke@1 | 64 | // Have ClassPath find the file for us, and wrap it in a |
duke@1 | 65 | // ClassFile. Note: This is where it looks inside jar files that |
duke@1 | 66 | // are specified in the path. |
duke@1 | 67 | ClassFile classFile = classPath.getFile(filename); |
duke@1 | 68 | |
duke@1 | 69 | if (classFile != null) { |
duke@1 | 70 | |
duke@1 | 71 | // Provide the most specific reason for failure in addition |
duke@1 | 72 | // to ClassNotFound |
duke@1 | 73 | Exception reportedError = null; |
duke@1 | 74 | byte data[] = null; |
duke@1 | 75 | |
duke@1 | 76 | try { |
duke@1 | 77 | // ClassFile is beautiful because it shields us from |
duke@1 | 78 | // knowing if it's a separate file or an entry in a |
duke@1 | 79 | // jar file. |
duke@1 | 80 | DataInputStream input |
duke@1 | 81 | = new DataInputStream(classFile.getInputStream()); |
duke@1 | 82 | |
duke@1 | 83 | // Can't rely on input available() since it will be |
duke@1 | 84 | // something unusual if it's a jar file! May need |
duke@1 | 85 | // to worry about a possible problem if someone |
duke@1 | 86 | // makes a jar file entry with a size greater than |
duke@1 | 87 | // max int. |
duke@1 | 88 | data = new byte[(int)classFile.length()]; |
duke@1 | 89 | |
duke@1 | 90 | try { |
duke@1 | 91 | input.readFully(data); |
duke@1 | 92 | } catch (IOException ex) { |
duke@1 | 93 | // Something actually went wrong reading the file. This |
duke@1 | 94 | // is a real error so save it to report it. |
duke@1 | 95 | data = null; |
duke@1 | 96 | reportedError = ex; |
duke@1 | 97 | } finally { |
duke@1 | 98 | // Just don't care if there's an exception on close! |
duke@1 | 99 | // I hate that close can throw an IOException! |
duke@1 | 100 | try { input.close(); } catch (IOException ex) {} |
duke@1 | 101 | } |
duke@1 | 102 | } catch (IOException ex) { |
duke@1 | 103 | // Couldn't get the input stream for the file. This is |
duke@1 | 104 | // probably also a real error. |
duke@1 | 105 | reportedError = ex; |
duke@1 | 106 | } |
duke@1 | 107 | |
duke@1 | 108 | if (data == null) |
duke@1 | 109 | throw new ClassNotFoundException(className, reportedError); |
duke@1 | 110 | |
duke@1 | 111 | return data; |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | // Couldn't find the file in the class path. |
duke@1 | 115 | throw new ClassNotFoundException(className); |
duke@1 | 116 | } |
duke@1 | 117 | } |