[Arakhnę-Dev] [323] * Add support for Android operating system.

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


Revision: 323
Author:   galland
Date:     2012-01-30 20:17:54 +0100 (Mon, 30 Jan 2012)
Log Message:
-----------
* Add support for Android operating system.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/pom.xml
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
    trunk/arakhneVmutils/native/josuuid/mingw32/pom.xml
    trunk/arakhneVmutils/native/josuuid/mingw64/pom.xml
    trunk/arakhneVmutils/native/josuuid/pom.xml
    trunk/arakhneVmutils/native/pom.xml
    trunk/arakhneVmutils/pom.xml

Added Paths:
-----------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java

Modified: trunk/arakhneVmutils/java/pom.xml
===================================================================
--- trunk/arakhneVmutils/java/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/java/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -16,7 +16,7 @@
 	<groupId>org.arakhne.afc</groupId>
 	<artifactId>arakhneVmutils-java</artifactId>
 	<packaging>jar</packaging>
-	<version>6.4-SNAPSHOT</version>
+	<version>7.0-SNAPSHOT</version>
 	<name>VM Utilities</name>
 	<url>http://www.arakhne.org/arakhneVmutils/</url>
 

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -0,0 +1,280 @@
+/* 
+  * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stephane GALLANDibrary 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;
+
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Method;
+
+/**
+ * This class stores several information given by
+ * the Android operating systems.
+ * The stored informations are used by the arakhneVmutil
+ * tools to proceed several tasks, such as {@link OperatingSystem}. 
+ *
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 7.0
+ */
+public class Android {
+
+	private static SoftReference<Object> context = null;
+	private static WeakReference<Object> contextResolver = null;
+	private static WeakReference<ClassLoader> contextClassLoader = null;
+	
+	/**
+	 */
+	private Android() {
+		//
+	}
+	
+	/** Replies the class {@code Context} from Android.
+	 * 
+	 * @return the class {@code Context} from Android.
+	 * @throws AndroidException when the class cannot be found.
+	 */
+	public static Class<?> getContextClass() throws AndroidException {
+		try {
+			ClassLoader loader = ClassLoaderFinder.findClassLoader();
+			return Class.forName("android.content.Context", true, loader); //$NON-NLS-1$
+		}
+		catch(Throwable e) {
+			throw new AndroidException(e);
+		}
+	}
+	
+	/** Replies the class {@code ContextResolver} from Android.
+	 * 
+	 * @return the class {@code ContextResolver} from Android.
+	 * @throws AndroidException when the class cannot be found.
+	 */
+	public static Class<?> getContextResolverClass() throws AndroidException {
+		try {
+			ClassLoader loader = ClassLoaderFinder.findClassLoader();
+			return Class.forName("android.content.ContentResolver", true, loader); //$NON-NLS-1$
+		}
+		catch(Throwable e) {
+			throw new AndroidException(e);
+		}
+	}
+	
+	private static Class<?> getInnerClass(String enclosingClassname, String innerClassname) throws AndroidException {
+		ClassLoader loader = ClassLoaderFinder.findClassLoader();
+		Throwable ex = null;
+		try {
+			StringBuffer b = new StringBuffer(enclosingClassname);
+			b.append("$"); //$NON-NLS-1$
+			b.append(innerClassname);
+			Class<?> innerClass = Class.forName(b.toString(), true, loader);
+			return innerClass;
+		}
+		catch(Throwable e) {
+			ex = e;
+		}
+		try {
+			Class<?> enclosingClass = Class.forName(enclosingClassname, true, loader);
+			for(Class<?> innerClass : enclosingClass.getClasses()) {
+				if (innerClassname.equals(innerClass.getName())) {
+					return innerClass;
+				}
+			}
+		}
+		catch(Throwable _) {
+			//
+		}
+		throw new AndroidException(ex);
+	}
+
+	/** Replies the class {@code Secure} from Android.
+	 * 
+	 * @return the class {@code Secure} from Android.
+	 * @throws AndroidException when the class cannot be found.
+	 */
+	public static Class<?> getSecureSettingsClass() throws AndroidException {
+		return getInnerClass(
+				"android.provider.Settings", //$NON-NLS-1$
+				"Secure"); //$NON-NLS-1$
+	}
+
+	/** Replies the class {@code Secure} from Android.
+	 * 
+	 * @return the class {@code Secure} from Android.
+	 * @throws AndroidException when the class cannot be found.
+	 */
+	public static Class<?> getSystemSettingsClass() throws AndroidException {
+		return getInnerClass(
+				"android.provider.Settings", //$NON-NLS-1$
+				"System"); //$NON-NLS-1$
+	}
+
+	/** Extract informations from the current {@code Context} of the android task.
+	 * 
+	 * @param androidContext is the Android {@code Context}.
+	 * @throws AndroidException when the information cannot be extracted.
+	 */
+	public static void initialize(Object androidContext) throws AndroidException {
+		assert(androidContext!=null);
+		try {
+			Class<?> contextType = androidContext.getClass();
+			Class<?> contextClass = getContextClass();
+			if (!contextClass.isAssignableFrom(contextType))
+				throw new AndroidException("not an Android Context class"); //$NON-NLS-1$
+			synchronized(Android.class) {
+				contextResolver = null;
+				context = new SoftReference<Object>(androidContext);
+			}
+		}
+		catch(AssertionError e) {
+			throw e;
+		}
+		catch(Throwable e) {
+			throw new AndroidException(e);
+		}
+	}
+
+	/** Replies the current {@code Context} for the android task.
+	 * 
+	 * @return the current {@code Context} for the android task.
+	 * @throws AndroidException when the context is <code>null</code>.
+	 * @see #initialize(Object)
+	 */
+	public static Object getContext() throws AndroidException {
+		Object c;
+		synchronized(Android.class) {
+			if (context==null) throw new AndroidException();
+			c = context.get();
+		}
+		if (c==null) throw new AndroidException();
+		return c;
+	}
+	
+	/** Replies the class loader of the current Android context.
+	 * 
+	 * @return class loader used by the current Android context.
+	 * @throws AndroidException when the context is <code>null</code>.
+	 * @see #initialize(Object)
+	 */
+	public static ClassLoader getContextClassLoader() throws AndroidException {
+		ClassLoader cl;
+		synchronized(Android.class) {
+			cl = (contextClassLoader==null) ? null : contextClassLoader.get();
+		}
+		if (cl==null) {
+			Object context = getContext();
+			try {
+				Method method = context.getClass().getMethod("getClassLoader"); //$NON-NLS-1$
+				Object classLoader = method.invoke(context);
+				if (classLoader instanceof ClassLoader) {
+					cl = (ClassLoader)classLoader;
+					synchronized(Android.class) {
+						contextClassLoader = new WeakReference<ClassLoader>(cl);
+					}
+				}
+				else {
+					throw new AndroidException();
+				}
+			}
+			catch (Throwable e) {
+				throw new AndroidException(e);
+			}
+		}
+		return cl;
+	}
+	
+	/** Replies the current {@code ContextResolver} for the android task.
+	 * 
+	 * @return the current {@code ContextResolver} for the android task.
+	 * @throws AndroidException when the context is <code>null</code>.
+	 * @see #initialize
+	 */
+	public static Object getContextResolver() throws AndroidException {
+		Object resolver;
+		synchronized(Android.class) {
+			resolver = (contextResolver==null) ? null : contextResolver.get();
+		}
+		if (resolver==null) {
+			Object context = getContext();
+			try {
+				Class<?> resolverType = getContextResolverClass();
+				Class<?> contextType = context.getClass();
+				Method getContextResolverMethod = contextType.getMethod("getContentResolver"); //$NON-NLS-1$
+				resolver = getContextResolverMethod.invoke(context);
+				resolver = resolverType.cast(resolver);
+				synchronized(Android.class) {
+					contextResolver = new WeakReference<Object>(resolver);
+				}
+			}
+			catch(AssertionError e) {
+				throw e;
+			}
+			catch(Throwable e) {
+				throw new AndroidException(e);
+			}
+		}
+		return resolver;
+	}
+
+	/**
+	 * This exception is thrown when the {@link Android} attributes
+	 * are not correctly initialized.
+	 *
+	 * @author $Author: galland$
+	 * @version $FullVersion$
+	 * @mavengroupid $GroupId$
+	 * @mavenartifactid $ArtifactId$
+	 * @since 7.0
+	 */
+	public static class AndroidException extends Exception {
+
+		private static final long serialVersionUID = 1521675695582278476L;
+
+		/**
+		 */
+		public AndroidException() {
+			//
+		}
+		
+		/**
+		 * @param message is the error message.
+		 */
+		public AndroidException(String message) {
+			super(message);
+		}
+
+		/**
+		 * @param exception is the cause of this exception.
+		 */
+		public AndroidException(Throwable exception) {
+			super(exception);
+		}
+		
+		/**
+		 * @param message is the error message.
+		 * @param exception is the cause of this exception.
+		 */
+		public AndroidException(String message, Throwable exception) {
+			super(message, exception);
+		}
+
+	} // class AndroidException
+	
+}


