Exemple #1
0
  /**
   * Loads the specified library, if the library is already loaded it will not be loaded again.
   *
   * @param tcLibraryName the name of the library to load
   * @return true if the library was loaded after this call
   * @throws com.icatalyst.karyon.exceptions.LibraryNotFoundException if the library specified can
   *     not be found
   */
  public static boolean loadLibrary(String tcLibraryName) throws LibraryNotFoundException {
    Utilities.checkParameterNotNull("tcLibraryName", tcLibraryName);

    if (!isLibraryLoaded(tcLibraryName)) {
      // Attempt to load locally
      // TODO: Make the library directory configurable with the application configuration
      File loLibrary =
          new File(
              "."
                  + Environment.FILESEPARATOR()
                  + "lib"
                  + Environment.FILESEPARATOR()
                  + tcLibraryName.replaceFirst("^(?:lib)?(.+)$", "lib$1")
                  + "."
                  + OS.getOS().getSharedLibraryExtension());
      if (loLibrary.exists()) {
        try {
          System.load(loLibrary.getAbsolutePath());
          g_oLibraries = null;
          getLoadedLibraries();
          return true;
        } catch (SecurityException | UnsatisfiedLinkError | NullPointerException ex) {
          // Could not load the library locally, so attempt a system load
        }
      }
      try {
        System.loadLibrary(tcLibraryName);
        g_oLibraries = null;
        getLoadedLibraries();
        return true;
      } catch (SecurityException | UnsatisfiedLinkError | NullPointerException ex) {
        // Still could not load the library so throw the error
        throw new LibraryNotFoundException(tcLibraryName, ex);
      }
    }
    return false;
  }
Exemple #2
0
 /**
  * Checks if the library specified is actually loaded. This is a case insensitive check
  *
  * @param tcLibrary the library to check.
  * @return true if the library is loaded, false otherwise
  */
 public static boolean isLibraryLoaded(String tcLibrary) {
   Utilities.checkParameterNotNull("tcLibraryName", tcLibrary);
   return g_oLibraries != null
       && g_oLibraries.contains(tcLibrary.replaceFirst(m_cLibRegex, "$1").toLowerCase());
 }