1. /*
  2. * @(#)LibraryManager.java 1.31 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.internal.io;
  16. import java.security.AccessController;
  17. //import sun.security.action.LoadLibraryAction;
  18. import java.security.PrivilegedAction;
  19. public class LibraryManager
  20. {
  21. private static boolean attempted = false;
  22. private static int majorVersion = 1;
  23. private static int minorVersion = 11; /*sun.4296963 ibm.11861*/
  24. native private static int getMajorVersion();
  25. native private static int getMinorVersion();
  26. public static boolean load()
  27. {
  28. // First check if the ioser library has already been loaded
  29. // by other code in this VM using System.load()
  30. // or System.loadLibrary().
  31. try {
  32. if ( getMajorVersion() == majorVersion
  33. && getMinorVersion() == minorVersion ) {
  34. attempted = true;
  35. return true ;
  36. }
  37. } catch ( java.lang.UnsatisfiedLinkError ule ) {
  38. }
  39. // Now try to load the ioser library
  40. try{
  41. String libName = "ioser12";
  42. try{
  43. AccessController.doPrivileged(new LoadLibraryAction(libName));
  44. } catch(java.lang.UnsatisfiedLinkError ule1) {
  45. if (!attempted){
  46. System.out.println( "ERROR! Shared library " + libName +
  47. " could not be found.");
  48. }
  49. throw ule1;
  50. }
  51. if ((!attempted) &&
  52. ((getMajorVersion() != majorVersion) ||
  53. (getMinorVersion() != minorVersion))) {
  54. System.out.println( "WARNING : The " + libName +
  55. " library is not the correct version.");
  56. System.out.println(" Expected v" +
  57. majorVersion + "." + minorVersion +
  58. " but loaded v" +
  59. getMajorVersion() + "." + getMinorVersion() + "\n");
  60. System.out.println(
  61. " *** YOU ARE ADVISED TO USE EXPECTED VERSION ***");
  62. }
  63. attempted = true;
  64. return true;
  65. } catch(Error e){
  66. attempted = true;
  67. return false;
  68. }
  69. }
  70. private static native boolean setEnableOverride(Class targetClass, Object instance);
  71. }
  72. // For some reason it doesn't work with the public class
  73. // sun.security.action.LoadLibraryAction
  74. class LoadLibraryAction implements PrivilegedAction {
  75. private String libname;
  76. public LoadLibraryAction (String libname) {
  77. this.libname = libname;
  78. }
  79. public Object run() {
  80. System.loadLibrary(libname);
  81. return null;
  82. }
  83. }