Property changes on: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -0,0 +1,80 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stephane GALLANDibrary 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;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.arakhne.vmutil.Android.AndroidException;
+
+/**
+ * This interface provides the Android implementation to load resources.
+ * 
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 7.0
+ */
+class AndroidResourceWrapper implements ResourceWrapper {
+
+	/**
+	 */
+	public AndroidResourceWrapper() {
+		//
+	}
+	
+    /**
+     * {@inheritDoc}
+     */
+	@Override
+    public URL getResource(ClassLoader classLoader, String path) {
+		ClassLoader androidClassLoader;
+		try {
+			androidClassLoader = Android.getContextClassLoader();
+			assert(androidClassLoader!=null);
+			URL url = androidClassLoader.getResource(path);
+			if (url!=null) return url;
+		}
+		catch (AndroidException e) {
+			//
+		}
+		return classLoader.getResource(path);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+	@Override
+    public InputStream getResourceAsStream(ClassLoader classLoader, String path) {
+		ClassLoader androidClassLoader;
+		try {
+			androidClassLoader = Android.getContextClassLoader();
+			assert(androidClassLoader!=null);
+			InputStream stream = androidClassLoader.getResourceAsStream(path);
+			if (stream!=null) return stream;
+		}
+		catch (AndroidException e) {
+			//
+		}
+		return classLoader.getResourceAsStream(path);
+    }
+    
+}


Property changes on: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -44,6 +44,13 @@
 	LINUX,
 	
 	/**
+	 * Android Linux distribution.
+	 * 
+	 * @since 7.0
+	 */
+	ANDROID,
+
+	/**
 	 * Solaris&reg;.
 	 */
 	SOLARIS,
@@ -91,6 +98,7 @@
 	private static final String NULL = new String();
 	private static String osSerialNumber = null;
 	private static String osUUID = null;
+	private static OperatingSystem currentOSInstance = null;
 	
 	/** Replies the type of identification found on this operating system.
 	 * 
@@ -124,14 +132,17 @@
 		case FREEBSD:
 		case HPUX:
 		case LINUX:
+		case ANDROID:
 		case MACOSX:
 		case NETBSD:
 		case OPENBSD:
 		case SOLARIS:
 			return true;
-		default:
+		case WIN:
+		case OTHER:
 			return false;
 		}
+		return false;
 	}
 	
 
@@ -158,48 +169,58 @@
 	 * @return the current operating system constant.
 	 */
 	public static OperatingSystem getCurrentOS() {
-	      String os = System.getProperty("os.name").trim().toLowerCase(); //$NON-NLS-1$
+		if (currentOSInstance!=null) return currentOSInstance;
+		
+		String os = System.getProperty("os.name").trim().toLowerCase(); //$NON-NLS-1$
 
-	      /* Let's try to figure canonical OS name, just in case some
-	       * JVMs use funny values (unlikely)
-	       */
-	      if (os.indexOf("windows") >= 0) { //$NON-NLS-1$
-	          return WIN;
-	      }
-	      else if (os.indexOf("linux") >= 0) { //$NON-NLS-1$
-	          return LINUX;
-	      }
-	      else if ((os.indexOf("solaris") >= 0)|| //$NON-NLS-1$
-	               (os.indexOf("sunos") >= 0)) { //$NON-NLS-1$
-	          return SOLARIS;
-	      }
-	      else if ((os.indexOf("mac os x") >= 0)|| //$NON-NLS-1$
-	               (os.indexOf("macosx") >= 0)) { //$NON-NLS-1$
-	          return MACOSX;
-	      }
-	      else if (os.indexOf("bsd") >= 0) { //$NON-NLS-1$
-	          if (os.indexOf("freebsd") >= 0) { //$NON-NLS-1$
-	              return FREEBSD;
-	          }
-	          else if (os.indexOf("netbsd") >= 0) { //$NON-NLS-1$
-	              return NETBSD;
-	          }
-	          else if (os.indexOf("openbsd") >= 0) { //$NON-NLS-1$
-	              return OPENBSD;
-	          }
-	          else { // default
-	              return BSD;
-	          }
-	      }
-	      else if (os.indexOf("aix") >= 0) { //$NON-NLS-1$
-	          return AIX;
-	      }
-	      else if (os.indexOf("hp ux") >= 0) { //$NON-NLS-1$
-	          return HPUX;
-	      }
-	      else {
-	          return OTHER;
-	      }
+		/* Let's try to figure canonical OS name, just in case some
+		 * JVMs use funny values (unlikely)
+		 */
+		if (os.indexOf("windows") >= 0) { //$NON-NLS-1$
+			return currentOSInstance=WIN;
+		}
+		else if (os.indexOf("linux") >= 0) { //$NON-NLS-1$
+			String vmName = System.getProperty("java.vm.name").trim().toLowerCase(); //$NON-NLS-1$
+			if (vmName.indexOf("dalvik") >= 0) { //$NON-NLS-1$
+				return currentOSInstance=ANDROID;
+			}
+			String runtimeName = System.getProperty("java.runtime.name").trim().toLowerCase(); //$NON-NLS-1$
+			if (runtimeName.indexOf("android") >= 0) { //$NON-NLS-1$
+				return currentOSInstance=ANDROID;
+			}
+			return currentOSInstance=LINUX;
+		}
+		else if ((os.indexOf("solaris") >= 0)|| //$NON-NLS-1$
+				(os.indexOf("sunos") >= 0)) { //$NON-NLS-1$
+			return currentOSInstance=SOLARIS;
+		}
+		else if ((os.indexOf("mac os x") >= 0)|| //$NON-NLS-1$
+				(os.indexOf("macosx") >= 0)) { //$NON-NLS-1$
+			return currentOSInstance=MACOSX;
+		}
+		else if (os.indexOf("bsd") >= 0) { //$NON-NLS-1$
+			if (os.indexOf("freebsd") >= 0) { //$NON-NLS-1$
+				return currentOSInstance=FREEBSD;
+			}
+			else if (os.indexOf("netbsd") >= 0) { //$NON-NLS-1$
+				return currentOSInstance=NETBSD;
+			}
+			else if (os.indexOf("openbsd") >= 0) { //$NON-NLS-1$
+				return currentOSInstance=OPENBSD;
+			}
+			else { // default
+				return currentOSInstance=BSD;
+			}
+		}
+		else if (os.indexOf("aix") >= 0) { //$NON-NLS-1$
+			return currentOSInstance=AIX;
+		}
+		else if (os.indexOf("hp ux") >= 0) { //$NON-NLS-1$
+			return currentOSInstance=HPUX;
+		}
+		else {
+			return currentOSInstance=OTHER;
+		}
 	}
 	
 	/** Replies the data model of the current operating system: 32 or 64 bits.
@@ -303,6 +324,9 @@
 		case LINUX:
 			nativeWrapper = new OperatingSystemUDevWrapper();
 			break;
+		case ANDROID:
+			nativeWrapper = new OperatingSystemAndroidWrapper();
+			break;
 		case WIN:
 			type = OperatingSystemIdentificationType.OPERATING_SYSTEM;
 			break;

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -0,0 +1,96 @@
+/* 
+  * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stephane GALLANDibrary 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;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Wrapper to the Android 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 $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 7.0
+ */
+class OperatingSystemAndroidWrapper extends AbstractOperatingSystemWrapper {
+
+	/**
+	 */
+	public OperatingSystemAndroidWrapper() {
+		//
+	}
+
+	/** {@inheritDoc}
+	 */
+	@Override
+	public String getOSSerialNumber(boolean enableSuperUser, boolean enableGUI) {
+		String serial;
+		try {
+			Class<?> secureClass = Android.getSystemSettingsClass();
+
+			Method getStringMethod = secureClass.getMethod("getString", Android.getContextResolverClass(), String.class); //$NON-NLS-1$
+			
+			Field androidIdField = secureClass.getField("ANDROID_ID"); //$NON-NLS-1$
+			Object androidId = androidIdField.get(null);
+			
+			serial = (String)getStringMethod.invoke(null, Android.getContextResolver(), androidId);
+        }
+		catch (Throwable _) {
+            serial = null;
+        }
+		return serial;
+	}
+
+	/** {@inheritDoc}
+	 */
+	@Override
+	public String getOSUUID(boolean enableSuperUser, boolean enableGUI) {
+		String serial;
+		try {
+			Class<?> secureClass = Android.getSecureSettingsClass();
+
+			Method getStringMethod = secureClass.getMethod("getString", Android.getContextResolverClass(), String.class); //$NON-NLS-1$
+			
+			Field androidIdField = secureClass.getField("ANDROID_ID"); //$NON-NLS-1$
+			Object androidId = androidIdField.get(null);
+			
+			serial = (String)getStringMethod.invoke(null, Android.getContextResolver(), androidId);
+        }
+		catch (Throwable _) {
+            serial = null;
+        }
+		return serial;
+	}
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public OperatingSystemIdentificationType getIdentificationType() {
+		return OperatingSystemIdentificationType.OPERATING_SYSTEM;
+	}
+	
+}


Property changes on: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -1,9 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2009 Stephane GALLAND.
- * 
- * This library is free software; you can redistribute it and/or
+ * Copyright (C) 2009 Stephane GALLANDibrary 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.
@@ -94,5 +92,5 @@
 		showValue("is32BitOperatingSystem()", Boolean.toString(OperatingSystem.is32BitOperatingSystem())); //$NON-NLS-1$
 		showValue("is64BitOperatingSystem()", Boolean.toString(OperatingSystem.is64BitOperatingSystem())); //$NON-NLS-1$
 	}
