com.jogamp.common.jvm
Class JNILibLoaderBase

java.lang.Object
  extended by com.jogamp.common.jvm.JNILibLoaderBase

public class JNILibLoaderBase
extends Object


Nested Class Summary
static interface JNILibLoaderBase.LoaderAction
           
 
Field Summary
static boolean DEBUG
           
 
Constructor Summary
JNILibLoaderBase()
           
 
Method Summary
static void addLoaded(String libName)
           
static boolean addNativeJarLibs(Class<?>[] classesFromJavaJars, String singleJarMarker, String[] stripBasenameSuffixes)
          Loads and adds a JAR file's native library to the TempJarCache.
The native library JAR file's URL is derived as follows: [1] GLProfile.class -> [2] http://lala/gluegen-rt.jar -> [3] http://lala/gluegen-rt -> [4] http://lala/gluegen-rt-natives-'os.and.arch'.jar Where: [1] is one of classesFromJavaJars [2] is it's complete URL [3] is it's base URL [4] is the derived native JAR filename Examples:

JOCL:
static boolean addNativeJarLibs(Class<?> classFromJavaJar, String nativeJarBasename)
          Loads and adds a JAR file's native library to the TempJarCache.
The native library JAR file's URL is derived as follows: [1] GLProfile.class -> [2] http://lala/ -> [4] http://lala/'nativeJarBaseName'-'os.and.arch'.jar Where: [1] is the classFromJavaJar [2] is it's URL path [4] is the derived native JAR filename
static void disableLoading()
           
static void enableLoading()
           
static boolean isLoaded(String libName)
           
protected static boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl)
          Loads the library specified by libname, using the JNILibLoaderBase.LoaderAction set by setLoadingAction(LoaderAction).
The implementation should ignore, if the library has been loaded already.
protected static void loadLibrary(String libname, String[] preload, boolean preloadIgnoreError, ClassLoader cl)
          Loads the library specified by libname, using the JNILibLoaderBase.LoaderAction set by setLoadingAction(LoaderAction).
Optionally preloads the libraries specified by preload.
The implementation should ignore, if any library has been loaded already.
static void setLoadingAction(JNILibLoaderBase.LoaderAction action)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
Constructor Detail

JNILibLoaderBase

public JNILibLoaderBase()
Method Detail

isLoaded

public static boolean isLoaded(String libName)

addLoaded

public static void addLoaded(String libName)

disableLoading

public static void disableLoading()

enableLoading

public static void enableLoading()

setLoadingAction

public static void setLoadingAction(JNILibLoaderBase.LoaderAction action)

addNativeJarLibs

public static final boolean addNativeJarLibs(Class<?> classFromJavaJar,
                                             String nativeJarBasename)
Loads and adds a JAR file's native library to the TempJarCache.
The native library JAR file's URL is derived as follows: Where:

Parameters:
classFromJavaJar - GLProfile
nativeJarBasename - jogl-all
Returns:
true if the native JAR file loaded successful or were loaded already, false in case of an error

addNativeJarLibs

public static boolean addNativeJarLibs(Class<?>[] classesFromJavaJars,
                                       String singleJarMarker,
                                       String[] stripBasenameSuffixes)
Loads and adds a JAR file's native library to the TempJarCache.
The native library JAR file's URL is derived as follows: Where: Examples:

JOCL:
        // only: jocl.jar -> jocl-natives-'os.and.arch'.jar
        addNativeJarLibs(new Class[] { JOCLJNILibLoader.class }, null, null );
 
Newt Only:
       // either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar] -> jogl-all-natives-.jar
       // or:     nativewindow-core.jar                                   -> nativewindow-natives-.jar,
       //         newt-core.jar                                           -> newt-natives-.jar
       JNILibLoaderBase.addNativeJarLibs(new Class[] { NWJNILibLoader.class, NEWTJNILibLoader.class }, "-all", new String[] { "-noawt", "-mobile", "-core" } );
 
JOGL:
       final ClassLoader cl = GLProfile.class.getClassLoader();
       // either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar] -> jogl-all-natives-.jar
       // or:     nativewindow-core.jar                                   -> nativewindow-natives-.jar,
       //         jogl-core.jar                                           -> jogl-natives-.jar,
       //        (newt-core.jar                                           -> newt-natives-.jar)? (if available)
       final String newtFactoryClassName = "com.jogamp.newt.NewtFactory";
       final Class[] classesFromJavaJars = new Class[] { NWJNILibLoader.class, GLProfile.class, null };
       if( ReflectionUtil.isClassAvailable(newtFactoryClassName, cl) ) {
           classesFromJavaJars[2] = ReflectionUtil.getClass(newtFactoryClassName, false, cl);
       }
       JNILibLoaderBase.addNativeJarLibs(classesFromJavaJars, "-all", new String[] { "-noawt", "-mobile", "-core" } );
 

Parameters:
classesFromJavaJars - For each given Class, load the native library JAR.
singleJarMarker - Optional string marker like "-all" to identify the single 'all-in-one' JAR file after which processing of the class array shall stop.
stripBasenameSuffixes - Optional substrings to be stripped of the base URL
Returns:
true if either the 'all-in-one' native JAR or all native JARs loaded successful or were loaded already, false in case of an error

loadLibrary

protected static boolean loadLibrary(String libname,
                                     boolean ignoreError,
                                     ClassLoader cl)
Loads the library specified by libname, using the JNILibLoaderBase.LoaderAction set by setLoadingAction(LoaderAction).
The implementation should ignore, if the library has been loaded already.

Parameters:
libname - the library to load
ignoreError - if true, errors during loading the library should be ignored
cl - optional ClassLoader, used to locate the library
Returns:
true if library loaded successful

loadLibrary

protected static void loadLibrary(String libname,
                                  String[] preload,
                                  boolean preloadIgnoreError,
                                  ClassLoader cl)
Loads the library specified by libname, using the JNILibLoaderBase.LoaderAction set by setLoadingAction(LoaderAction).
Optionally preloads the libraries specified by preload.
The implementation should ignore, if any library has been loaded already.

Parameters:
libname - the library to load
preload - the libraries to load before loading the main library if not null
preloadIgnoreError - if true, errors during loading the preload-libraries should be ignored
cl - optional ClassLoader, used to locate the library