[Arakhnę-Dev] [139] Add a flag that permits to enable/disable the library loader.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 139
Author:   galland
Date:     2010-05-07 10:06:27 +0200 (Fri, 07 May 2010)
Log Message:
-----------
Add a flag that permits to enable/disable the library loader.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java	2010-04-30 12:42:59 UTC (rev 138)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java	2010-05-07 08:06:27 UTC (rev 139)
@@ -31,7 +31,12 @@
 
 /**
  * This class provides more generic means for loading
- * dynamical libraries. 
+ * dynamical libraries.
+ * <p>
+ * The library loader may be enabled or not.
+ * When library loader is enable, it is able to
+ * retreive and load native libraries. When it is
+ * disable, it ignore all the loading queries. 
  *
  * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
  * @version $Name$ $Revision$ $Date$
@@ -40,7 +45,38 @@
  */
 public class LibraryLoader {
 
-    /**
+	private static volatile boolean DISABLE = false;
+	
+	/** Replies if this library loader is enable.
+	 * <p>
+	 * The library loader is able to load native libraries
+	 * when it is enable. Otherwise it ignore all the loading
+	 * queries.
+	 *
+	 * @return <code>true</code> if the library loader is enable,
+	 * otherwise <code>false</code>
+	 * @since 5.0
+	 */
+	public static boolean isEnable() {
+		return !DISABLE;
+	}
+	
+	/** Replies if this library loader is enable.
+	 * <p>
+	 * The library loader is able to load native libraries
+	 * when it is enable. Otherwise it ignore all the loading
+	 * queries.
+	 *
+	 * @param enable is <code>true</code> to allow this loader
+	 * to retreive native libraries, or <code>false</code> to
+	 * ignore all the loading queries.
+	 * @since 5.0
+	 */
+	public static void setEnable(boolean enable) {
+		DISABLE = !enable;
+	}
+
+	/**
      * Loads a code file with the specified filename from the local file
      * system as a dynamic library. The filename
      * argument must be a complete path name.
@@ -61,6 +97,8 @@
      * @see        java.lang.System#load(java.lang.String)
      */
     public static void load(String filename) {
+    	// Silently ignore loading query
+    	if (DISABLE) return;
     	Runtime.getRuntime().load(filename);
     }
 
@@ -85,6 +123,8 @@
      * @see        java.lang.System#loadLibrary(java.lang.String)
      */
     public static void loadLibrary(String libname) {
+    	// Silently ignore loading query
+    	if (DISABLE) return;
     	Runtime.getRuntime().loadLibrary(libname);
     }
 
@@ -109,6 +149,8 @@
      * @see        java.lang.System#load(java.lang.String)
      */
     public static void load(File filename) {
+    	// Silently ignore loading query
+    	if (DISABLE) return;
     	Runtime.getRuntime().load(filename.getAbsolutePath());
     }
 
@@ -182,6 +224,9 @@
      * @see        java.lang.System#load(java.lang.String)
      */
     public static void load(URL filename) throws IOException {
+    	// Silently ignore loading query
+    	if (DISABLE) return;
+    	
         if (URISchemeType.FILE.isURL(filename)) {
         	try {
         		load(new File(filename.toURI()));


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/