-
+	
 }

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -0,0 +1,79 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stephane GALLANDibrary 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;
+
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * This interface provides implementations to load resources according to
+ * several heuristics:<ul>
+ * <li>search the resource in class paths;</li>
+ * <li>search the resource in ./resources subdirectory in class paths.</li>
+ * </ul>
+ * 
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 7.0
+ */
+public interface ResourceWrapper {
+
+    /**
+     * Replies the URL of a resource.
+     * <p>
+     * You may use Unix-like syntax to write the resource path, ie.
+     * you may use slashes to separate filenames.
+     * <p>
+     * If the <var>classLoader</var> parameter is <code>null</code>,
+     * the class loader replied by {@link ClassLoaderFinder} is used.
+     * If this last is <code>null</code>, the class loader of
+     * the Resources class is used.
+     *
+     * @param classLoader is the research scope. If <code>null</code>,
+     * the class loader replied by {@link ClassLoaderFinder} is used.
+     * @param path is the absolute path of the resource. 
+     * @return the url of the resource or <code>null</code> if the resource was
+     * not found in class paths.
+     */
+    public URL getResource(ClassLoader classLoader, String path);
+    
+    /**
+     * Replies the input stream of a resource.
+     * <p>
+     * You may use Unix-like syntax to write the resource path, ie.
+     * you may use slashes to separate filenames, and may not start the
+     * path with a slash.
+     * <p>
+     * If the <var>classLoader</var> parameter is <code>null</code>,
+     * the class loader replied by {@link ClassLoaderFinder} is used.
+     * If this last is <code>null</code>, the class loader of
+     * the Resources class is used.
+     *
+     * @param classLoader is the research scope. If <code>null</code>,
+     * the class loader replied by {@link ClassLoaderFinder} is used.
+     * @param path is the absolute path of the resource. 
+     * @return the url of the resource or <code>null</code> if the resource was
+     * not found in class paths.
+     */
+    public InputStream getResourceAsStream(ClassLoader classLoader, String path);
+    	
+}


