[Arakhnę-Dev] [204] * Avoid to stop the JVM when the native functions from Operating System could not be loaded . |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
- To: dev@xxxxxxxxxxx
- Subject: [Arakhnę-Dev] [204] * Avoid to stop the JVM when the native functions from Operating System could not be loaded .
- From: subversion@xxxxxxxxxxxxx
- Date: Mon, 14 Feb 2011 18:09:54 +0100
Revision: 204
Author: galland
Date: 2011-02-14 18:09:54 +0100 (Mon, 14 Feb 2011)
Log Message:
-----------
* Avoid to stop the JVM when the native functions from Operating System could not be loaded.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
Added Paths:
-----------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java
trunk/arakhneVmutils/java/src/main/resources/
trunk/arakhneVmutils/java/src/main/resources/org/
trunk/arakhneVmutils/java/src/main/resources/org/arakhne/
trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/
trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem.properties
trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem_fr.properties
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java 2011-02-14 13:22:48 UTC (rev 203)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java 2011-02-14 17:09:54 UTC (rev 204)
@@ -1,7 +1,7 @@
/*
* $Id$
*
- * Copyright (C) 2004-2009 Stéphane GALLAND
+ * Copyright (C) 2004-2011 Stéphane GALLAND
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,8 +21,7 @@
package org.arakhne.vmutil;
-import java.io.IOError;
-import java.io.IOException;
+import java.util.ResourceBundle;
/**
* This is a list of supported operating system.
@@ -221,24 +220,55 @@
*
* @return the serial number associated to the current operating system.
*/
- public static native String getOSSerialNumber();
+ public static String getOSSerialNumber() {
+ if (nativeWrapper!=null)
+ return nativeWrapper.getOSSerialNumber();
+ return null;
+ }
/** Get the OS UUID.
*
* @return an unique identifier for the current operating system.
*/
- public static native String getOSUUID();
+ public static String getOSUUID() {
+ if (nativeWrapper!=null)
+ return nativeWrapper.getOSUUID();
+ return null;
+ }
+ private static final OperatingSystemNativeWrapper nativeWrapper;
+
static {
+ Throwable error = null;
try {
LibraryLoader.loadPlatformDependentLibrary(
"josuuid", //$NON-NLS-1$
System.getProperty("os.name").trim().toLowerCase(), //$NON-NLS-1$
"org/arakhne/vmutil"); //$NON-NLS-1$
}
- catch (IOException e) {
- throw new IOError(e);
+ catch (Throwable e) {
+ error = e;
}
+ if (error==null) {
+ nativeWrapper = new OperatingSystemNativeWrapper();
+ }
+ else {
+ nativeWrapper = null;
+
+ try {
+ ResourceBundle bundle = ResourceBundle.getBundle(OperatingSystem.class.getCanonicalName());
+ String errorMsg = bundle.getString("NATIVE_NOT_SUPPORTED"); //$NON-NLS-1$
+ if (errorMsg!=null && !"".equals(errorMsg)) { //$NON-NLS-1$
+ System.err.println(errorMsg);
+ }
+ else {
+ error.printStackTrace();
+ }
+ }
+ catch(Throwable e) {
+ error.printStackTrace();
+ }
+ }
}
-
+
}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java 2011-02-14 17:09:54 UTC (rev 204)
@@ -0,0 +1,57 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2009 Stéphane GALLAND
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+
+package org.arakhne.vmutil;
+
+/**
+ * Wrapper to the native functions.
+ * This class was introduced to avoid to kill the current
+ * JVM even if the native functions are unloadable.
+ * In this way, on operating system without the support
+ * for the native libs is still able to be run.
+ *
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 6.0
+ */
+class OperatingSystemNativeWrapper {
+
+ /**
+ */
+ public OperatingSystemNativeWrapper() {
+ //
+ }
+
+ /** Get the OS serial number.
+ *
+ * @return the serial number associated to the current operating system.
+ */
+ public native String getOSSerialNumber();
+
+ /** Get the OS UUID.
+ *
+ * @return an unique identifier for the current operating system.
+ */
+ public native String getOSUUID();
+
+}
Added: trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem.properties
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem.properties (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem.properties 2011-02-14 17:09:54 UTC (rev 204)
@@ -0,0 +1,20 @@
+# $Id$
+#
+# Copyright (C) 2011 Stéphane GALLAND
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# This program is free software; you can redistribute it and/or modify
+
+NATIVE_NOT_SUPPORTED = Your operating system is not supporting the native methods defined in OperatingSystem. They may replies null value.
Added: trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem_fr.properties
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem_fr.properties (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/org/arakhne/vmutil/OperatingSystem_fr.properties 2011-02-14 17:09:54 UTC (rev 204)
@@ -0,0 +1,20 @@
+# $Id$
+#
+# Copyright (C) 2011 Stéphane GALLAND
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# This program is free software; you can redistribute it and/or modify
+
+NATIVE_NOT_SUPPORTED = Votre syst\xE8me d'exploitation ne supporte pas les fonctions natives d\xE9finies dans OperatingSystem. Ces fonctions retourneront la valeur null.