Property changes on: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -23,6 +23,7 @@
 
 import java.io.InputStream;
 import java.net.URL;
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -41,18 +42,42 @@
  */
 public class Resources {
 
+	private static ResourceWrapper currentResourceInstance = null;
+
 	static {
 		URLHandlerUtil.installArakhneHandlers();
+		
+		ResourceWrapper wrapper = null;
+		
+		switch(OperatingSystem.getCurrentOS()) {
+		case ANDROID:
+			wrapper = new AndroidResourceWrapper();
+			break;
+		case AIX:
+		case BSD:
+		case FREEBSD:
+		case HPUX:
+		case LINUX:
+		case MACOSX:
+		case NETBSD:
+		case OPENBSD:
+		case OTHER:
+		case SOLARIS:
+		case WIN:
+		}
+		
+		if (wrapper==null) {
+			currentResourceInstance = new StandardJREResourceWrapper();
+		}
+		else {
+			currentResourceInstance = wrapper;
+		}
 	}
 
 	/** Character used to separate paths on an resource name.
 	 */
 	public static final String NAME_SEPARATOR = "/"; //$NON-NLS-1$
 
-	/** Prefix (or directory name) where resources may be located.
-	 */
-	private static final String RESOURCE_PREFIX = "resources/"; //$NON-NLS-1$
-
 	/**
      * Replies the URL of a resource.
      * <p>
@@ -141,7 +166,7 @@
     	return u;
     }
 
-   	/**
+    /**
      * Replies the URL of a resource.
      * <p>
      * You may use Unix-like syntax to write the resource path, ie.
@@ -159,27 +184,7 @@
      * not found in class paths.
      */
     public static URL getResource(ClassLoader classLoader, String path) {
-    	if (path==null) return null;
-    	String resourcePath = path;
-    	if (path.startsWith("/")) { //$NON-NLS-1$
-    		resourcePath = path.substring(1);
-    	}
-    	
-    	ClassLoader loader = (classLoader==null)
-    			? Resources.class.getClassLoader()
-    			: classLoader;
-    	assert(loader!=null);
-    			
-    	URL url = loader.getResource(resourcePath);
-    	
-    	if (url==null) {
-    		// Try to find in ./resources sub directory
-    		StringBuffer b = new StringBuffer();
-    		b.append(RESOURCE_PREFIX);
-    		b.append(resourcePath);
-    		url = loader.getResource(b.toString());
-    	}
-    	return url;
+    	return currentResourceInstance.getResource(classLoader, path);
     }
     
     /**
@@ -290,29 +295,57 @@
      * not found in class paths.
      */
     public static InputStream getResourceAsStream(ClassLoader classLoader, String path) {
-    	if (path==null) return null;
-    	String resourcePath = path;
-    	if (path.startsWith("/")) { //$NON-NLS-1$
-    		resourcePath = path.substring(1);
+    	return currentResourceInstance.getResourceAsStream(classLoader, path);
+    }
+
+   	/**
+     * Replies the URL of a property resource that is associated to the given class.
+     *
+     * @param classname is the class for which the property resource should be replied.
+     * @param locale is the expected localization of the resource file; or <code>null</code>
+     * for the default. 
+     * @return the url of the property resource or <code>null</code> if the resource was
+     * not found in class paths.
+     * @since 7.0
+     */
+    public static URL getPropertyFile(Class<?> classname, Locale locale) {
+    	return getPropertyFile(classname.getClassLoader(), classname, locale);
+    }
+
+   	/**
+     * Replies the URL of a property resource that is associated to the given class.
+     *
+     * @param classLoader is the research scope. If <code>null</code>,
+     * the class loader replied by {@link ClassLoaderFinder} is used.
+     * @param classname is the class for which the property resource should be replied.
+     * @param locale is the expected localization of the resource file; or <code>null</code>
+     * for the default. 
+     * @return the url of the property resource or <code>null</code> if the resource was
+     * not found in class paths.
+     */
+    public static URL getPropertyFile(ClassLoader classLoader, Class<?> classname, Locale locale) {
+    	StringBuffer name = new StringBuffer();
+    	
+    	// Localized file
+    	if (locale!=null) {
+    		String country = locale.getCountry();
+    		if (country!=null && !country.isEmpty()) {
+    	    	name.append(classname.getSimpleName());
+    	    	name.append("_"); //$NON-NLS-1$
+    	    	name.append(country);
+    	    	name.append(".properties"); //$NON-NLS-1$
+    	    	URL url = getResource(classLoader, classname.getPackage(), name.toString());
+    	    	if (url!=null) {
+    	    		return url;
+    	    	}
+    		}
     	}
-    	ClassLoader loader = classLoader;
-    	if (loader==null) {
-    		loader = ClassLoaderFinder.findClassLoader();
-    	}
-    	if (loader==null) {
-    		loader = Resources.class.getClassLoader();
-    	}
     	
-    	assert(loader!=null);
-    	InputStream is = loader.getResourceAsStream(resourcePath);
-    	if (is==null) {
-    		// Try to find in ./resources sub directory
-    		StringBuffer b = new StringBuffer();
-    		b.append(RESOURCE_PREFIX);
-    		b.append(resourcePath);
-    		is = loader.getResourceAsStream(b.toString());
-    	}
-    	return is;
+    	// Default property file
+    	name.setLength(0);
+    	name.append(classname.getSimpleName());
+    	name.append(".properties"); //$NON-NLS-1$
+    	return getResource(classLoader, classname.getPackage(), name.toString());
     }
 
 }

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java	2012-01-30 19:17:54 UTC (rev 323)
@@ -0,0 +1,108 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stephane GALLANDibrary 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;
+
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * This interface provides the standard JRE implementation to load resources according to
+ * several heuristics:<ul>
+ * <li>search the resource in class paths;</li>
+ * <li>search the resource in ./resources subdirectory in class paths.</li>
+ * </ul>
+ * 
+ * @author $Author: galland$
+ * @version $FullVersion$
+ * @mavengroupid $GroupId$
+ * @mavenartifactid $ArtifactId$
+ * @since 7.0
+ */
+class StandardJREResourceWrapper implements ResourceWrapper {
+
+	/** Prefix (or directory name) where resources may be located.
+	 */
+	public static final String RESOURCE_PREFIX = "resources/"; //$NON-NLS-1$
+
+	/**
+	 */
+	public StandardJREResourceWrapper() {
+		//
+	}
+	
+    /**
+     * {@inheritDoc}
+     */
+	@Override
+    public URL getResource(ClassLoader classLoader, String path) {
+    	if (path==null) return null;
+    	String resourcePath = path;
+    	if (path.startsWith("/")) { //$NON-NLS-1$
+    		resourcePath = path.substring(1);
+    	}
+    	
+    	ClassLoader loader = (classLoader==null)
+    			? ClassLoaderFinder.findClassLoader() //Resources.class.getClassLoader()
+    			: classLoader;
+    	assert(loader!=null);
+    			
+    	URL url = loader.getResource(resourcePath);
+    	
+    	if (url==null) {
+    		// Try to find in ./resources sub directory
+    		StringBuffer b = new StringBuffer();
+    		b.append(RESOURCE_PREFIX);
+    		b.append(resourcePath);
+    		url = loader.getResource(b.toString());
+    	}
+    	return url;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+	@Override
+    public InputStream getResourceAsStream(ClassLoader classLoader, String path) {
+    	if (path==null) return null;
+    	String resourcePath = path;
+    	if (path.startsWith("/")) { //$NON-NLS-1$
+    		resourcePath = path.substring(1);
+    	}
+    	ClassLoader loader = classLoader;
+    	if (loader==null) {
+    		loader = ClassLoaderFinder.findClassLoader();
+    	}
+    	if (loader==null) {
+    		loader = Resources.class.getClassLoader();
+    	}
+    	
+    	assert(loader!=null);
+    	InputStream is = loader.getResourceAsStream(resourcePath);
+    	if (is==null) {
+    		// Try to find in ./resources sub directory
+    		StringBuffer b = new StringBuffer();
+    		b.append(RESOURCE_PREFIX);
+    		b.append(resourcePath);
+    		is = loader.getResourceAsStream(b.toString());
+    	}
+    	return is;
+    }
+    
+}


Property changes on: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/arakhneVmutils/native/josuuid/mingw32/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/mingw32/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/native/josuuid/mingw32/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -7,13 +7,13 @@
 	<parent>
 		<artifactId>josuuid</artifactId>
 		<groupId>org.arakhne.afc</groupId>
-		<version>6.4-SNAPSHOT</version>
+		<version>7.0-SNAPSHOT</version>
 	</parent>
 
 	<groupId>org.arakhne.afc</groupId>
 	<artifactId>josuuid-mingw32</artifactId>
 	<packaging>dll</packaging>
-	<version>6.4-SNAPSHOT</version>
+	<version>7.0-SNAPSHOT</version>
 	<name>Win 32 OS UUID Library</name>
 
 	<!-- ======================================= -->

Modified: trunk/arakhneVmutils/native/josuuid/mingw64/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/mingw64/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/native/josuuid/mingw64/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -7,13 +7,13 @@
 	<parent>
 		<artifactId>josuuid</artifactId>
 		<groupId>org.arakhne.afc</groupId>
-		<version>6.4-SNAPSHOT</version>
+		<version>7.0-SNAPSHOT</version>
 	</parent>
 
 	<groupId>org.arakhne.afc</groupId>
 	<artifactId>josuuid-mingw64</artifactId>
 	<packaging>dll</packaging>
-	<version>6.4-SNAPSHOT</version>
+	<version>7.0-SNAPSHOT</version>
 	<name>Win 64 OS UUID Library</name>
 
 	<!-- ======================================= -->

Modified: trunk/arakhneVmutils/native/josuuid/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/native/josuuid/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -6,13 +6,13 @@
 	<parent>
 		<artifactId>arakhneVmutils-native</artifactId>
 		<groupId>org.arakhne.afc</groupId>
-		<version>6.4-SNAPSHOT</version>
+		<version>7.0-SNAPSHOT</version>
 	</parent>
 
 	<groupId>org.arakhne.afc</groupId>
 	<artifactId>josuuid</artifactId>
 	<packaging>pom</packaging>
-	<version>6.4-SNAPSHOT</version>
+	<version>7.0-SNAPSHOT</version>
 	<name>OS UUID Library</name>
 
 	<!-- ======================================= -->

Modified: trunk/arakhneVmutils/native/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/native/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -17,7 +17,7 @@
   <artifactId>arakhneVmutils-native</artifactId>
   <groupId>org.arakhne.afc</groupId>
   <packaging>pom</packaging>
-  <version>6.4-SNAPSHOT</version>
+  <version>7.0-SNAPSHOT</version>
   <name>Native VM Utilities</name>
 	<url>http://www.arakhne.org/arakhneVmutils/</url>
 

Modified: trunk/arakhneVmutils/pom.xml
===================================================================
--- trunk/arakhneVmutils/pom.xml	2012-01-28 14:04:42 UTC (rev 322)
+++ trunk/arakhneVmutils/pom.xml	2012-01-30 19:17:54 UTC (rev 323)
@@ -12,7 +12,7 @@
 	<groupId>org.arakhne.afc</groupId>
 	<artifactId>arakhneVmutils</artifactId>
 	<packaging>pom</packaging>
-	<version>6.4-SNAPSHOT</version>
+	<version>7.0-SNAPSHOT</version>
 	<name>Java and Native VM Utilities</name>
 	<description>Additional tools dedicated to low-level and virtual machine features</description>
 	<url>http://www.arakhne.org/arakhneVmutils/</url>


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