[Arakhnę-Dev] [1] Initial import of the AFC |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 1
Author: galland
Date: 2008-10-07 16:32:10 +0200 (Tue, 07 Oct 2008)
Log Message:
-----------
Initial import of the AFC
Added Paths:
-----------
.classpath
.project
.settings/
.settings/org.eclipse.jdt.core.prefs
.settings/org.maven.ide.eclipse.prefs
branches/
tags/
trunk/
trunk/arakhneRefs/
trunk/arakhneRefs/pom.xml
trunk/arakhneRefs/src/
trunk/arakhneRefs/src/main/
trunk/arakhneRefs/src/main/java/
trunk/arakhneRefs/src/main/java/org/
trunk/arakhneRefs/src/main/java/org/arakhne/
trunk/arakhneRefs/src/main/java/org/arakhne/util/
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableSoftReference.java
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableWeakReference.java
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/SoftValueMap.java
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java
trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakValueMap.java
trunk/arakhneRefs/src/main/resources/
trunk/arakhneRefs/src/main/resources/AUTHORS
trunk/arakhneRefs/src/main/resources/COPYING
trunk/arakhneRefs/src/main/resources/Changelog
trunk/arakhneRefs/src/main/resources/VERSION
trunk/arakhneRefs/src/test/
trunk/arakhneRefs/src/test/java/
trunk/arakhneVmutils/
trunk/arakhneVmutils/java/
trunk/arakhneVmutils/java/pom.xml
trunk/arakhneVmutils/java/src/
trunk/arakhneVmutils/java/src/main/
trunk/arakhneVmutils/java/src/main/java/
trunk/arakhneVmutils/java/src/main/java/org/
trunk/arakhneVmutils/java/src/main/java/org/arakhne/
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AutoboxingUtil.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClassLoaderFinder.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/VMCommandLine.java
trunk/arakhneVmutils/java/src/main/resources/
trunk/arakhneVmutils/java/src/main/resources/AUTHORS
trunk/arakhneVmutils/java/src/main/resources/COPYING
trunk/arakhneVmutils/java/src/main/resources/Changelog
trunk/arakhneVmutils/java/src/main/resources/VERSION
trunk/arakhneVmutils/java/src/test/
trunk/arakhneVmutils/native/
trunk/arakhneVmutils/native/josuuid/
trunk/arakhneVmutils/native/josuuid/linux/
trunk/arakhneVmutils/native/josuuid/linux/pom.xml
trunk/arakhneVmutils/native/josuuid/mingw/
trunk/arakhneVmutils/native/josuuid/mingw/pom.xml
trunk/arakhneVmutils/native/josuuid/pom.xml
trunk/arakhneVmutils/native/josuuid/src/
trunk/arakhneVmutils/native/josuuid/src/main/
trunk/arakhneVmutils/native/josuuid/src/main/native/
trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp
trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp
trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h
trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp
trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h
trunk/arakhneVmutils/native/josuuid/src/main/resources/
trunk/arakhneVmutils/native/josuuid/src/main/resources/AUTHORS
trunk/arakhneVmutils/native/josuuid/src/main/resources/COPYING
trunk/arakhneVmutils/native/josuuid/src/main/resources/Changelog
trunk/arakhneVmutils/native/josuuid/src/main/resources/VERSION
trunk/arakhneVmutils/native/josuuid/src/test/
trunk/arakhneVmutils/native/pom.xml
trunk/arakhneVmutils/pom.xml
trunk/arakhneVmutils/with-dll.xml
trunk/pom.xml
Added: .classpath
===================================================================
--- .classpath (rev 0)
+++ .classpath 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: .project
===================================================================
--- .project (rev 0)
+++ .project 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>arakhneRefs</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: .settings/org.eclipse.jdt.core.prefs
===================================================================
--- .settings/org.eclipse.jdt.core.prefs (rev 0)
+++ .settings/org.eclipse.jdt.core.prefs 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,12 @@
+#Fri Sep 26 14:27:57 CEST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: .settings/org.maven.ide.eclipse.prefs
===================================================================
--- .settings/org.maven.ide.eclipse.prefs (rev 0)
+++ .settings/org.maven.ide.eclipse.prefs 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,8 @@
+#Fri Sep 26 14:24:22 CEST 2008
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+version=1
Added: trunk/arakhneRefs/pom.xml
===================================================================
--- trunk/arakhneRefs/pom.xml (rev 0)
+++ trunk/arakhneRefs/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>arakhneRefs</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0-SNAPSHOT</version>
+ <name>arakhneRefs Java Library</name>
+ <url>http://www.arakhne.org/arakhneRefs/</url>
+ <description>Java library that provides additional tools to manage weak and soft references</description>
+ <parent>
+ <artifactId>afc</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <scm>
+ <connection>scm:svn:svn+ssh://svn.tuxfamily.org/svnroot/arakhne/afc/arakhneRefs</connection>
+ <developerConnection>scm:svn:svn+ssh://username@xxxxxxxxxxxxxxxxx/svnroot/arakhne/afc/arakhneRefs</developerConnection>
+ <url>http://www.arakhne.org/websvn.php?project=afc&subproject=arakhneRefs</url>
+ </scm>
+
+</project>
Added: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableSoftReference.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableSoftReference.java (rev 0)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableSoftReference.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,172 @@
+/*
+ * $Id: ComparableSoftReference.java,v 1.1 2007-02-20 08:52:37 sgalland Exp $
+ *
+ * Copyright (C) 2005-2007 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.util.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+
+/**
+ * This class is a WeakReference that allows to be
+ * compared on its pointed value.
+ *
+ * @param <T> is the type of the referenced object.
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+public class ComparableSoftReference<T> extends SoftReference<T> implements Comparable<Object> {
+
+ /**
+ * @param referent is the referenced object.
+ */
+ public ComparableSoftReference(T referent) {
+ super(referent);
+ }
+
+ /**
+ * @param referent is the referenced object.
+ * @param queue is the object that will be notified of the memory released for the referenced object.
+ */
+ public ComparableSoftReference(T referent, ReferenceQueue<? super T> queue) {
+ super(referent,queue);
+ }
+
+ /** {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object o) {
+ if (super.equals(o)) return true;
+
+ try {
+ if (o instanceof Reference)
+ return (compareToRef((Reference)o)==0);
+
+ return compareToObject((T)o)==0;
+ }
+ catch(Exception _) {
+ return false;
+ }
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public int compareTo(Object o) {
+ try {
+ if (o instanceof Reference)
+ return compareToRef((Reference)o);
+
+ return compareToObject((T)o);
+ }
+ catch(Exception _) {
+ int a = hashCode();
+ int b = o.hashCode();
+ return a - b;
+ }
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o the object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ */
+ @SuppressWarnings("unchecked")
+ public int compareToRef(Reference<T> o) {
+ T obj = o.get();
+ T cur = get();
+
+ if (((cur==null)&&(obj==null))||(cur==obj)) return 0;
+ if (cur==null) return -1;
+ if (obj==null) return 1;
+
+ if (cur instanceof Comparable) {
+ Comparable cmp = (Comparable<?>)cur;
+ return cmp.compareTo(obj);
+ }
+
+ if ((cur==obj)||(cur.equals(obj))) return 0;
+
+ int a = cur.hashCode();
+ int b = obj.hashCode();
+
+ return a - b;
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o the object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ */
+ @SuppressWarnings("unchecked")
+ public int compareToObject(T o) {
+ if (super.equals(o)) return 0;
+
+ T cur = get();
+
+ if ((cur==null)&&(o==null)) return 0;
+ if (cur==null) return -1;
+ if (o==null) return 1;
+
+ if (cur instanceof Comparable) {
+ Comparable cmp = (Comparable)cur;
+ return cmp.compareTo(o);
+ }
+
+ if ((cur==o)||(cur.equals(o))) return 0;
+
+ int a = cur.hashCode();
+ int b = o.hashCode();
+
+ return a - b;
+ }
+
+ /** {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('{');
+ T obj = get();
+ if (obj==null) buffer.append("#null#"); //$NON-NLS-1$
+ else buffer.append(obj.toString());
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+}
Added: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableWeakReference.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableWeakReference.java (rev 0)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ComparableWeakReference.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,172 @@
+/*
+ * $Id: ComparableWeakReference.java,v 1.1 2007-02-20 08:52:37 sgalland Exp $
+ *
+ * Copyright (C) 2005-2007 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.util.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+
+/**
+ * This class is a WeakReference that allows to be
+ * compared on its pointed value.
+ *
+ * @param <T> is the type of the referenced object.
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+public class ComparableWeakReference<T> extends WeakReference<T> implements Comparable<Object> {
+
+ /**
+ * @param referent is the referenced object.
+ */
+ public ComparableWeakReference(T referent) {
+ super(referent);
+ }
+
+ /**
+ * @param referent is the referenced object.
+ * @param queue is the object that will be notified of the memory released for the referenced object.
+ */
+ public ComparableWeakReference(T referent, ReferenceQueue<? super T> queue) {
+ super(referent,queue);
+ }
+
+ /** {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object o) {
+ if (super.equals(o)) return true;
+
+ try {
+ if (o instanceof Reference)
+ return (compareToRef((Reference)o)==0);
+
+ return compareToObject((T)o)==0;
+ }
+ catch(Exception _) {
+ return false;
+ }
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public int compareTo(Object o) {
+ try {
+ if (o instanceof Reference)
+ return compareToRef((Reference)o);
+
+ return compareToObject((T)o);
+ }
+ catch(Exception _) {
+ int a = hashCode();
+ int b = o.hashCode();
+ return a - b;
+ }
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o the object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ */
+ @SuppressWarnings("unchecked")
+ public int compareToObject(T o) {
+ if (super.equals(o)) return 0;
+
+ T cur = get();
+
+ if ((cur==null)&&(o==null)) return 0;
+ if (cur==null) return -1;
+ if (o==null) return 1;
+
+ if (cur instanceof Comparable) {
+ Comparable cmp = (Comparable)cur;
+ return cmp.compareTo(o);
+ }
+
+ if ((cur==o)||(cur.equals(o))) return 0;
+
+ int a = cur.hashCode();
+ int b = o.hashCode();
+
+ return a - b;
+ }
+
+ /** Compare this reference to the specified object
+ * based on the {@link Object#hashCode()} if the
+ * references are not equals.
+ *
+ * @param o the object to be compared.
+ * @return a negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ */
+ @SuppressWarnings("unchecked")
+ public int compareToRef(Reference<T> o) {
+ Object obj = o.get();
+ Object cur = get();
+
+ if (((cur==null)&&(obj==null))||(obj==cur)) return 0;
+ if (cur==null) return -1;
+ if (obj==null) return 1;
+
+ if (cur instanceof Comparable) {
+ Comparable cmp = (Comparable)cur;
+ return cmp.compareTo(obj);
+ }
+
+ if ((cur==obj)||(cur.equals(obj))) return 0;
+
+ int a = cur.hashCode();
+ int b = obj.hashCode();
+
+ return a - b;
+ }
+
+ /** {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('{');
+ T obj = get();
+ if (obj==null) buffer.append("#null#"); //$NON-NLS-1$
+ else buffer.append(obj.toString());
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+}
Added: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/SoftValueMap.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/SoftValueMap.java (rev 0)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/SoftValueMap.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,448 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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.util.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ConcurrentModificationException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A <tt>Map</tt> implementation with <em>soft-referenced values</em>. An entry in a
+ * <tt>SoftValueMap</tt> will automatically be removed when its value is no
+ * longer in ordinary use or null.
+ * <p>
+ * This class was inspirated from {@link WeakValueMap}.
+ * <p>
+ * This class has a special flag which permits to control the
+ * way how the released references are expurged: {@link #isDeeplyExpurge()},
+ * {@link #setDeeplyExpurge(boolean)}. If this flag is <code>true</code>,
+ * all the released references will be immediately removed from the map even
+ * if they are not enqueued by the virtual machine (see {@link #expurge()}.
+ * If this flag is <code>false</code>,
+ * only the enqueued references will be removed from the map
+ * (see {@link #expurgeQueuedReferences()}.
+ * <p>
+ * If this map does not use a "deep expurge" of the released references,
+ * it could contains <code>null</code> values that corresponds to
+ * values that are released by the garbage collector. If a "deep expurge"
+ * is used, all the values released by the garbage collector will be
+ * removed from the map.
+ * <p>
+ * "Deep expurge" consumes much more time that "No deep expurge". This is the
+ * reason why this feature is not activated by default.
+ * <p>
+ * The "deep expurge" feature was added to fix the uncoherent behavior
+ * of the garbage collector which seems to not always enqueued the
+ * released values (sometimes the queue is empty even if a value was released).
+ *
+ * @param <K> is the type of the keys.
+ * @param <V> is the type of the values.
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+public class SoftValueMap<K,V> extends AbstractMap<K,V> implements Map<K,V> {
+
+ /** Constant that represent a NULL value inside a SoftValueMap.
+ * @see #maskNull(Object)
+ */
+ protected static final Object NULL_VALUE = new Object();
+
+ /** Mask the null values given by the used of this map.
+ * <p>
+ * This method replaces the <code>null</code> value by
+ * the internal representation {@link #NULL_VALUE}.
+ *
+ * @param <V> is the type of the value
+ * @param value is the value given by the user of this map.
+ * @return the internal representation of the value.
+ * @see #unmaskNull(Object)
+ */
+ @SuppressWarnings("unchecked")
+ protected static <V> V maskNull(V value) {
+ return (value==null) ? (V)NULL_VALUE : value;
+ }
+
+ /** Unmask the null values given by the used of this map.
+ * <p>
+ * This method replaces the internal representation
+ * {@link #NULL_VALUE} of null values by its user representation
+ * <code>null</code>.
+ *
+ * @param <V> is the type of the value
+ * @param value is the value given by the user of this map.
+ * @return the internal representation of the value.
+ * @see #maskNull(Object)
+ */
+ protected static <V> V unmaskNull(V value) {
+ return (value==NULL_VALUE) ? null : value;
+ }
+
+ private boolean autoExpurge = false;
+ private final HashMap<K,Value<K,V>> map;
+ private final ReferenceQueue<V> queue = new ReferenceQueue<V>();
+ private final EntrySet entrySet;
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the specified initial
+ * capacity and load factor.
+ *
+ * @param initialCapacity the initial capacity
+ * @param loadFactor the load factor
+ * @throws IllegalArgumentException if the initial capacity is negative
+ * or the load factor is nonpositive
+ */
+ public SoftValueMap(int initialCapacity, float loadFactor) {
+ this.map = new HashMap<K,Value<K,V>>(initialCapacity, loadFactor);
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the specified initial
+ * capacity and the default load factor (0.75).
+ *
+ * @param initialCapacity the initial capacity.
+ * @throws IllegalArgumentException if the initial capacity is negative.
+ */
+ public SoftValueMap(int initialCapacity) {
+ this.map = new HashMap<K,Value<K,V>>(initialCapacity);
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the default initial capacity
+ * (16) and the default load factor (0.75).
+ */
+ public SoftValueMap() {
+ this.map = new HashMap<K,Value<K,V>>();
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs a new <tt>HashMap</tt> with the same mappings as the
+ * specified <tt>Map</tt>. The <tt>HashMap</tt> is created with
+ * default load factor (0.75) and an initial capacity sufficient to
+ * hold the mappings in the specified <tt>Map</tt>.
+ *
+ * @param m the map whose mappings are to be placed in this map
+ * @throws NullPointerException if the specified map is null
+ */
+ public SoftValueMap(Map<? extends K, ? extends V> m) {
+ this.map = new HashMap<K,Value<K,V>>();
+ this.entrySet = new EntrySet();
+ putAll(m);
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ */
+ protected void expurgeNow() {
+ if (this.autoExpurge)
+ expurge();
+ else
+ expurgeQueuedReferences();
+ }
+
+ /** Replies if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @return <code>true</code> if this map deeply expurge its content,
+ * otherwise <code>false</code>
+ */
+ public boolean isDeeplyExpurge() {
+ return this.autoExpurge;
+ }
+
+ /** Set if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @param deeplyExpurge must be <code>true</code> to
+ * expurge all the released values, otherwise <code>false</code>
+ * to expurge only the enqueued values.
+ * @return the old value of this flag
+ */
+ public boolean setDeeplyExpurge(boolean deeplyExpurge) {
+ boolean old = this.autoExpurge;
+ this.autoExpurge = deeplyExpurge;
+ return old;
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ */
+ public void expurgeQueuedReferences() {
+ Reference<? extends V> o;
+ while((o = this.queue.poll()) != null) {
+ if (o instanceof Value) {
+
+ this.map.remove(((Value<?,?>)o).getKey());
+ }
+ o.clear();
+ }
+ }
+
+ /** Clean the references that was released.
+ */
+ public void expurge() {
+ Reference<? extends V> o;
+
+ Iterator<Entry<K,Value<K,V>>> iter = this.map.entrySet().iterator();
+ Entry<K,Value<K,V>> entry;
+ Value<K,V> value;
+ while (iter.hasNext()) {
+ entry = iter.next();
+ if (entry!=null) {
+ value = entry.getValue();
+ if ((value!=null)&&
+ ((value.isEnqueued())||(value.get()==null))) {
+ value.enqueue();
+ value.clear();
+ }
+ }
+ }
+ entry = null;
+ value = null;
+
+ while((o = this.queue.poll()) != null) {
+ if (o instanceof Value) {
+ this.map.remove(((Value<?,?>)o).getKey());
+ }
+ o.clear();
+ }
+ }
+
+ /** Create a storage object that permits to put the specified
+ * elements inside this map.
+ *
+ * @param k is the key associated to the value
+ * @param v is the value
+ * @param queue is the reference queue to use
+ * @return the new storage object
+ */
+ protected Value<K,V> makeValue(K k, V v, ReferenceQueue<V> queue) {
+ return new Value<K,V>(k, v, queue);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V put(K key, V value) {
+ expurgeNow();
+ Value<K,V> ret = this.map.put(key, makeValue(key, value, this.queue));
+ if(ret == null) return null;
+ return ret.getValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Entry<K,V>> entrySet() {
+ expurgeNow();
+ return this.entrySet;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ expurgeNow();
+ return super.equals(o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ expurgeNow();
+ return hashCode();
+ }
+
+ /**
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+ private class EntrySet extends AbstractSet<Entry<K,V>> implements Set<Entry<K,V>> {
+
+ private final Set<Entry<K,Value<K,V>>> baseSet;
+
+ /**
+ *
+ */
+ @SuppressWarnings("synthetic-access")
+ public EntrySet() {
+ this.baseSet = SoftValueMap.this.map.entrySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public Iterator<Entry<K, V>> iterator() {
+ final Iterator<Entry<K,Value<K,V>>> iter = this.baseSet.iterator();
+ return new Iterator<Entry<K,V>>() {
+ public boolean hasNext() {
+ expurgeNow();
+ return iter.hasNext();
+ }
+ public Entry<K,V> next() {
+ Entry<K, Value<K,V>> entry = iter.next();
+ if (entry==null) throw new ConcurrentModificationException();
+ Value<K,V> value = entry.getValue();
+ if (value==null) throw new ConcurrentModificationException();
+ return value;
+ }
+ public void remove() {
+ iter.remove();
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ expurgeNow();
+ return this.baseSet.size();
+ }
+
+ }
+
+ /**
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+ private static class Value<K,V> extends SoftReference<V> implements Entry<K,V> {
+
+ private final K k;
+
+ /**
+ * @param k is the key.
+ * @param v is the value.
+ * @param queue is the memory release listener.
+ */
+ Value(K k, V v, ReferenceQueue<V> queue) {
+ super(maskNull(v), queue);
+ this.k = k;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('{');
+ K key = getKey();
+ buffer.append(key==null ? null : key.toString());
+ buffer.append('=');
+ if (isEnqueued()) {
+ buffer.append("Q#"); //$NON-NLS-1$
+ }
+ else {
+ buffer.append("P#"); //$NON-NLS-1$
+ }
+ V v = getValue();
+ buffer.append((v==null ? null : v.toString()));
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ public K getKey() {
+ return this.k;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ public V getValue() {
+ return unmaskNull(get());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ public V setValue(V o) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ Object val = getValue();
+ return (getKey()==null ? 0 : getKey().hashCode()) ^
+ (val==null ? 0 : val.hashCode());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Entry) {
+ Entry<K,V> e = (Entry<K,V>)o;
+ Object e1val = getValue();
+ Object e2val = e.getValue();
+ return (getKey()==null ?
+ e.getKey()==null : getKey().equals(e.getKey())) &&
+ (e1val==null ? e2val==null : e1val.equals(e2val));
+ }
+ return false;
+ }
+
+ }
+
+}
Added: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java (rev 0)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,400 @@
+/*
+ * $Id: WeakArrayList.java,v 1.1 2007-02-20 08:52:37 sgalland Exp $
+ *
+ * Copyright (C) 2005-2007 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.util.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.AbstractList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A array-based <tt>List</tt> implementation with <em>weak keys</em>.
+ * An entry in a <tt>WeakArrayList</tt> will automatically be removed when
+ * it is no longer in ordinary use.
+ *
+ * <p> The behavior of the <tt>WeakArrayList</tt> class depends in part upon
+ * the actions of the garbage collector, so several familiar (though not
+ * required) <tt>List</tt> invariants do not hold for this class. Because
+ * the garbage collector may discard values at any time, a
+ * <tt>WeakArrayList</tt> may behave as though an unknown thread is silently
+ * removing entries. In particular, even if you synchronize on a
+ * <tt>WeakArrayList</tt> instance and invoke none of its mutator methods, it
+ * is possible for the <tt>size</tt> method to return smaller values over
+ * time, for the <tt>isEmpty</tt> method to return <tt>false</tt> and
+ * then <tt>true</tt>, for the <tt>contains</tt> method to return
+ * <tt>true</tt> and later <tt>false</tt> for a given value, for the
+ * <tt>get</tt> method to return a value for a given key but later return
+ * <tt>null</tt>, for the <tt>add</tt> method to return
+ * <tt>null</tt> and the <tt>remove</tt> method to return
+ * <tt>false</tt> for a value that previously appeared to be in the list.
+ * <p>
+ * This class has a special flag which permits to control the
+ * way how the released references are expurged: {@link #isDeeplyExpurge()},
+ * {@link #setDeeplyExpurge(boolean)}. If this flag is <code>true</code>,
+ * all the released references will be immediately removed from the map even
+ * if they are not enqueued by the virtual machine (see {@link #expurge()}.
+ * If this flag is <code>false</code>,
+ * only the enqueued references will be removed from the map
+ * (see {@link #expurgeQueuedReferences()}.
+ * <p>
+ * If this map does not use a "deep expurge" of the released references,
+ * it could contains <code>null</code> values that corresponds to
+ * values that are released by the garbage collector. If a "deep expurge"
+ * is used, all the values released by the garbage collector will be
+ * removed from the map.
+ * <p>
+ * "Deep expurge" consumes much more time that "No deep expurge". This is the
+ * reason why this feature is not activated by default.
+ * <p>
+ * The "deep expurge" feature was added to fix the uncoherent behavior
+ * of the garbage collector which seems to not always enqueued the
+ * released values (sometimes the queue is empty even if a value was released).
+ *
+ * @param <T> is the type of the array's elements.
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+public class WeakArrayList<T> extends AbstractList<T> implements List<T> {
+
+ private static final long serialVersionUID = 2601162363164961860L;
+
+ /** This value represents a null value given by the user.
+ */
+ private static final Object NULL_VALUE = new Object();
+
+ /** Replies the null value given by the user by the corresponding null object.
+ */
+ @SuppressWarnings("unchecked")
+ private T maskNull(T value) {
+ return (value==null) ? (T)NULL_VALUE : value;
+ }
+
+ /** Replies the value given by the user.
+ */
+ private T unmaskNull(T value) {
+ return (value==NULL_VALUE) ? null : value;
+ }
+
+ private final transient ReferenceQueue<T> queue = new ReferenceQueue<T>();
+
+ private Object[] data;
+
+ private int size;
+
+ private boolean autoExpurge = false;
+
+ /**
+ * Constructs an empty list with the specified initial capacity.
+ *
+ * @param initialCapacity the initial capacity of the list
+ * @exception IllegalArgumentException if the specified initial capacity
+ * is negative
+ */
+ public WeakArrayList(int initialCapacity) {
+ if (initialCapacity < 0)
+ throw new IllegalArgumentException("Illegal Capacity: "+initialCapacity); //$NON-NLS-1$
+ this.data = new Object[initialCapacity];
+ this.size = 0;
+ }
+
+ /**
+ * Constructs an empty list with an initial capacity of ten.
+ */
+ public WeakArrayList() {
+ this(10);
+ }
+
+ /**
+ * Constructs a list containing the elements of the specified
+ * collection, in the order they are returned by the collection's
+ * iterator.
+ *
+ * @param c the collection whose elements are to be placed into this list
+ * @throws NullPointerException if the specified collection is null
+ */
+ public WeakArrayList(Collection<? extends T> c) {
+ this.data = new Object[c.size()];
+ this.size = this.data.length;
+ int i=0;
+ for (T t : c) {
+ this.data[i] = createRef(t);
+ i++;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ Reference<T> ref;
+ T obj;
+ for(int i=0; i<this.size; i++) {
+ ref = (Reference<T>)this.data[i];
+ obj = ref.get();
+ buffer.append('{');
+ buffer.append(obj==null ? null : obj.toString());
+ buffer.append('}');
+ }
+ return buffer.toString();
+ }
+
+ /** Create and replies the reference for the specified object.
+ *
+ * @param obj is the object on which a weak reference must be attached.
+ * @return the weak reference.
+ */
+ private Reference<T> createRef(T obj) {
+ return new WeakReference<T>(maskNull(obj), this.queue);
+ }
+
+ /**
+ * Increases the capacity of this <tt>WeakArrayList</tt> instance, if
+ * necessary, to ensure that it can hold at least the number of elements
+ * specified by the minimum capacity argument.
+ *
+ * @param minCapacity the desired minimum capacity
+ */
+ public void ensureCapacity(int minCapacity) {
+ this.modCount++;
+ int oldCapacity = this.data.length;
+ if (minCapacity > oldCapacity) {
+ Object[] oldData = this.data;
+ int newCapacity = (oldCapacity * 3)/2 + 1;
+ if (newCapacity < minCapacity)
+ newCapacity = minCapacity;
+ // minCapacity is usually close to size, so this is a win:
+ this.data = Arrays.copyOf(oldData, newCapacity);
+ }
+ }
+
+ /**
+ * Trims the capacity of this <tt>WeakArrayList</tt> instance to be the
+ * list's current size. An application can use this operation to minimize
+ * the storage of an <tt>WeakArrayList</tt> instance.
+ */
+ public void trimToSize() {
+ this.modCount++;
+ int oldCapacity = this.data.length;
+ if (this.size < oldCapacity) {
+ this.data = Arrays.copyOf(this.data, this.size);
+ }
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ *
+ * @return the count of expurged elements.
+ */
+ protected int expurgeNow() {
+ if (this.autoExpurge)
+ return expurge();
+ return expurgeQueuedReferences();
+ }
+
+ /** Replies if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @return <code>true</code> if this array list deeply expurge the
+ * released elements, otherwise <code>false</code>
+ */
+ public boolean isDeeplyExpurge() {
+ return this.autoExpurge;
+ }
+
+ /** Set if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @param deeplyExpurge must be <code>true</code> to
+ * expurge all the released values, otherwise <code>false</code>
+ * to expurge only the enqueued values.
+ * @return the old value of this flag
+ */
+ public boolean setDeeplyExpurge(boolean deeplyExpurge) {
+ boolean old = this.autoExpurge;
+ this.autoExpurge = deeplyExpurge;
+ return old;
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ *
+ * @return the size
+ */
+ public int expurgeQueuedReferences() {
+ synchronized (this.queue) {
+ // Expurge the array only if a referenced
+ // object was marked as releasable
+ Reference<? extends T> ref = this.queue.poll();
+ if (ref!=null) {
+ return expurge();
+ }
+ return this.size;
+ }
+ }
+
+ /** Clean the references that was released.
+ *
+ * @return the size
+ */
+ @SuppressWarnings("unchecked")
+ public int expurge() {
+ synchronized(this.queue) {
+ Reference<? extends T> ref = this.queue.poll();
+ while (ref!=null) {
+ ref.clear();
+ ref = this.queue.poll();
+ }
+
+ // Clear the table
+ for(int i=this.size-1; i>=0; i--) {
+ ref = (Reference<T>)this.data[i];
+ assert(ref!=null);
+ if ((ref.isEnqueued())||(ref.get()==null)) {
+ ref.enqueue();
+ ref.clear();
+ System.arraycopy(
+ this.data, i+1,
+ this.data, i,
+ this.size - i - 1);
+ this.size --;
+ }
+ }
+
+ ref = this.queue.poll();
+ while (ref!=null) {
+ ref.clear();
+ ref = this.queue.poll();
+ }
+ return this.size;
+ }
+ }
+
+ /** Verify if the specified index is inside the array.
+ *
+ * @param index is the index totest
+ * @param allowLast indicates if the last elements is assumed to be valid or not.
+ */
+ protected void assertRange(int index, boolean allowLast) {
+ int size = expurgeNow();
+ if (index<0)
+ throw new IndexOutOfBoundsException("invalid negative value: "+Integer.toString(index)); //$NON-NLS-1$
+ if ((allowLast)&&(index>size))
+ throw new IndexOutOfBoundsException("index>"+size+": "+Integer.toString(index)); //$NON-NLS-1$ //$NON-NLS-2$
+ if ((!allowLast)&&(index>=size))
+ throw new IndexOutOfBoundsException("index>="+size+": "+Integer.toString(index)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ synchronized(this.queue) {
+ return expurgeNow();
+ }
+ }
+
+ /** {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T get(int index) {
+ synchronized(this.queue) {
+ T value;
+ do {
+ assertRange(index,false);
+ value = ((Reference<T>)this.data[index]).get();
+ }
+ while (value==null);
+ return unmaskNull(value);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T set(int index, T element) {
+ synchronized(this.queue) {
+ T oldValue;
+ Reference<T> ref;
+ do {
+ assertRange(index, false);
+ ref = (Reference<T>)this.data[index];
+ oldValue = ref.get();
+ }
+ while (oldValue==null);
+ ref.clear();
+ this.data[index] = createRef(element);
+ this.modCount++;
+ return unmaskNull(oldValue);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void add(int index, T element) {
+ synchronized(this.queue) {
+ assertRange(index,true);
+ ensureCapacity(this.size+1);
+ System.arraycopy(this.data, index, this.data, index+1, this.size-index);
+ this.data[index] = createRef(element);
+ this.size++;
+ this.modCount++;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public T remove(int index) {
+ synchronized(this.queue) {
+ T oldValue;
+ Reference<T> ref;
+ do {
+ assertRange(index, false);
+ ref = (Reference<T>)this.data[index];
+ oldValue = ref.get();
+ }
+ while (oldValue==null);
+ ref.clear();
+ System.arraycopy(this.data, index+1, this.data, index, this.size-index-1);
+ this.data[this.size-1] = null;
+ this.size--;
+ this.modCount++;
+ return unmaskNull(oldValue);
+ }
+ }
+
+}
Added: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakValueMap.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakValueMap.java (rev 0)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakValueMap.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,449 @@
+/*
+ * $Id: WeakValueMap.java,v 1.1 2007-02-20 08:52:37 sgalland Exp $
+ *
+ * Copyright (C) 2005-2007 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.util.ref;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ConcurrentModificationException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+/**
+ * A <tt>Map</tt> implementation with <em>weak values</em>. An entry in a
+ * <tt>WeakValueMap</tt> will automatically be removed when its value is no
+ * longer in ordinary use or null.
+ * <p>
+ * This class was inspirated from {@link WeakHashMap}
+ * <p>
+ * This class has a special flag which permits to control the
+ * way how the released references are expurged: {@link #isDeeplyExpurge()},
+ * {@link #setDeeplyExpurge(boolean)}. If this flag is <code>true</code>,
+ * all the released references will be immediately removed from the map even
+ * if they are not enqueued by the virtual machine (see {@link #expurge()}.
+ * If this flag is <code>false</code>,
+ * only the enqueued references will be removed from the map
+ * (see {@link #expurgeQueuedReferences()}.
+ * <p>
+ * If this map does not use a "deep expurge" of the released references,
+ * it could contains <code>null</code> values that corresponds to
+ * values that are released by the garbage collector. If a "deep expurge"
+ * is used, all the values released by the garbage collector will be
+ * removed from the map.
+ * <p>
+ * "Deep expurge" consumes much more time that "No deep expurge". This is the
+ * reason why this feature is not activated by default.
+ * <p>
+ * The "deep expurge" feature was added to fix the uncoherent behavior
+ * of the garbage collector which seems to not always enqueued the
+ * released values (sometimes the queue is empty even if a value was released).
+ *
+ * @param <K> is the type of the keys.
+ * @param <V> is the type of the values.
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+public class WeakValueMap<K,V> extends AbstractMap<K,V> implements Map<K,V> {
+
+ /** Defines the NULL object inside a WeakValueMap.
+ *
+ * @see #maskNull(Object)
+ */
+ protected static final Object NULL_VALUE = new Object();
+
+ /** Mask the null values given by the used of this map.
+ * <p>
+ * This method replaces the <code>null</code> value by
+ * the internal representation {@link #NULL_VALUE}.
+ *
+ * @param <V> is the type of the value.
+ * @param value is the value given by the user of this map.
+ * @return the internal representation of the value.
+ * @see #unmaskNull(Object)
+ */
+ @SuppressWarnings("unchecked")
+ protected static <V> V maskNull(V value) {
+ return (value==null) ? (V)NULL_VALUE : value;
+ }
+
+ /** Unmask the null values given by the used of this map.
+ * <p>
+ * This method replaces the internal representation
+ * {@link #NULL_VALUE} of null values by its user representation
+ * <code>null</code>.
+ *
+ * @param <V> is the type of the value.
+ * @param value is the value given by the user of this map.
+ * @return the internal representation of the value.
+ * @see #maskNull(Object)
+ */
+ protected static <V> V unmaskNull(V value) {
+ return (value==NULL_VALUE) ? null : value;
+ }
+
+ private boolean autoExpurge = false;
+ private final HashMap<K,Value<K,V>> map;
+ private final ReferenceQueue<V> queue = new ReferenceQueue<V>();
+ private final EntrySet entrySet;
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the specified initial
+ * capacity and load factor.
+ *
+ * @param initialCapacity the initial capacity
+ * @param loadFactor the load factor
+ * @throws IllegalArgumentException if the initial capacity is negative
+ * or the load factor is nonpositive
+ */
+ public WeakValueMap(int initialCapacity, float loadFactor) {
+ this.map = new HashMap<K,Value<K,V>>(initialCapacity, loadFactor);
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the specified initial
+ * capacity and the default load factor (0.75).
+ *
+ * @param initialCapacity the initial capacity.
+ * @throws IllegalArgumentException if the initial capacity is negative.
+ */
+ public WeakValueMap(int initialCapacity) {
+ this.map = new HashMap<K,Value<K,V>>(initialCapacity);
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs an empty <tt>HashMap</tt> with the default initial capacity
+ * (16) and the default load factor (0.75).
+ */
+ public WeakValueMap() {
+ this.map = new HashMap<K,Value<K,V>>();
+ this.entrySet = new EntrySet();
+ }
+
+ /**
+ * Constructs a new <tt>HashMap</tt> with the same mappings as the
+ * specified <tt>Map</tt>. The <tt>HashMap</tt> is created with
+ * default load factor (0.75) and an initial capacity sufficient to
+ * hold the mappings in the specified <tt>Map</tt>.
+ *
+ * @param m the map whose mappings are to be placed in this map
+ * @throws NullPointerException if the specified map is null
+ */
+ public WeakValueMap(Map<? extends K, ? extends V> m) {
+ this.map = new HashMap<K,Value<K,V>>();
+ this.entrySet = new EntrySet();
+ putAll(m);
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ */
+ protected void expurgeNow() {
+ if (this.autoExpurge)
+ expurge();
+ else
+ expurgeQueuedReferences();
+ }
+
+ /** Replies if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @return <code>true</code> is the values are deeply expurged when they
+ * are released from the moemory, otherwise <code>false</code>
+ */
+ public boolean isDeeplyExpurge() {
+ return this.autoExpurge;
+ }
+
+ /** Set if this map expurge all the released references
+ * even if they are not enqueued by the virtual machine
+ *
+ * @param deeplyExpurge must be <code>true</code> to
+ * expurge all the released values, otherwise <code>false</code>
+ * to expurge only the enqueued values.
+ * @return the old value of this flag
+ */
+ public boolean setDeeplyExpurge(boolean deeplyExpurge) {
+ boolean old = this.autoExpurge;
+ this.autoExpurge = deeplyExpurge;
+ return old;
+ }
+
+ /** Clean the references that was marked as released inside
+ * the queue.
+ */
+ public void expurgeQueuedReferences() {
+ Reference<? extends V> o;
+ while((o = this.queue.poll()) != null) {
+ if (o instanceof Value) {
+ this.map.remove(((Value<?,?>)o).getKey());
+ }
+ o.clear();
+ }
+ }
+
+ /** Clean the references that was released.
+ */
+ public void expurge() {
+ Reference<? extends V> o;
+
+ Iterator<Entry<K,Value<K,V>>> iter = this.map.entrySet().iterator();
+ Entry<K,Value<K,V>> entry;
+ Value<K,V> value;
+ while (iter.hasNext()) {
+ entry = iter.next();
+ if (entry!=null) {
+ value = entry.getValue();
+ if ((value!=null)&&
+ ((value.isEnqueued())||(value.get()==null))) {
+ value.enqueue();
+ value.clear();
+ }
+ }
+ }
+ entry = null;
+ value = null;
+
+ while((o = this.queue.poll()) != null) {
+ if (o instanceof Value) {
+ this.map.remove(((Value<?,?>)o).getKey());
+ }
+ o.clear();
+ }
+ }
+
+ /** Create a storage object that permits to put the specified
+ * elements inside this map.
+ *
+ * @param k is the key associated to the value
+ * @param v is the value
+ * @param queue is the reference queue to use
+ * @return the new storage object
+ */
+ protected Value<K,V> makeValue(K k, V v, ReferenceQueue<V> queue) {
+ return new Value<K,V>(k, v, queue);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V put(K key, V value) {
+ expurgeNow();
+ Value<K,V> ret = this.map.put(key, makeValue(key, value, this.queue));
+ if(ret == null) return null;
+ return ret.getValue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Entry<K,V>> entrySet() {
+ expurgeNow();
+ return this.entrySet;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ expurgeNow();
+ return super.equals(o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ expurgeNow();
+ return hashCode();
+ }
+
+ /**
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+ private class EntrySet extends AbstractSet<Entry<K,V>> implements Set<Entry<K,V>> {
+
+ private final Set<Entry<K,Value<K,V>>> baseSet;
+
+ /**
+ *
+ */
+ @SuppressWarnings("synthetic-access")
+ public EntrySet() {
+ this.baseSet = WeakValueMap.this.map.entrySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public Iterator<Entry<K, V>> iterator() {
+ final Iterator<Entry<K,Value<K,V>>> iter = this.baseSet.iterator();
+ return new Iterator<Entry<K,V>>() {
+ public boolean hasNext() {
+ expurgeNow();
+ return iter.hasNext();
+ }
+ public Entry<K,V> next() {
+ Entry<K, Value<K,V>> entry = iter.next();
+ if (entry==null) throw new ConcurrentModificationException();
+ Value<K,V> value = entry.getValue();
+ if (value==null) throw new ConcurrentModificationException();
+ return value;
+ }
+ public void remove() {
+ iter.remove();
+ }
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int size() {
+ expurgeNow();
+ return this.baseSet.size();
+ }
+
+ }
+
+ /**
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:37 $
+ */
+ private static class Value<K,V> extends WeakReference<V> implements Entry<K,V> {
+
+ private final K k;
+
+ /**
+ * @param k is the key.
+ * @param v is the value.
+ * @param queue is the memory-release listener.
+ */
+ Value(K k, V v, ReferenceQueue<V> queue) {
+ super(maskNull(v), queue);
+ this.k = k;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append('{');
+ K key = getKey();
+ buffer.append(key==null ? null : key.toString());
+ buffer.append('=');
+ if (isEnqueued()) {
+ buffer.append("Q#"); //$NON-NLS-1$
+ }
+ else {
+ buffer.append("P#"); //$NON-NLS-1$
+ }
+ V v = getValue();
+ buffer.append((v==null ? null : v.toString()));
+ buffer.append('}');
+ return buffer.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ public K getKey() {
+ return this.k;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ public V getValue() {
+ return unmaskNull(get());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ public V setValue(V o) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ Object val = getValue();
+ return (getKey()==null ? 0 : getKey().hashCode()) ^
+ (val==null ? 0 : val.hashCode());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param o {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof Entry) {
+ Entry<K,V> e = (Entry<K,V>)o;
+ Object e1val = getValue();
+ Object e2val = e.getValue();
+ return (getKey()==null ?
+ e.getKey()==null : getKey().equals(e.getKey())) &&
+ (e1val==null ? e2val==null : e1val.equals(e2val));
+ }
+ return false;
+ }
+
+ }
+
+}
Added: trunk/arakhneRefs/src/main/resources/AUTHORS
===================================================================
--- trunk/arakhneRefs/src/main/resources/AUTHORS (rev 0)
+++ trunk/arakhneRefs/src/main/resources/AUTHORS 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+Stephane GALLAND <galland@xxxxxxxxxxx>
Added: trunk/arakhneRefs/src/main/resources/COPYING
===================================================================
--- trunk/arakhneRefs/src/main/resources/COPYING (rev 0)
+++ trunk/arakhneRefs/src/main/resources/COPYING 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
Added: trunk/arakhneRefs/src/main/resources/Changelog
===================================================================
--- trunk/arakhneRefs/src/main/resources/Changelog (rev 0)
+++ trunk/arakhneRefs/src/main/resources/Changelog 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,17 @@
+arakhneRefs-3.0
+
+ * Add the class SoftValueMap
+
+ -- Stephane GALLAND <galland@xxxxxxxxxxx> Mon, 18 Feb 2008 20:04:24 +0100
+
+arakhneRefs-2.0
+
+ * Bug fixes inside the weak data structures
+
+ -- Stephane GALLAND <galland@xxxxxxxxxxx> Mon, 31 Dec 2007 12:24:59 +0100
+
+arakhneRefs-1.0
+
+ * First public release.
+
+ -- Stephane GALLAND <galland@xxxxxxxxxxx>
Added: trunk/arakhneRefs/src/main/resources/VERSION
===================================================================
--- trunk/arakhneRefs/src/main/resources/VERSION (rev 0)
+++ trunk/arakhneRefs/src/main/resources/VERSION 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+arakhneRefs 3.0
Added: trunk/arakhneVmutils/java/pom.xml
===================================================================
--- trunk/arakhneVmutils/java/pom.xml (rev 0)
+++ trunk/arakhneVmutils/java/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>arakhneVmutils-java</artifactId>
+ <packaging>jar</packaging>
+ <groupId>org.arakhne.afc</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Arakhnê VM Java utilities</name>
+ <description>Java libraries for the Arakhnê VM utilities dedicated to SUN©'s virtual machine.</description>
+
+ <parent>
+ <artifactId>arakhneVmutils</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+</project>
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AutoboxingUtil.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AutoboxingUtil.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AutoboxingUtil.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,224 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+/**
+ * This utility class provides a way to extend the Class class
+ * with autoboxing-compliant functions.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @since since JDK 1.5
+ */
+public class AutoboxingUtil {
+
+ /**
+ * Determines if the specified <code>Object</code> is assignment-compatible
+ * with the object represented by the <code>Class</code>. This method extends
+ * {@link Class#isInstance(Object)} with autoboxing support.
+ *
+ * @param type is the class against which the object must be test
+ * @param obj is the object to check
+ * @return <code>true</code> if <code>obj</code> is an instance of the type
+ * @see Class#isInstance(Object)
+ */
+ public static boolean isInstance(Class<?> type, Object obj) {
+ assert(type!=null);
+ if (obj==null) return false;
+
+ // Test according to the Class's behaviour
+ if (type.isInstance(obj)) return true;
+
+ // Test according to autoboxing
+ if (type.isPrimitive()
+ &&
+ type!=Void.class && type!=void.class) {
+
+ if (type==Boolean.class) return boolean.class.isInstance(obj);
+ if (type==boolean.class) return Boolean.class.isInstance(obj);
+
+ if (type==Character.class) return char.class.isInstance(obj);
+ if (type==char.class) return Character.class.isInstance(obj);
+
+ if (type==Byte.class) return byte.class.isInstance(obj);
+ if (type==byte.class) return Byte.class.isInstance(obj);
+
+ if (type==Short.class) return short.class.isInstance(obj);
+ if (type==short.class) return Short.class.isInstance(obj);
+
+ if (type==Integer.class) return int.class.isInstance(obj);
+ if (type==int.class) return Integer.class.isInstance(obj);
+
+ if (type==Long.class) return long.class.isInstance(obj);
+ if (type==long.class) return Long.class.isInstance(obj);
+
+ if (type==Float.class) return float.class.isInstance(obj);
+ if (type==float.class) return Float.class.isInstance(obj);
+
+ if (type==Double.class) return double.class.isInstance(obj);
+ if (type==double.class) return Double.class.isInstance(obj);
+
+ if (type==Void.class) return void.class.isInstance(obj);
+ if (type==void.class) return Void.class.isInstance(obj);
+
+ assert false: "Unsupported primitive type"; //$NON-NLS-1$
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Determines if the <code>assignmentTarget</code> object is either the same as,
+ * or is a superclass or superinterface of, the class or interface
+ * represented by the specified
+ * <code>assignementSource</code> parameter. This method extends
+ * {@link Class#isAssignableFrom(Class)} with autoboxing support.
+ *
+ * @param assignementTarget is the class that is tested to be a super class.
+ * @param assignementSource is the class that is tested to be a sub class.
+ * @return <code>true</code> if an object of the <var>assignementSource</var> type
+ * could be assigned to a variable of <var>assignementTarget</var> type,
+ * otherwise <code>false</code>.
+ */
+ public static boolean isAssignableFrom(Class<?> assignementTarget, Class<?> assignementSource) {
+ assert(assignementSource!=null);
+ assert(assignementTarget!=null);
+
+ // Test according to the Class's behaviour
+ if (assignementTarget.isAssignableFrom(assignementSource)) return true;
+
+ // Test according to autoboxing
+ if (assignementTarget.isPrimitive() && assignementSource.isPrimitive()
+ &&
+ assignementTarget!=Void.class && assignementTarget!=void.class
+ &&
+ assignementSource!=Void.class && assignementSource!=void.class) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /** Replies the type that corresponds to the specified class.
+ * If the name corresponds to a primitive type, the low-level type
+ * will be replied.
+ * This method extends
+ * {@link Class#forName(String)} with autoboxing support.
+ *
+ * @param name is the name of the class to load.
+ * @return the loaded class
+ * @throws ClassNotFoundException if name names an
+ * unknown class or primitive
+ */
+ public static Class<?> forName(String name) throws ClassNotFoundException {
+ if (name == null || "".equals(name) || "null".equals(name) || "void".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return void.class;
+ }
+ if ("boolean".equals(name)) { //$NON-NLS-1$
+ return boolean.class;
+ }
+ if ("byte".equals(name)) { //$NON-NLS-1$
+ return byte.class;
+ }
+ if ("char".equals(name)) { //$NON-NLS-1$
+ return char.class;
+ }
+ if ("double".equals(name)) { //$NON-NLS-1$
+ return double.class;
+ }
+ if ("float".equals(name)) { //$NON-NLS-1$
+ return float.class;
+ }
+ if ("int".equals(name)) { //$NON-NLS-1$
+ return int.class;
+ }
+ if ("long".equals(name)) { //$NON-NLS-1$
+ return long.class;
+ }
+ if ("short".equals(name)) { //$NON-NLS-1$
+ return short.class;
+ }
+ return Class.forName(name);
+ }
+
+ /** Replies the type that corresponds to the specified class.
+ * If the name corresponds to a primitive type, the low-level type
+ * will be replied.
+ * This method extends
+ * {@link Class#forName(String)} with autoboxing support.
+ *
+ * @param name is the name of the class to load.
+ * @param loader is the class loader to use.
+ * @return the loaded class
+ * @throws ClassNotFoundException if name names an
+ * unknown class or primitive
+ */
+ public static Class<?> forName(String name, ClassLoader loader) throws ClassNotFoundException {
+ return forName(name, true, loader);
+ }
+
+ /** Replies the type that corresponds to the specified class.
+ * If the name corresponds to a primitive type, the low-level type
+ * will be replied.
+ * This method extends
+ * {@link Class#forName(String)} with autoboxing support.
+ *
+ * @param name is the name of the class to load.
+ * @param typeInitialization must be <code>true</code> to initialize the type, <code>false</code> otherwise.
+ * @param loader is the class loader to use.
+ * @return the loaded class
+ * @throws ClassNotFoundException if name names an
+ * unknown class or primitive
+ */
+ public static Class<?> forName(String name, boolean typeInitialization, ClassLoader loader) throws ClassNotFoundException {
+ if (name == null || "".equals(name) || "null".equals(name) || "void".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return void.class;
+ }
+ if ("boolean".equals(name)) { //$NON-NLS-1$
+ return boolean.class;
+ }
+ if ("byte".equals(name)) { //$NON-NLS-1$
+ return byte.class;
+ }
+ if ("char".equals(name)) { //$NON-NLS-1$
+ return char.class;
+ }
+ if ("double".equals(name)) { //$NON-NLS-1$
+ return double.class;
+ }
+ if ("float".equals(name)) { //$NON-NLS-1$
+ return float.class;
+ }
+ if ("int".equals(name)) { //$NON-NLS-1$
+ return int.class;
+ }
+ if ("long".equals(name)) { //$NON-NLS-1$
+ return long.class;
+ }
+ if ("short".equals(name)) { //$NON-NLS-1$
+ return short.class;
+ }
+ return Class.forName(name, typeInitialization, loader);
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import sun.reflect.Reflection;
+
+/**
+ * This utility class provides a way to determine which class
+ * call a function.
+ * <p>
+ * It inspirated from the Sun's <code>sun.reflect.Reflection</code> class
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-04-25 13:08:07 $
+ */
+public class Caller {
+
+ /** Replies the class of the caller that invoked the function
+ * from which <code>GetCallerClass()</code> was invoked.
+ *
+ * @return the class of the caller that invoked the function
+ * from which <code>GetCallerClass()</code> was invoked.
+ */
+ public static Class<?> getCallerClass() {
+ // Parameter value:
+ // 0: is the top from the trace stack (Reflection.class)
+ // 1: is the second top from the trace stack (Caller.class)
+ // 2: is the third top of the trace stack ie, the caller of this function
+ // 3: is the fourth top of the trace stack ie, the caller of invoked function in step 2
+ return Reflection.getCallerClass(3);
+ }
+
+ /** Replies the class from the stack according to its level.
+ * <p>
+ * The given <var>level</var> permits to specify which class to reply:
+ * <ul>
+ * <li><code>0</code>: the class where is defined the function (<code>f<sub>0</sub></code>)
+ * that has called <code>getCallerClass()</code></li>
+ * <li><code>1</code>: the class where is defined the function (<code>f<sub>1</sub></code>)
+ * that has called <code>f<sub>0</sub></code></li>
+ * <li><code>1</code>: the class where is defined the function (<code>f<sub>2</sub></code>)
+ * that has called <code>f<sub>1</sub></code></li>
+ * <li>etc.</li>
+ * </ul>
+ *
+ * @param level is the desired level of the class
+ * @return the class from the call stack according to the given level.
+ */
+ public static Class<?> getCallerClass(int level) {
+ if (level<0) throw new IllegalArgumentException();
+ // Parameter value:
+ // 0: is the top from the trace stack (Reflection.class)
+ // 1: is the second top from the trace stack (Caller.class)
+ // 2: is the third top of the trace stack ie, the caller of this function
+ // 3: is the fourth top of the trace stack ie, the caller of invoked function in step 2
+ return Reflection.getCallerClass(level+2);
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClassLoaderFinder.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClassLoaderFinder.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClassLoaderFinder.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,101 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+/**
+ * This utility class permits to find the better class loader
+ * for your application.
+ * <p>
+ * It tries to find the preferred class loader registered with
+ * {@link #setPreferredClassLoader(ClassLoader)}.
+ * If none was found, the default class loader will be replied.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:43:41 $
+ */
+public final class ClassLoaderFinder {
+
+ private static volatile ClassLoader __dyn_loader = null;
+
+ /**
+ * Replies the better class loader.
+ * <p>
+ * It tries to find the preferred class loader.
+ * If none was found, the default class loader will be replied.
+ *
+ * @return the class loader
+ */
+ public static ClassLoader findClassLoader() {
+
+ if (__dyn_loader==null)
+ return ClassLoaderFinder.class.getClassLoader();
+ return __dyn_loader;
+ }
+
+ /**
+ * Set the preferred class loader.
+ *
+ * @param class_loader is the preferred class loader
+ */
+ public static void setPreferredClassLoader(ClassLoader class_loader) {
+ if (class_loader!=__dyn_loader) {
+ __dyn_loader = class_loader;
+ Thread[] threads = new Thread[Thread.activeCount()];
+ Thread.enumerate(threads);
+ for(Thread t : threads) {
+ if (t!=null)
+ t.setContextClassLoader(class_loader);
+ }
+ }
+ }
+
+ /**
+ * Pop the preferred class loader.
+ */
+ public static void popPreferredClassLoader() {
+ ClassLoader sysLoader = ClassLoaderFinder.class.getClassLoader();
+
+ if ((__dyn_loader==null)||
+ (__dyn_loader==sysLoader)) {
+ __dyn_loader = null;
+ Thread[] threads = new Thread[Thread.activeCount()];
+ Thread.enumerate(threads);
+ for(Thread t : threads) {
+ if (t!=null)
+ t.setContextClassLoader(sysLoader);
+ }
+ return;
+ }
+
+ ClassLoader parent = __dyn_loader.getParent();
+
+ __dyn_loader = (parent==sysLoader) ? null : parent;
+
+ Thread[] threads = new Thread[Thread.activeCount()];
+ Thread.enumerate(threads);
+ for(Thread t : threads) {
+ if (t!=null)
+ t.setContextClassLoader(parent);
+ }
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,582 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.SocketPermission;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.CodeSigner;
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.security.SecureClassLoader;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.NoSuchElementException;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes.Name;
+
+import sun.misc.Resource;
+import sun.misc.URLClassPath;
+import sun.net.www.ParseUtil;
+import sun.security.util.SecurityConstants;
+
+/** This class loader permits to load classes from
+ * a set of classpaths.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.2 $ $Date: 2007-04-10 08:35:33 $
+ */
+public class DynamicURLClassLoader extends SecureClassLoader {
+
+ /**
+ * The search path for classes and resources.
+ */
+ protected URLClassPath _ucp;
+
+ /**
+ * The context to be used when loading classes and resources
+ */
+ protected AccessControlContext _acc;
+
+ /**
+ * Constructs a new ClassPathClassLoader for the given URLs. The URLs will be
+ * searched in the order specified for classes and resources after first
+ * searching in the specified parent class loader. Any URL that ends with
+ * a '/' is assumed to refer to a directory. Otherwise, the URL is assumed
+ * to refer to a JAR file which will be downloaded and opened as needed.
+ *
+ * <p>If there is a security manager, this method first
+ * calls the security manager's <code>checkCreateClassLoader</code> method
+ * to ensure creation of a class loader is allowed.
+ *
+ * @param parent the parent class loader for delegation
+ * @param acc is the current access context
+ * @param urls the URLs from which to load classes and resources
+ * @exception SecurityException if a security manager exists and its
+ * <code>checkCreateClassLoader</code> method doesn't allow
+ * creation of a class loader.
+ * @see SecurityManager#checkCreateClassLoader
+ */
+ protected DynamicURLClassLoader(ClassLoader parent, AccessControlContext acc, URL... urls) {
+ super(parent);
+ // this is to make the stack depth consistent with 1.1
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkCreateClassLoader();
+ }
+ this._ucp = new URLClassPath(mergeClassPath(urls));
+ this._acc = acc;
+ }
+
+ /**
+ * Appends the specified URL to the list of URLs to search for
+ * classes and resources.
+ *
+ * @param url the URL to be added to the search path of URLs
+ */
+ public void addURL(final URL url) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ DynamicURLClassLoader.this._ucp.addURL(url);
+ return null;
+ }
+ }, this._acc);
+ }
+
+ /**
+ * Appends the specified URL to the list of URLs to search for
+ * classes and resources.
+ *
+ * @param urls the URLs to be added to the search path of URLs
+ */
+ public void addURLs(URL... urls) {
+ for (URL url : urls) {
+ addURL(url);
+ }
+ }
+
+ /**
+ * Appends the specified URL to the list of URLs to search for
+ * classes and resources.
+ *
+ * @param urls the URL to be added to the search path of URLs
+ */
+ public void removeURLs(URL... urls) {
+ HashSet<URL> set = new HashSet<URL>();
+ set.addAll(Arrays.asList(this._ucp.getURLs()));
+ set.removeAll(Arrays.asList(urls));
+ URL[] tab = new URL[set.size()];
+ set.toArray(tab);
+ this._ucp = new URLClassPath(tab);
+ tab = null;
+ }
+
+ /**
+ * Appends the specified URL to the list of URLs to search for
+ * classes and resources.
+ *
+ * @param url the URL to be added to the search path of URLs
+ */
+ public void removeURL(URL url) {
+ removeURLs(url);
+ }
+
+ /**
+ * Returns the search path of URLs for loading classes and resources.
+ * This includes the original list of URLs specified to the constructor,
+ * along with any URLs subsequently appended by the addURL() method.
+ * @return the search path of URLs for loading classes and resources.
+ */
+ public URL[] getURLs() {
+ return this._ucp.getURLs();
+ }
+
+ /**
+ * Finds and loads the class with the specified name from the URL search
+ * path. Any URLs referring to JAR files are loaded and opened as needed
+ * until the class is found.
+ *
+ * @param name the name of the class
+ * @return the resulting class
+ * @exception ClassNotFoundException if the class could not be found
+ */
+ @Override
+ protected Class<?> findClass(final String name) throws ClassNotFoundException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws ClassNotFoundException {
+ String path = name.replace('.', '/').concat(".class"); //$NON-NLS-1$
+ Resource res = DynamicURLClassLoader.this._ucp.getResource(path, false);
+ if (res != null) {
+ try {
+ return defineClass(name, res);
+ }
+ catch (IOException e) {
+ throw new ClassNotFoundException(name, e);
+ }
+ }
+ throw new ClassNotFoundException(name);
+ }
+ }, this._acc);
+ }
+ catch (java.security.PrivilegedActionException pae) {
+ throw (ClassNotFoundException) pae.getException();
+ }
+ }
+
+ /**
+ * Defines a Class using the class bytes obtained from the specified
+ * Resource. The resulting Class must be resolved before it can be
+ * used.
+ *
+ * @param name is the name of the class to define
+ * @param res is the resource from which the class byte-code could be obtained
+ * @return the loaded class.
+ * @throws IOException in case the byte-code was unavailable.
+ */
+ protected Class<?> defineClass(String name, Resource res) throws IOException {
+ int i = name.lastIndexOf('.');
+ URL url = res.getCodeSourceURL();
+ if (i != -1) {
+ String pkgname = name.substring(0, i);
+ // Check if package already loaded.
+ Package pkg = getPackage(pkgname);
+ Manifest man = res.getManifest();
+ if (pkg != null) {
+ // Package found, so check package sealing.
+ if (pkg.isSealed()) {
+ // Verify that code source URL is the same.
+ if (!pkg.isSealed(url)) {
+ throw new SecurityException(
+ "sealing violation: package " + pkgname + " is sealed"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ } else {
+ // Make sure we are not attempting to seal the package
+ // at this code source URL.
+ if ((man != null) && isSealed(pkgname, man)) {
+ throw new SecurityException(
+ "sealing violation: can't seal package " + pkgname + //$NON-NLS-1$
+ ": already loaded"); //$NON-NLS-1$
+ }
+ }
+ } else {
+ if (man != null) {
+ definePackage(pkgname, man, url);
+ } else {
+ definePackage(pkgname, null, null, null, null, null, null, null);
+ }
+ }
+ }
+ // Now read the class bytes and define the class
+ java.nio.ByteBuffer bb = res.getByteBuffer();
+ if (bb != null) {
+ // Use (direct) ByteBuffer:
+ CodeSigner[] signers = res.getCodeSigners();
+ CodeSource cs = new CodeSource(url, signers);
+ return defineClass(name, bb, cs);
+ }
+
+ byte[] b = res.getBytes();
+ // must read certificates AFTER reading bytes.
+ CodeSigner[] signers = res.getCodeSigners();
+ CodeSource cs = new CodeSource(url, signers);
+ return defineClass(name, b, 0, b.length, cs);
+
+ }
+
+ /**
+ * Defines a new package by name in this ClassLoader. The attributes
+ * contained in the specified Manifest will be used to obtain package
+ * version and sealing information. For sealed packages, the additional
+ * URL specifies the code source URL from which the package was loaded.
+ *
+ * @param name the package name
+ * @param man the Manifest containing package version and sealing
+ * information
+ * @param url the code source url for the package, or null if none
+ * @exception IllegalArgumentException if the package name duplicates
+ * an existing package either in this class loader or one
+ * of its ancestors
+ * @return the newly defined Package object
+ */
+ protected Package definePackage(String name, Manifest man, URL url)
+ throws IllegalArgumentException
+ {
+ String path = name.replace('.', '/').concat("/"); //$NON-NLS-1$
+ String specTitle = null, specVersion = null, specVendor = null;
+ String implTitle = null, implVersion = null, implVendor = null;
+ String sealed = null;
+ URL sealBase = null;
+
+ Attributes attr = man.getAttributes(path);
+ if (attr != null) {
+ specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
+ specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
+ specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
+ implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
+ implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
+ implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
+ sealed = attr.getValue(Name.SEALED);
+ }
+ attr = man.getMainAttributes();
+ if (attr != null) {
+ if (specTitle == null) {
+ specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
+ }
+ if (specVersion == null) {
+ specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
+ }
+ if (specVendor == null) {
+ specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
+ }
+ if (implTitle == null) {
+ implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
+ }
+ if (implVersion == null) {
+ implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
+ }
+ if (implVendor == null) {
+ implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
+ }
+ if (sealed == null) {
+ sealed = attr.getValue(Name.SEALED);
+ }
+ }
+ if ("true".equalsIgnoreCase(sealed)) { //$NON-NLS-1$
+ sealBase = url;
+ }
+ return definePackage(name, specTitle, specVersion, specVendor,
+ implTitle, implVersion, implVendor, sealBase);
+ }
+
+ /*
+ * Returns true if the specified package name is sealed according to the
+ * given manifest.
+ */
+ private boolean isSealed(String name, Manifest man) {
+ String path = name.replace('.', '/').concat("/"); //$NON-NLS-1$
+ Attributes attr = man.getAttributes(path);
+ String sealed = null;
+ if (attr != null) {
+ sealed = attr.getValue(Name.SEALED);
+ }
+ if (sealed == null) {
+ if ((attr = man.getMainAttributes()) != null) {
+ sealed = attr.getValue(Name.SEALED);
+ }
+ }
+ return "true".equalsIgnoreCase(sealed); //$NON-NLS-1$
+ }
+
+ /**
+ * Finds the resource with the specified name on the URL search path.
+ *
+ * @param name the name of the resource
+ * @return a <code>URL</code> for the resource, or <code>null</code>
+ * if the resource could not be found.
+ */
+ @Override
+ public URL findResource(final String name) {
+ /*
+ * The same restriction to finding classes applies to resources
+ */
+ URL url =
+ AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return DynamicURLClassLoader.this._ucp.findResource(name, true);
+ }
+ }, this._acc);
+
+ return url != null ? this._ucp.checkURL(url) : null;
+ }
+
+ /**
+ * Returns an Enumeration of URLs representing all of the resources
+ * on the URL search path having the specified name.
+ *
+ * @param name the resource name
+ * @exception IOException if an I/O exception occurs
+ * @return an <code>Enumeration</code> of <code>URL</code>s
+ */
+ @Override
+ public Enumeration<URL> findResources(final String name) throws IOException {
+ final Enumeration<?> e = this._ucp.findResources(name, true);
+
+ return new Enumeration<URL>() {
+ private URL url = null;
+
+ private boolean next() {
+ if (this.url != null) {
+ return true;
+ }
+ do {
+ URL u = AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ if (!e.hasMoreElements())
+ return null;
+ return (URL)e.nextElement();
+ }
+ }, DynamicURLClassLoader.this._acc);
+ if (u == null) break;
+ this.url = DynamicURLClassLoader.this._ucp.checkURL(u);
+ }
+ while (this.url == null);
+
+ return (this.url != null);
+ }
+
+ public URL nextElement() {
+ if (!next()) {
+ throw new NoSuchElementException();
+ }
+ URL u = this.url;
+ this.url = null;
+ return u;
+ }
+
+ public boolean hasMoreElements() {
+ return next();
+ }
+ };
+ }
+
+ /**
+ * Returns the permissions for the given codesource object.
+ * The implementation of this method first calls super.getPermissions
+ * and then adds permissions based on the URL of the codesource.
+ * <p>
+ * If the protocol is "file"
+ * and the path specifies a file, then permission to read that
+ * file is granted. If protocol is "file" and the path is
+ * a directory, permission is granted to read all files
+ * and (recursively) all files and subdirectories contained in
+ * that directory.
+ * <p>
+ * If the protocol is not "file", then
+ * to connect to and accept connections from the URL's host is granted.
+ * @param codesource the codesource
+ * @return the permissions granted to the codesource
+ */
+ @Override
+ protected PermissionCollection getPermissions(CodeSource codesource) {
+ PermissionCollection perms = super.getPermissions(codesource);
+
+ URL url = codesource.getLocation();
+
+ Permission p;
+ URLConnection urlConnection;
+
+ try {
+ urlConnection = url.openConnection();
+ p = urlConnection.getPermission();
+ }
+ catch (java.io.IOException ioe) {
+ p = null;
+ urlConnection = null;
+ }
+
+ if ((p!=null)&&(p instanceof FilePermission)) {
+ // if the permission has a separator char on the end,
+ // it means the codebase is a directory, and we need
+ // to add an additional permission to read recursively
+ String path = p.getName();
+ if (path.endsWith(File.separator)) {
+ path += "-"; //$NON-NLS-1$
+ p = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
+ }
+ }
+ else if ((p == null) && (url.getProtocol().equals("file"))) { //$NON-NLS-1$
+ String path = url.getFile().replace('/', File.separatorChar);
+ path = ParseUtil.decode(path);
+ if (path.endsWith(File.separator))
+ path += "-"; //$NON-NLS-1$
+ p = new FilePermission(path, SecurityConstants.FILE_READ_ACTION);
+ }
+ else {
+ URL locUrl = url;
+ if (urlConnection instanceof JarURLConnection) {
+ locUrl = ((JarURLConnection)urlConnection).getJarFileURL();
+ }
+ String host = locUrl.getHost();
+ if (host == null)
+ host = "localhost"; //$NON-NLS-1$
+ p = new SocketPermission(host,
+ SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION);
+ }
+
+ // make sure the person that created this class loader
+ // would have this permission
+
+ final SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ final Permission fp = p;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() throws SecurityException {
+ sm.checkPermission(fp);
+ return null;
+ }
+ }, this._acc);
+ }
+ perms.add(p);
+
+ return perms;
+ }
+
+ /**
+ * Creates a new instance of DynamicURLClassLoader for the specified
+ * URLs and parent class loader. If a security manager is
+ * installed, the <code>loadClass</code> method of the URLClassLoader
+ * returned by this method will invoke the
+ * <code>SecurityManager.checkPackageAccess</code> method before
+ * loading the class.
+ *
+ * @param parent the parent class loader for delegation
+ * @param urls the URLs to search for classes and resources
+ * @return the resulting class loader
+ */
+ public static DynamicURLClassLoader newInstance(final ClassLoader parent, final URL... urls) {
+ // Save the caller's context
+ final AccessControlContext acc = AccessController.getContext();
+ // Need a privileged block to create the class loader
+ DynamicURLClassLoader ucl =
+ AccessController.doPrivileged(new PrivilegedAction<DynamicURLClassLoader>() {
+ public DynamicURLClassLoader run() {
+ // Now set the context on the loader using the one we saved,
+ // not the one inside the privileged block...
+ return new FactoryDynamicURLClassLoader(parent, acc, urls);
+ }
+ });
+ return ucl;
+ }
+
+ /**
+ * Merge the specified URLs to the current classpath.
+ */
+ private static URL[] mergeClassPath(URL... urls) {
+ String path = System.getProperty("java.class.path"); //$NON-NLS-1$
+ String separator = System.getProperty("path.separator"); //$NON-NLS-1$
+ String[] parts = path.split(separator);
+ URL[] u = new URL[parts.length+urls.length];
+ for(int i=0; i<parts.length; i++) {
+ try {
+ u[i] = new File(parts[i]).toURI().toURL();
+ }
+ catch (MalformedURLException _) {
+ // ignore exception
+ }
+ }
+ System.arraycopy(urls,0,u,parts.length,urls.length);
+ return u;
+ }
+
+ /**
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.2 $ $Date: 2007-04-10 08:35:33 $
+ */
+ protected final static class FactoryDynamicURLClassLoader extends DynamicURLClassLoader {
+
+ /**
+ * @param parent is the parent class loader.
+ * @param acc is the accessible context.
+ * @param urls is the list of urls to insert inside the class loading path.
+ */
+ protected FactoryDynamicURLClassLoader(ClassLoader parent, AccessControlContext acc, URL... urls) {
+ super(parent,acc,urls);
+ }
+
+ /** {@inheritDoc}
+ *
+ * @param name {@inheritDoc}
+ * @param resolve {@inheritDoc}
+ * @return {@inheritDoc}
+ * @throws ClassNotFoundException {@inheritDoc}
+ */
+ @Override
+ public final synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ // First check if we have permission to access the package. This
+ // should go away once we've added support for exported packages.
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ int i = name.lastIndexOf('.');
+ if (i != -1) {
+ sm.checkPackageAccess(name.substring(0, i));
+ }
+ }
+ return super.loadClass(name, resolve);
+ }
+
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,391 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+
+
+/** An utility class that permits to deal with filenames.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.4 $ $Date: 2007-05-04 07:21:05 $
+ */
+public class FileSystem {
+
+ /** Replies if the current operating system uses case-sensitive filename.
+ *
+ * @return <code>true</code> if the filenames on the current file system are case sensitive,
+ * otherwise <code>false</code>
+ */
+ public static boolean isCaseSensitiveFilenameSystem() {
+ switch(OperatingSystem.getCurrentOS()) {
+ case AIX:
+ case BSD:
+ case FREEBSD:
+ case NETBSD:
+ case OPENBSD:
+ case LINUX:
+ case SOLARIS:
+ case HPUX:
+ return true;
+ case MACOSX:
+ case WIN:
+ case OTHER:
+ default:
+ return false;
+ }
+ }
+
+ /** Replies the character used to separate the basename and the file extension.
+ *
+ * @return the character used to separate the basename and the file extension.
+ */
+ public static char getFileExtensionCharacter() {
+ return '.';
+ }
+
+ /** Replies the dirname of the specified file.
+ *
+ * @param filename is the name to parse.
+ * @return the dirname of the specified file.
+ */
+ public static String dirname(String filename) {
+ if (filename==null) return null;
+ return new File(filename).getParent();
+ }
+
+ /** Replies the basename of the specified file with the extension.
+ *
+ * @param filename is the name to parse.
+ * @return the basename of the specified file with the extension.
+ */
+ public static String largeBasename(String filename) {
+ if (filename==null) return null;
+ return new File(filename).getName();
+ }
+
+ /** Reply the basename of the specified file without the last extension.
+ *
+ * @param filename is the name to parse.
+ * @return the basename of the specified file without the last extension.
+ */
+ public static String basename(String filename) {
+ if (filename==null) return null;
+ String largeBasename = new File(filename).getName();
+ int idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
+ if (idx<=0) return largeBasename;
+ return largeBasename.substring(0,idx);
+ }
+
+ /** Reply the basename of the specified file without the last extension.
+ *
+ * @param filename is the name to parse.
+ * @return the basename of the specified file without the last extension.
+ */
+ public static String basename(File filename) {
+ if (filename==null) return null;
+ return basename(filename.getAbsolutePath());
+ }
+
+ /** Reply the basename of the specified file without all the extensions.
+ *
+ * @param filename is the name to parse.
+ * @return the basename of the specified file without all the extensions.
+ */
+ public static String shortBasename(String filename) {
+ if (filename==null) return null;
+ String largeBasename = new File(filename).getName();
+ int idx = largeBasename.indexOf(getFileExtensionCharacter());
+ if (idx<=0) return largeBasename;
+ return largeBasename.substring(0,idx);
+ }
+
+ /** Reply the basename of the specified file without all the extensions.
+ *
+ * @param filename is the name to parse.
+ * @return the basename of the specified file without all the extensions.
+ */
+ public static String shortBasename(File filename) {
+ if (filename==null) return null;
+ return shortBasename(filename.getAbsolutePath());
+ }
+
+ /** Reply the extension of the specified file.
+ *
+ * @param filename is the name to parse.
+ * @return the extension of the specified file
+ */
+ public static String extension(String filename) {
+ if (filename==null) return null;
+ String largeBasename = new File(filename).getName();
+ int idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
+ if (idx<=0) return ""; //$NON-NLS-1$
+ return largeBasename.substring(idx+1);
+ }
+
+ /** Reply the extension of the specified file.
+ *
+ * @param filename is the name to parse.
+ * @return the extension of the specified file
+ */
+ public static String extension(File filename) {
+ if (filename==null) return null;
+ return extension(filename.getAbsolutePath());
+ }
+
+ /** Reply all the extensions of the specified file.
+ *
+ * @param filename is the name to parse.
+ * @return the extensions of the specified file
+ */
+ public static String[] extensions(String filename) {
+ if (filename==null) return new String[0];
+ String largeBasename = new File(filename).getName();
+ String[] parts = largeBasename.split("["+getFileExtensionCharacter()+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (parts.length<=1) return new String[0];
+ String[] r = new String[parts.length-1];
+ System.arraycopy(parts, 1, r, 0, r.length);
+ return r;
+ }
+
+ /** Reply all the extensions of the specified file.
+ *
+ * @param filename is the name to parse.
+ * @return the extensions of the specified file
+ */
+ public static String[] extensions(File filename) {
+ if (filename==null) return new String[0];
+ return extensions(filename.getAbsolutePath());
+ }
+
+ /** Replies the parts of a path.
+ *
+ * @param filename is the name to parse.
+ * @return the parts of a path.
+ */
+ public static String[] split(String filename) {
+ if (filename==null) return new String[0];
+ return filename.split("["+File.separatorChar+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** Replies the parts of a path.
+ *
+ * @param filename is the name to parse.
+ * @return the parts of a path.
+ */
+ public static String[] split(File filename) {
+ if (filename==null) return new String[0];
+ return split(filename.getAbsolutePath());
+ }
+
+ /** Join the parts of a path with the current OS directory separator.
+ *
+ * @param elements are the path's elements to join.
+ * @return the result of the join of the path's elements.
+ */
+ public static String join(String... elements) {
+ StringBuffer buf = new StringBuffer();
+ for (String elt : elements) {
+ if (buf.length()>0) buf.append(File.separatorChar);
+ buf.append(elt);
+ }
+ return buf.toString();
+ }
+
+ /** Replies if the specified file has the specified extension.
+ * <p>
+ * The test is dependent of the case-sensitive attribute of operating system.
+ *
+ * @param filename is the filename to parse
+ * @param extension is the extension to test.
+ * @return <code>true</code> if the given filename has the given extension,
+ * otherwise <code>false</code>
+ */
+ public static boolean hasExtension(String filename, String extension) {
+ if (filename==null) return false;
+ String ext = extension(filename);
+ if (ext==null) return false;
+ if (isCaseSensitiveFilenameSystem())
+ return ext.equals(extension);
+ return ext.equalsIgnoreCase(extension);
+ }
+
+ /** Replies if the specified file has the specified extension.
+ * <p>
+ * The test is dependent of the case-sensitive attribute of operating system.
+ *
+ * @param filename is the filename to parse
+ * @param extension is the extension to test.
+ * @return <code>true</code> if the given filename has the given extension,
+ * otherwise <code>false</code>
+ */
+ public static boolean hasExtension(File filename, String extension) {
+ if (filename==null) return false;
+ return hasExtension(filename.getName(), extension);
+ }
+
+ /** Remove the extension from the specified filename.
+ *
+ * @param filename is the filename to parse.
+ * @return the filename without the extension.
+ */
+ public static String removeExtension(String filename) {
+ if (filename==null) return null;
+ int idx = filename.lastIndexOf(getFileExtensionCharacter());
+ if (idx<=0) return filename;
+ return filename.substring(0,idx);
+ }
+
+ /** Replace the extension of the specified filename by the given extension.
+ * If the filename has no extension, the specifiedone will be added.
+ *
+ * @param filename is the filename to parse.
+ * @param extension is the extension to remove if it is existing.
+ * @return the filename without the extension.
+ */
+ public static String replaceExtension(String filename, String extension) {
+ if (filename==null) return null;
+ int idx = filename.lastIndexOf(getFileExtensionCharacter());
+ StringBuffer buf = new StringBuffer();
+ if (idx<=0) buf.append(filename);
+ else buf.append(filename.substring(0, idx));
+ buf.append(getFileExtensionCharacter());
+ buf.append(extension);
+ return buf.toString();
+ }
+
+ /** Replace the extension of the specified filename by the given extension.
+ * If the filename has no extension, the specifiedone will be added.
+ *
+ * @param filename is the filename to parse.
+ * @param extension is the extension to remove if it is existing.
+ * @return the filename without the extension.
+ */
+ public static File replaceExtension(File filename, String extension) {
+ if (filename==null) return null;
+ return new File(replaceExtension(filename.getAbsolutePath(), extension));
+ }
+
+ /** Copy the first file into the second file.
+ * <p>
+ * The content of the second file will be lost.
+ * This copy function allows to do a copy between two different
+ * partitions.
+ *
+ * @param in is the file to copy.
+ * @param out is the target file
+ * @throws IOException in case of error.
+ */
+ public static void fileCopy(File in, File out) throws IOException {
+ FileChannel inChannel = new FileInputStream(in).getChannel();
+ FileChannel outChannel = new FileOutputStream(out).getChannel();
+ try {
+ // apparently has trouble copying large files on Windows
+ if (OperatingSystem.WIN.isCurrentOS()) {
+ // magic number for Windows, 64Mb - 32Kb
+ int maxCount = (64 * 1024 * 1024) - (32 * 1024);
+ long size = inChannel.size();
+ long position = 0;
+ while ( position < size ) {
+ position += inChannel.transferTo( position, maxCount, outChannel );
+ }
+ }
+ else {
+ inChannel.transferTo(0, inChannel.size(), outChannel);
+ }
+ }
+ finally {
+ if (inChannel!=null) inChannel.close();
+ if (outChannel!=null) outChannel.close();
+ }
+ }
+
+ /** Replies the user home directory.
+ *
+ * @return the home directory of the current user.
+ * @throws FileNotFoundException
+ */
+ public static File getUserHomeDirectory() throws FileNotFoundException {
+ String userHome = System.getProperty("user.home"); //$NON-NLS-1$
+ if (userHome!=null) {
+ File file = new File(userHome);
+ if (file.isDirectory()) return file;
+ }
+ throw new FileNotFoundException();
+ }
+
+ /** Replies the user home directory.
+ *
+ * @return the home directory of the current user.
+ */
+ public static String getUserHomeDirectoryName() {
+ return System.getProperty("user.home"); //$NON-NLS-1$
+ }
+
+ /** Replies the user configuration directory for the specified software.
+ *
+ * @param software is the name of the concerned software.
+ * @return the configuration directory of the current user.
+ */
+ public static File getUserConfigurationDirectoryFor(String software) {
+ try {
+ File userHome = getUserHomeDirectory();
+ OperatingSystem os = OperatingSystem.getCurrentOS();
+ if (os.isUnixCompliant()) {
+ return new File(userHome, "."+software); //$NON-NLS-1$
+ }
+ else if (os==OperatingSystem.WIN) {
+ String userName = System.getProperty("user.name"); //$NON-NLS-1$
+ if (userName!=null && !"".equals(userName)) { //$NON-NLS-1$
+ return new File(join(
+ "C:","Documents and Settings", //$NON-NLS-1$//$NON-NLS-2$
+ userName,
+ "Local Settings","Application Data", //$NON-NLS-1$//$NON-NLS-2$
+ software));
+ }
+ }
+ return new File(userHome,software);
+ }
+ catch(FileNotFoundException _) {
+ //
+ }
+ return null;
+ }
+
+ /** Replies the user configuration directory for the specified software.
+ *
+ * @param software is the name of the concerned software.
+ * @return the configuration directory of the current user.
+ */
+ public static String getUserConfigurationDirectoryNameFor(String software) {
+ File directory = getUserConfigurationDirectoryFor(software);
+ if (directory!=null) return directory.getAbsolutePath();
+ return null;
+ }
+
+}
+
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/LibraryLoader.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,200 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * This class provides more generic means for loading
+ * dynamical libraries.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:43:41 $
+ */
+public class LibraryLoader {
+
+ /**
+ * 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.
+ * <p>
+ * The call <code>LibraryLoader.load(name)</code> is effectively equivalent
+ * to the call:
+ * <blockquote><pre>
+ * System.load(name)
+ * </pre></blockquote>
+ *
+ * @param filename is the file to load.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkLink</code> method doesn't allow
+ * loading of the specified dynamic library
+ * @throws UnsatisfiedLinkError if the file does not exist.
+ * @throws NullPointerException if <code>filename</code> is
+ * <code>null</code>
+ * @see java.lang.System#load(java.lang.String)
+ */
+ public static void load(String filename) {
+ System.load(filename);
+ }
+
+ /**
+ * Loads the system library specified by the <code>libname</code>
+ * argument. The manner in which a library name is mapped to the
+ * actual system library is system dependent.
+ * <p>
+ * The call <code>LibraryLoader.loadLibrary(name)</code> is effectively
+ * equivalent to the call
+ * <blockquote><pre>
+ * System.loadLibrary(name)
+ * </pre></blockquote>
+ *
+ * @param libname the name of the library.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkLink</code> method doesn't allow
+ * loading of the specified dynamic library
+ * @throws UnsatisfiedLinkError if the library does not exist.
+ * @throws NullPointerException if <code>libname</code> is
+ * <code>null</code>
+ * @see java.lang.System#loadLibrary(java.lang.String)
+ */
+ public static void loadLibrary(String libname) {
+ System.loadLibrary(libname);
+ }
+
+ /**
+ * 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.
+ * <p>
+ * The call <code>LibraryLoader.load(name)</code> is effectively equivalent
+ * to the call:
+ * <blockquote><pre>
+ * System.load(name.getAbsolutePath())
+ * </pre></blockquote>
+ *
+ * @param filename is the file to load.
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkLink</code> method doesn't allow
+ * loading of the specified dynamic library
+ * @throws UnsatisfiedLinkError if the file does not exist.
+ * @throws NullPointerException if <code>filename</code> is
+ * <code>null</code>
+ * @see java.lang.System#load(java.lang.String)
+ */
+ public static void load(File filename) {
+ System.load(filename.getAbsolutePath());
+ }
+
+ /** Replies the URL for the specified library.
+ *
+ * @param libName is the name of the library
+ * @return the URL where the specified library was located.
+ */
+ public static URL findLibraryURL(String libName) {
+ return findLibraryURL(null,libName);
+ }
+
+ /** Replies the URL for the specified library.
+ * <p>
+ * The call <code>LibraryLoader.findLibraryURL(path,name)</code> is effectively equivalent
+ * to the call:
+ * <blockquote><pre>
+ * getClassLoader().getResource(path+System.mapLibraryName(name))
+ * </pre></blockquote>
+ *
+ * @param path is the resource's path where the library was located.
+ * @param libName is the name of the library
+ * @return the URL where the specified library was located.
+ */
+ public static URL findLibraryURL(String path, String libName) {
+ String realLibName = System.mapLibraryName(libName);
+ ClassLoader cl = ClassLoaderFinder.findClassLoader();
+ if (cl==null) cl = LibraryLoader.class.getClassLoader();
+ if (path==null) path = ""; //$NON-NLS-1$
+ else if ((path.length()>0)&&(!path.endsWith("/"))) { //$NON-NLS-1$
+ path += "/"; //$NON-NLS-1$
+ }
+ return cl.getResource(path+realLibName);
+ }
+
+ /**
+ * 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.
+ *
+ * @param filename is the file to load.
+ * @throws IOException
+ * @throws SecurityException if a security manager exists and its
+ * <code>checkLink</code> method doesn't allow
+ * loading of the specified dynamic library
+ * @throws UnsatisfiedLinkError if the file does not exist.
+ * @throws NullPointerException if <code>filename</code> is
+ * <code>null</code>
+ * @see java.lang.System#load(java.lang.String)
+ */
+ public static void load(URL filename) throws IOException {
+ if (filename.getProtocol().equalsIgnoreCase("file")) { //$NON-NLS-1$
+ try {
+ System.load(new File(filename.toURI()).getAbsolutePath());
+ }
+ catch (URISyntaxException e) {
+ throw new FileNotFoundException(filename.toExternalForm());
+ }
+ }
+ else {
+ // Create a tmp file to receive the library code.
+ String libName = System.mapLibraryName("javaDynLib"); //$NON-NLS-1$
+ String suffix = ".dll"; //$NON-NLS-1$
+ String prefix = "javaDynLib"; //$NON-NLS-1$
+ int pos = libName.lastIndexOf('.');
+ if (pos>=0) {
+ suffix = libName.substring(pos);
+ prefix = libName.substring(0,pos);
+ }
+ File f = File.createTempFile(prefix,suffix);
+
+ // Copy the library code into the local file
+ FileOutputStream outs = new FileOutputStream(f);
+ InputStream ins = filename.openStream();
+ byte[] buffer = new byte[2048];
+ int lu;
+ while ((lu=ins.read(buffer))>0) {
+ outs.write(buffer,0,lu);
+ }
+ ins.close();
+ outs.close();
+
+ // Load the library from the local file
+ System.load(f.getAbsolutePath());
+
+ // Delete local file
+ f.deleteOnExit();
+ }
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,209 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import java.net.URL;
+
+/**
+ * This is a list of supported operating system.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.2 $ $Date: 2007-04-26 11:32:44 $
+ */
+public enum OperatingSystem {
+
+ /**
+ * Windows®.
+ */
+ WIN,
+
+ /**
+ * Linux distribution.
+ */
+ LINUX,
+
+ /**
+ * Solaris®.
+ */
+ SOLARIS,
+
+ /**
+ * Mac OS X®.
+ */
+ MACOSX,
+
+ /**
+ * Free BSD.
+ */
+ FREEBSD,
+
+ /**
+ * Net BSD.
+ */
+ NETBSD,
+
+ /**
+ * Standard BSD.
+ */
+ BSD,
+
+ /**
+ * Open BSD.
+ */
+ OPENBSD,
+
+ /**
+ * AIX®.
+ */
+ AIX,
+
+ /**
+ * HPUX®.
+ */
+ HPUX,
+
+ /**
+ * Unknown operating systems.
+ */
+ OTHER;
+
+ /** Replies if the current OperatingSystem constant is corresponding
+ * to the current operating system.
+ *
+ * @return <code>true</code> if the current operating system corresponds to this constant,
+ * otherwise <code>false</code>
+ */
+ public boolean isCurrentOS() {
+ return getCurrentOS()==this;
+ }
+
+ /** Replies of this OS is Unix compliant.
+ *
+ * @return <code>true</code> if this constant corresponds to a Unix-like operating system,
+ * otherwise <code>false</code>
+ */
+ public boolean isUnixCompliant() {
+ switch(this) {
+ case AIX:
+ case BSD:
+ case FREEBSD:
+ case HPUX:
+ case LINUX:
+ case MACOSX:
+ case NETBSD:
+ case OPENBSD:
+ case SOLARIS:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+
+ /** Replies the name of the current OS.
+ *
+ * @return the name of the current operating system.
+ * @see System#getProperty(java.lang.String)
+ */
+ public static String getCurrentOSName() {
+ return System.getProperty("os.name"); //$NON-NLS-1$
+ }
+
+ /** Replies the current operating system.
+ *
+ * @return the current operating system constant.
+ */
+ public static OperatingSystem getCurrentOS() {
+ 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;
+ }
+ }
+
+ /** Get the OS serial number.
+ *
+ * @return the serial number associated to the current operating system.
+ */
+ public static native String getOSSerialNumber();
+
+ /** Get the OS UUID.
+ *
+ * @return an unique identifier for the current operating system.
+ */
+ public static native String getOSUUID();
+
+ static {
+ String libName = "josuuid"; //$NON-NLS-1$
+ String realLibName = System.mapLibraryName(libName);
+ try {
+ ClassLoader clsLoader = ClassLoaderFinder.findClassLoader();
+ URL libURL = clsLoader.getResource("fr/utbm/set/vmutil/"+realLibName); //$NON-NLS-1$
+ //For debuging purpose only:
+ //URL libURL = new File("/home/stephane/workspace/jlauncherlib/Release/"+realLibName).toURL(); //$NON-NLS-1$
+ if (libURL!=null) {
+ LibraryLoader.load(libURL);
+ }
+ }
+ catch (Throwable e) {
+ //
+ }
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/VMCommandLine.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/VMCommandLine.java (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/VMCommandLine.java 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,373 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2004-2008 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;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+/**
+ * This utility class permits to get the java command line for the current VM.
+ *
+ * @author Stéphane GALLAND <stephane.galland@xxxxxxx>
+ * @version $Name: $ $Revision: 1.1 $ $Date: 2007-02-20 08:52:28 $
+ */
+public class VMCommandLine {
+
+ private static Class<?> __classToLaunch = null;
+ private static boolean analyzed = false;
+ private static SortedMap<String,String> __options = null;
+ private static String[] __parameters = null;
+
+ /** Replies a binary executable filename depending of the current platform.
+ *
+ * @param name is the name which must be converted into a binary executable filename.
+ * @return the binary executable filename.
+ */
+ public static String getExecutableFilename(String name) {
+ if (OperatingSystem.WIN.isCurrentOS()) name += ".exe"; //$NON-NLS-1$
+ return name;
+ }
+
+ /** Replies the current java VM binary.
+ *
+ * @return the binary executable filename that was used to launch the virtual machine.
+ */
+ public static String getVMBinary() {
+ String java_home = System.getProperty("java.home"); //$NON-NLS-1$
+ File bin_dir = new File(new File(java_home),"bin"); //$NON-NLS-1$
+ if (bin_dir.isDirectory()) {
+ File exec = new File(bin_dir,getExecutableFilename("javaw")); //$NON-NLS-1$
+ if (exec.isFile()) {
+ return exec.getAbsolutePath();
+ }
+ exec = new File(bin_dir,getExecutableFilename("java")); //$NON-NLS-1$
+ if (exec.isFile()) {
+ return exec.getAbsolutePath();
+ }
+ }
+ return null;
+ }
+
+ /** Run a new VM with the class path of the current VM.
+ *
+ * @param class_to_launch is the class to launch.
+ * @param additional_params is the list of additional parameters
+ * @return the process that is running the new virtual machine, neither <code>null</code>
+ * @throws IOException
+ */
+ public static Process launchVM(Class<?> class_to_launch, String... additional_params) throws IOException {
+ String java_bin = getVMBinary();
+ if (java_bin==null) throw new FileNotFoundException("java"); //$NON-NLS-1$
+ long totalMemory = Runtime.getRuntime().maxMemory() / 1024;
+ String classpath = System.getProperty("java.class.path"); //$NON-NLS-1$
+ String user_dir = System.getProperty("user.dir"); //$NON-NLS-1$
+ String[] params = new String[additional_params.length+5];
+ params[0] = java_bin;
+ params[1] = "-Xmx"+totalMemory+"k"; //$NON-NLS-1$ //$NON-NLS-2$
+ params[2] = "-classpath"; //$NON-NLS-1$
+ params[3] = classpath;
+ params[4] = class_to_launch.getCanonicalName();
+ System.arraycopy(additional_params,0,params,5,additional_params.length);
+ return Runtime.getRuntime().exec(params,null,new File(user_dir));
+ }
+
+ /** Save parameters that permit to relaunch a VM with
+ * {@link #relaunchVM()}.
+ *
+ * @param class_to_launch is the class which contains a <code>main</code>.
+ * @param parameters is the parameters to pass to the <code>main</code>.
+ */
+ public static void saveVMParameters(Class<?> class_to_launch, String... parameters) {
+ __classToLaunch = class_to_launch;
+ __parameters = parameters;
+ if (__options!=null) __options.clear();
+ __options = null;
+ analyzed = false;
+ }
+
+ /** Save parameters that permit to relaunch a VM with
+ * {@link #relaunchVM()}.
+ *
+ * @param class_to_launch is the class which contains a <code>main</code>.
+ * @param parameters is the parameters to pass to the <code>main</code>.
+ */
+ public static void saveVMParametersIfNotSet(Class<?> class_to_launch, String... parameters) {
+ if (__classToLaunch==null) {
+ saveVMParameters(class_to_launch, parameters);
+ }
+ }
+
+ /** Launch a VM with the same parameters as ones saved by
+ * {@link #saveVMParameters(Class, String[])}.
+ *
+ * @return the process that is running the new virtual machine, neither <code>null</code>
+ * @throws IOException
+ */
+ public static Process relaunchVM() throws IOException {
+ if (__classToLaunch==null) return null;
+ return launchVM(__classToLaunch, getAllCommandLineParameters());
+ }
+
+ /** Replies the command line parameters.
+ *
+ * @return the command line parameters.
+ */
+ protected static String[] getAllCommandLineParameters() {
+ int osize = __options==null ? 0 : __options.size();
+ int psize = __parameters==null ? 0 : __parameters.length;
+ int tsize = (osize>0 && psize>0) ? 1 : 0;
+ String[] params = new String[osize+psize+tsize];
+ if (osize>0) {
+ int i=0;
+ String value;
+ for(Entry<String,String> entry : __options.entrySet()) {
+ value = entry.getValue();
+ if ((value!=null)&&(!"".equals(value))) //$NON-NLS-1$
+ params[i] = "-"+entry.getKey()+"="+entry.getValue(); //$NON-NLS-1$ //$NON-NLS-2$
+ else
+ params[i] = "-"+entry.getKey(); //$NON-NLS-1$
+ i++;
+ }
+ }
+ if (tsize>0) params[osize] = "--"; //$NON-NLS-1$
+ if (psize>0)
+ System.arraycopy(__parameters, 0, params, osize+tsize, psize);
+ return params;
+ }
+
+ /** Replies the command line parameters.
+ *
+ * @return the list of the parameters on the command line
+ */
+ public static String[] getCommandLineParameters() {
+ return __parameters==null ? new String[0] : __parameters;
+ }
+
+ /** Replies the command line parameters.
+ *
+ * @return the list of options passed on the command line
+ */
+ public static SortedMap<String,String> getCommandLineOptions() {
+ if (__options!=null)
+ return Collections.unmodifiableSortedMap(__options);
+ return new TreeMap<String,String>();
+ }
+
+ /** Analyse the command line to extract the options.
+ * <p>
+ * The options will be recognized thanks to the <var>optionDefinitions</var>.
+ * Each entry of <var>optionDefinitions</var> describes an option. They must
+ * have one of the following formats:
+ * <ul>
+ * <li>{@code name>}: a simple option without value or flag,</li>
+ * <li>{@code name=>}: an option with a mandatory string value,</li>
+ * </ul>
+ *
+ * @param optionDefinitions is the list of definitions of the available command line options.
+ */
+ public static void splitOptionsAndParameters(String... optionDefinitions) {
+ if (analyzed) return;
+
+ // Analyze definitions
+ Map<String,Integer> defs = new TreeMap<String,Integer>();
+ for (String def : optionDefinitions) {
+ if (def.endsWith("=")) { //$NON-NLS-1$
+ defs.put(def.substring(0, def.length()-1), 1);
+ }
+ else {
+ defs.put(def, 0);
+ }
+ }
+
+ ArrayList<String> params = new ArrayList<String>();
+ SortedMap<String,String> options = new TreeMap<String,String>();
+
+ int idx;
+ String opt, base, val;
+ Integer code;
+ String waitingValue = null;
+ boolean allParameters = false;
+
+ for(String param : __parameters) {
+ if (allParameters) {
+ params.add(param);
+ continue;
+ }
+ else if (waitingValue!=null){
+ options.put(waitingValue, param);
+ waitingValue = null;
+ continue;
+ }
+ else if ("--".equals(param)) { //$NON-NLS-1$
+ allParameters = true;
+ continue;
+ }
+ else if ((File.separatorChar!='/')&&(param.startsWith("/"))) { //$NON-NLS-1$
+ opt = param.substring(1);
+ }
+ else if (param.startsWith("--")) { //$NON-NLS-1$
+ opt = param.substring(2);
+ }
+ else if (param.startsWith("-")) { //$NON-NLS-1$
+ opt = param.substring(1);
+ }
+ else {
+ params.add(param);
+ continue;
+ }
+
+ idx = opt.indexOf('=');
+ if (idx>0) {
+ base = opt.substring(0,idx);
+ val = opt.substring(idx+1);
+ }
+ else {
+ base = opt;
+ val = null;
+ }
+
+ code = defs.get(base);
+ if (code!=null) {
+ if (code==1) {
+ if (val==null)
+ waitingValue = base;
+ else
+ options.put(base, val);
+ }
+ else {
+ options.put(base, null);
+ }
+ }
+ }
+
+ __parameters = new String[params.size()];
+ params.toArray(__parameters);
+ params.clear();
+
+ __options = options;
+
+ analyzed = true;
+ }
+
+ /**
+ * Create a interface to the command line options.
+ *
+ * @param class_to_launch is the class which contains a <code>main</code>.
+ * @param parameters is the parameters to pass to the <code>main</code>.
+ * @see #saveVMParametersIfNotSet(Class, String[])
+ */
+ public VMCommandLine(Class<?> class_to_launch, String... parameters) {
+ saveVMParametersIfNotSet(class_to_launch, parameters);
+ }
+
+ /**
+ * Create a interface to the command line options.
+ *
+ * @param class_to_launch is the class which contains a <code>main</code>.
+ * @param optionDefinitions is the list of definitions of the available command line options.
+ * @param parameters is the parameters to pass to the <code>main</code>.
+ * @see #saveVMParametersIfNotSet(Class, String[])
+ * @see #splitOptionsAndParameters(String[])
+ */
+ public VMCommandLine(Class<?> class_to_launch, String[] optionDefinitions, String... parameters) {
+ saveVMParametersIfNotSet(class_to_launch, parameters);
+ splitOptionsAndParameters(optionDefinitions);
+ }
+
+ /**
+ * Create a interface to the command line options.
+ *
+ * @see #VMCommandLine(Class, String[], String[])
+ * @see #VMCommandLine(Class, String[])
+ */
+ public VMCommandLine() {
+ if (__classToLaunch==null) {
+ throw new IllegalArgumentException("you must call the other constructor previously"); //$NON-NLS-1$
+ }
+ }
+
+ /** Replies if the given option is present on the command line.
+ *
+ * @param optionLabel is the name of the option
+ * @return <code>true</code> if the option is present, otherwise <code>false</code>
+ */
+ public boolean hasOption(String optionLabel) {
+ SortedMap<String,String> options = getCommandLineOptions();
+ return options.containsKey(optionLabel);
+ }
+
+ /** Replies if the given option is present on the command line.
+ *
+ * @param optionLabel is the name of the option
+ * @return the option value or <code>null</code> if the option is not present.
+ */
+ public String getOption(String optionLabel) {
+ SortedMap<String,String> options = getCommandLineOptions();
+ return options.get(optionLabel);
+ }
+
+ /** Replies the parameters on the command line that are not options.
+ *
+ * @return the parameters.
+ */
+ public String[] getParameters() {
+ return getCommandLineParameters();
+ }
+
+ /** Replies the count of parameters on the command line that are not options.
+ *
+ * @return the count of parameters
+ */
+ public int getParameterCount() {
+ return getCommandLineParameters().length;
+ }
+
+ /** Replies the parameter at the specified index.
+ *
+ * @param index
+ * @return the value of the parameter.
+ * @throws IndexOutOfBoundsException
+ */
+ public String getParameterAt(int index) {
+ return getCommandLineParameters()[index];
+ }
+
+ /** Replies if the given index corresponds to a command line parameter.
+ *
+ * @param index
+ * @return <code>true</code> if the given index corresponds to a parameter,
+ * otherwise <code>false</code>
+ * @throws IndexOutOfBoundsException
+ */
+ public boolean isParameterExists(int index) {
+ String[] params = getCommandLineParameters();
+ return index>=0 && index<params.length && params[index]!=null;
+ }
+
+}
Added: trunk/arakhneVmutils/java/src/main/resources/AUTHORS
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/AUTHORS (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/AUTHORS 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+Stephane GALLAND <galland@xxxxxxxxxxx>
Added: trunk/arakhneVmutils/java/src/main/resources/COPYING
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/COPYING (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/COPYING 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
Added: trunk/arakhneVmutils/java/src/main/resources/Changelog
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/Changelog (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/Changelog 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,6 @@
+arakhneVmutils-1.0
+
+ * First public release
+
+ -- Stephane GALLAND <galland@xxxxxxxxxxx> Sat, 04 Oct 2008 09:51:52 +0200
+
Added: trunk/arakhneVmutils/java/src/main/resources/VERSION
===================================================================
--- trunk/arakhneVmutils/java/src/main/resources/VERSION (rev 0)
+++ trunk/arakhneVmutils/java/src/main/resources/VERSION 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+arakhneVmutils 2.0
Added: trunk/arakhneVmutils/native/josuuid/linux/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/linux/pom.xml (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/linux/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>josuuid-linux</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <packaging>so</packaging>
+ <version>2.0-SNAPSHOT</version>
+ <name>josuuid Linux Library</name>
+ <description>Linux Native library to obtain a UUID for the operating system</description>
+ <parent>
+ <artifactId>josuuid</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <dependencies>
+ <dependency>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>arakhneVmutils-java</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <compilerProvider>generic</compilerProvider>
+ <compilerStartOptions>
+ <compilerStartOption>-O3 -Wall -Werror -fmessage-length=0</compilerStartOption>
+ </compilerStartOptions>
+
+ <javahOS>linux</javahOS>
+
+ <sources>
+ <source>
+ <directory>../src/main/native</directory>
+ <fileNames>
+ <fileName>josuuid.cpp</fileName>
+ <fileName>winos.cpp</fileName>
+ <fileName>OperatingSystemJNI.cpp</fileName>
+ </fileNames>
+ </source>
+
+ </sources>
+
+ <linkerStartOptions>
+ <linkerStartOption>-shared</linkerStartOption>
+ </linkerStartOptions>
+
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>javah</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <classNames>
+ <className>org.arakhne.vmutil.OperatingSystem</className>
+ </classNames>
+ </configuration>
+ <goals>
+ <goal>javah</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>once</forkMode>
+ <environmentVariables>
+ <LD_LIBRARY_PATH>${project.build.directory}</LD_LIBRARY_PATH>
+ </environmentVariables>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+
+</project>
Added: trunk/arakhneVmutils/native/josuuid/mingw/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/mingw/pom.xml (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/mingw/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>josuuid-mingw</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <packaging>dll</packaging>
+ <version>2.0-SNAPSHOT</version>
+ <name>josuuid Windows® Library</name>
+ <description>Windows® Native library to obtain a UUID for the operating system</description>
+ <parent>
+ <artifactId>josuuid</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <dependencies>
+ <dependency>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>arakhneVmutils-java</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>native-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <compilerProvider>generic</compilerProvider>
+ <compilerExecutable>i586-mingw32msvc-g++</compilerExecutable>
+ <compilerStartOptions>
+ <compilerStartOption>-O0 -Wall -Werror -fmessage-length=0</compilerStartOption>
+ </compilerStartOptions>
+
+ <javahOS>linux</javahOS> <!-- not 'windows' to retreive the jni_md.h file -->
+
+ <sources>
+ <source>
+ <directory>../src/main/native</directory>
+ <fileNames>
+ <fileName>josuuid.cpp</fileName>
+ <fileName>winos.cpp</fileName>
+ <fileName>OperatingSystemJNI.cpp</fileName>
+ </fileNames>
+ </source>
+ </sources>
+
+ <linkerExecutable>i586-mingw32msvc-g++</linkerExecutable>
+ <linkerStartOptions>
+ <linkerStartOption>-shared</linkerStartOption>
+ </linkerStartOptions>
+
+ </configuration>
+
+ <executions>
+ <execution>
+ <id>javah</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <classNames>
+ <className>org.arakhne.vmutil.OperatingSystem</className>
+ </classNames>
+ </configuration>
+ <goals>
+ <goal>javah</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>once</forkMode>
+ <environmentVariables>
+ <LD_LIBRARY_PATH>${project.build.directory}</LD_LIBRARY_PATH>
+ </environmentVariables>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+
+</project>
Added: trunk/arakhneVmutils/native/josuuid/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/josuuid/pom.xml (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>josuuid</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <packaging>pom</packaging>
+ <version>2.0-SNAPSHOT</version>
+ <name>josuuid</name>
+ <description>Native library to obtain a UUID for the operating system</description>
+ <parent>
+ <artifactId>arakhneVmutils-native</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <version>1.0-alpha-4</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+
+ <profile>
+ <id>linux-hosted</id>
+ <activation>
+ <os>
+ <name>linux</name>
+ <family>unix</family>
+ </os>
+ </activation>
+ <modules>
+ <module>linux</module>
+ <module>mingw</module>
+ </modules>
+ </profile>
+
+ <!--profile>
+ <id>win32</id>
+ <activation>
+ <os>
+ <name>Windows®</name>
+ <family>Windows</family>
+ <arch>x86</arch>
+ <version>5.1.2600</version>
+ </os>
+ </activation>
+ <modules>
+ <module>win32</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <id>macosx</id>
+ <activation>
+ <property>
+ <name>platform</name>
+ <value>macosx</value>
+ </property>
+ </activation>
+ <modules>
+ <module>macosx</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <id>aix</id>
+ <activation>
+ <property>
+ <name>platform</name>
+ <value>aix</value>
+ </property>
+ </activation>
+ <modules>
+ <module>aix</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <id>solaris</id>
+ <activation>
+ <property>
+ <name>platform</name>
+ <value>solaris</value>
+ </property>
+ </activation>
+ <modules>
+ <module>solaris</module>
+ </modules>
+ </profile-->
+
+ </profiles>
+
+</project>
Added: trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/OperatingSystemJNI.cpp 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,65 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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
+ */
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#include <jni.h>
+#include <stdlib.h>
+
+#include "org_arakhne_vmutil_OperatingSystem.h"
+#include "josuuid.h"
+
+/*
+ * Class: org_arakhne_vmutil_OperatingSystem
+ * Method: getOSSerialNumber
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_org_arakhne_vmutil_OperatingSystem_getOSSerialNumber
+(JNIEnv * env, jclass clazz) {
+ jstring jSerial = NULL;
+ char* cSerial = getOSSerial();
+ if (cSerial!=NULL) {
+ jSerial = env->NewStringUTF (cSerial);
+ free(cSerial);
+ }
+ return jSerial;
+}
+
+
+/*
+ * Class: org_arakhne_vmutil_OperatingSystem
+ * Method: getOSUUID
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL
+Java_org_arakhne_vmutil_OperatingSystem_getOSUUID
+(JNIEnv *env, jclass clazz) {
+ jstring jUUID = NULL;
+ char* cUUID = getOSUUID();
+ if (cUUID!=NULL) {
+ jUUID = env->NewStringUTF (cUUID);
+ free(cUUID);
+ }
+ return jUUID;
+}
Added: trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.cpp 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,175 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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
+ */
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifdef __WINDOWS__
+# include <windows.h>
+# include "winos.h"
+# define WINUUID_PART_COUNT 4
+static char hexCharacters[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+#else
+# include <unistd.h>
+# define DWORD unsigned long int
+#endif
+
+#include "josuuid.h"
+
+/* Remove white spaces at the begining and at the end of a string */
+static void trim(char** text) {
+ char* t;
+ unsigned long startIdx, endIdx;
+ unsigned long len, i;
+ if ((text==NULL)||(*text==NULL)) return;
+ len = strlen(*text);
+ // Search starting character
+ for(startIdx=0; startIdx<len; startIdx++) {
+ if (!isspace((*text)[startIdx])) break;
+ }
+ if (startIdx>=len) {
+ free(*text);
+ *text = strdup("");
+ return;
+ }
+ // Search ending character
+ for(endIdx=len-1; endIdx>=0; endIdx--) {
+ if (!isspace((*text)[endIdx])) break;
+ }
+ if (endIdx<0) {
+ free(*text);
+ *text = strdup("");
+ return;
+ }
+ // Create the new string
+ t = (char*)malloc(sizeof(char)*(endIdx-startIdx+2));
+ for(i=0; startIdx<=endIdx; i++, startIdx++) {
+ t[i] = (*text)[startIdx];
+ }
+ t[i] = '\0';
+ free(*text);
+ *text = t;
+}
+
+#ifndef __WINDOWS__
+/* Run the specified shell command and replies its standard output */
+static char* runCommand(const char* cmd) {
+ FILE* cmdOutput;
+ char* result = NULL;
+
+ cmdOutput = popen(cmd, "r");
+
+ if (cmdOutput!=NULL) {
+ char buffer[128];
+ unsigned long i,j, count = 0;
+ unsigned long charCount;
+
+ charCount = fread(buffer, sizeof(char), 128, cmdOutput);
+ while (charCount>0) {
+ result = (char*)realloc(result,sizeof(char)*(count+charCount+1));
+ for(i=0, j=count; i<charCount; i++, j++) {
+ result[j] = buffer[i];
+ }
+ count += charCount;
+ result[count] = '\0';
+ charCount = fread(buffer, sizeof(char), 128, cmdOutput);
+ }
+
+ pclose(cmdOutput);
+ }
+
+ return result;
+}
+#endif
+
+/* Replies the serial number of the system */
+char* getOSSerial() {
+#ifdef __WINDOWS__
+ DWORD size = 0;
+ BYTE* data = NULL;
+ if (getWindowsSerial(&data, &size)) {
+ char* serial = new char[size];
+ for(unsigned long i=0; i<size; i++) {
+ serial[i] = data[i];
+ }
+ free(data);
+ trim(&serial);
+ return serial;
+ }
+ return NULL;
+#else
+ char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.serial");
+ trim(&result);
+ return result;
+#endif
+}
+
+/* Replies the UUID of the system */
+char* getOSUUID() {
+#ifdef __WINDOWS__
+ DWORD size;
+ BYTE* data;
+ if (getWindowsSerial(&data, &size)) {
+ unsigned long i, j, k, totalSize = 2*(size-1);
+ char* serial = (char*)malloc(sizeof(char)*(totalSize+(totalSize/WINUUID_PART_COUNT)+2));
+ char characterToTreat;
+ short b0, b1;
+ bool lastIsSeparator = false;
+
+ for(i=0, j=0, k=WINUUID_PART_COUNT; i<size; i++) {
+ characterToTreat = data[i];
+ if (isalnum(characterToTreat)) {
+ b0 = (characterToTreat & 0x0F) ^ 0x0F;
+ b1 = ((characterToTreat & 0xF0) >> 4) ^ 0x0F;
+ serial[j++] = hexCharacters[b0];
+ serial[j++] = hexCharacters[b1];
+ k --;
+ if (k<=0) {
+ serial[j++] = '-';
+ k = WINUUID_PART_COUNT;
+ lastIsSeparator = true;
+ }
+ else {
+ lastIsSeparator = false;
+ }
+ }
+ }
+ if (lastIsSeparator) j--;
+ serial[j] = '\0';
+ free(data);
+
+ trim(&serial);
+
+ return serial;
+ }
+ return NULL;
+#else
+ char* result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.uuid");
+ trim(&result);
+ return result;
+#endif
+}
Added: trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/josuuid.h 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,31 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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
+ */
+
+#ifndef __JOSUUID_H__
+# define __JOSUUID_H__
+
+/* Replies the serial number of the system */
+char* getOSSerial();
+
+/* Replies the UUID of the system */
+char* getOSUUID();
+
+#endif /* __JOSUUID_H__ */
Added: trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/winos.cpp 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,176 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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
+ */
+
+#ifdef DEBUG
+# warning THE LIBRARY IS COMPILED WITH DEBUG INFORMATION
+#endif
+
+#ifdef __WINDOWS__
+
+#include <windows.h>
+#include <winreg.h>
+#include "winos.h"
+
+#include <stdio.h>
+
+/* Replies the windows version */
+BOOL getWindowsVersion(DWORD *version) {
+ OSVERSIONINFO osinfo;
+ osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (!GetVersionEx(&osinfo))
+ return false;
+
+ DWORD platform_id = osinfo.dwPlatformId;
+ DWORD minor_version = osinfo.dwMinorVersion;
+ DWORD major_version = osinfo.dwMajorVersion;
+ DWORD build_number = osinfo.dwBuildNumber & 0xFFFF; // Win 95 needs this
+
+ if ((platform_id == VER_PLATFORM_WIN32_WINDOWS) && (major_version == 4)) {
+ if ((minor_version < 10) && (build_number == 950))
+ *version = W95;
+ else if ((minor_version < 10) &&
+ ((build_number > 950) && (build_number <= 1080)))
+ *version = W95SP1;
+ else if ((minor_version < 10) && (build_number > 1080))
+ *version = W95OSR2;
+ else if ((minor_version == 10) && (build_number == 1998))
+ *version = W98;
+ else if ((minor_version == 10) &&
+ ((build_number > 1998) && (build_number < 2183)))
+ *version = W98SP1;
+ else if ((minor_version == 10) && (build_number >= 2183))
+ *version = W98SE;
+ else if (minor_version == 90)
+ *version = WME;
+ }
+ else if (platform_id == VER_PLATFORM_WIN32_NT) {
+ if ((major_version == 3) && (minor_version == 51))
+ *version = WNT351;
+ else if ((major_version == 4) && (minor_version == 0))
+ *version = WNT4;
+ else if ((major_version == 5) && (minor_version == 0))
+ *version = W2K;
+ else if ((major_version == 5) && (minor_version == 1))
+ *version = WXP;
+ }
+ else if (platform_id == VER_PLATFORM_WIN32_CE) {
+ *version = WCE;
+ }
+
+ return true;
+}
+
+/* Read the value of a registrery value */
+BOOL readRegistry(CHAR* key, CHAR* valueName, BYTE** data, DWORD* size) {
+ return readRegistryI(key,valueName,data,size,1);
+}
+
+/* Read the value of a registrery value */
+BOOL readRegistryI(CHAR* key, CHAR* valueName, BYTE** data, DWORD* size, BYTE allocationFactor) {
+ HKEY hKey = NULL; // registry handle, kept open between calls
+ LONG ret;
+
+ ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS /*KEY_QUERY_VALUE*/, &hKey);
+ if (ret != ERROR_SUCCESS) return false;
+
+ // Get the size of the value
+ DWORD valueSize=0;
+ ret = RegQueryValueEx(
+ hKey,
+ valueName,
+ NULL, //reserved
+ NULL, //type
+ NULL, //data
+ &valueSize);
+ if (ret != ERROR_SUCCESS) return false;
+ if (size!=NULL) {
+ *size = valueSize;
+ }
+ // Read the value data
+ BYTE* valueData;
+
+ if (data!=NULL) {
+ DWORD valueType;
+ valueData = (BYTE*)malloc(sizeof(BYTE)*valueSize*allocationFactor);
+ ret = RegQueryValueEx(
+ hKey,
+ valueName,
+ NULL, //reserved
+ &valueType, //type
+ valueData,
+ &valueSize);
+ RegCloseKey(hKey);
+ if (ret != ERROR_SUCCESS) {
+ free(valueData);
+ return false;
+ }
+ *data = valueData;
+ }
+ else {
+ RegCloseKey(hKey);
+ }
+
+ return true;
+}
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerial(BYTE** serial, DWORD* serialSize) {
+ return getWindowsSerialI(serial, serialSize, 1);
+}
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerialI(BYTE** serial, DWORD* serialSize, BYTE allocationFactor) {
+ DWORD version;
+ getWindowsVersion(&version);
+
+ CHAR* reg_path;
+ if ((version >=WNT_FIRST) && (version <= WNT_LAST))
+ reg_path = "Software\\Microsoft\\Windows NT\\CurrentVersion";
+ else
+ reg_path = "Software\\Microsoft\\Windows\\CurrentVersion";
+
+ DWORD size = 0;
+ BYTE* data = NULL;
+ if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor)) {
+ if ((version >=WNT_FIRST) && (version <= WNT_LAST)) {
+ reg_path = "Software\\Microsoft\\Windows\\CurrentVersion";
+ if (!readRegistryI(reg_path, "ProductId", &data, &size, allocationFactor))
+ return false;
+ }
+ else return false;
+ }
+
+ if (serial!=NULL) {
+ *serial = data;
+ }
+ else {
+ free(data);
+ }
+
+ if (serialSize!=NULL) {
+ *serialSize = size;
+ }
+
+ return true;
+}
+
+#endif
Added: trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/winos.h 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,73 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2005-2008 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
+ */
+
+#ifndef __WINOS_H__
+# define __WINOS_H__
+
+# define W9XFIRST 1
+# define W95 1
+# define W95SP1 2
+# define W95OSR2 3
+# define W98 4
+# define W98SP1 5
+# define W98SE 6
+# define WME 7
+# define W9XLAST 99
+
+# define WNT_FIRST 101
+# define WNT351 101
+# define WNT4 102
+# define W2K 103
+# define WXP 104
+# define WNT_LAST 199
+
+# define WCEFIRST 201
+# define WCE 201
+# define WCELAST 299
+
+# ifndef VER_PLATFORM_WIN32_WINDOWS
+# define VER_PLATFORM_WIN32_WINDOWS 1
+# endif
+# ifndef VER_PLATFORM_WIN32_NT
+# define VER_PLATFORM_WIN32_NT 2
+# endif
+# ifndef VER_PLATFORM_WIN32_CE
+# define VER_PLATFORM_WIN32_CE 3
+# endif
+
+# include <windows.h>
+
+/* Replies the windows version */
+BOOL getWindowsVersion(DWORD *version);
+
+/* Read the value of a registrery value */
+BOOL readRegistry(CHAR* key, CHAR* valueName, BYTE** data, DWORD* size);
+
+/* Read the value of a registrery value */
+BOOL readRegistryI(CHAR* key, CHAR* valueName, BYTE** data, DWORD* size, BYTE allocationFactor);
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerial(BYTE** serial, DWORD* serialSize);
+
+/* Replies the serial number of the system */
+BOOL getWindowsSerialI(BYTE** serial, DWORD* serialSize, BYTE allocationFactor);
+
+#endif
Added: trunk/arakhneVmutils/native/josuuid/src/main/resources/AUTHORS
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/resources/AUTHORS (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/resources/AUTHORS 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+Stephane GALLAND <galland@xxxxxxxxxxx>
Added: trunk/arakhneVmutils/native/josuuid/src/main/resources/COPYING
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/resources/COPYING (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/resources/COPYING 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
Added: trunk/arakhneVmutils/native/josuuid/src/main/resources/Changelog
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/resources/Changelog (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/resources/Changelog 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,6 @@
+josuuid-2.0
+
+ * First public release
+
+ -- Stephane GALLAND <galland@xxxxxxxxxxx> Sat, 04 Oct 2008 09:51:52 +0200
+
Added: trunk/arakhneVmutils/native/josuuid/src/main/resources/VERSION
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/resources/VERSION (rev 0)
+++ trunk/arakhneVmutils/native/josuuid/src/main/resources/VERSION 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1 @@
+josuuid 2.0
Added: trunk/arakhneVmutils/native/pom.xml
===================================================================
--- trunk/arakhneVmutils/native/pom.xml (rev 0)
+++ trunk/arakhneVmutils/native/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>arakhneVmutils-native</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <packaging>pom</packaging>
+ <version>2.0-SNAPSHOT</version>
+ <name>Native Libraries for arakhneVmutils</name>
+ <description>Native libraries for the Arakhnê VM utilities</description>
+ <parent>
+ <artifactId>arakhneVmutils</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>2.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <modules>
+ <module>josuuid</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>arakhneVmutils-java</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
Added: trunk/arakhneVmutils/pom.xml
===================================================================
--- trunk/arakhneVmutils/pom.xml (rev 0)
+++ trunk/arakhneVmutils/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>arakhneVmutils</artifactId>
+ <packaging>pom</packaging>
+ <version>2.0-SNAPSHOT</version>
+ <name>arakhneVmutils</name>
+ <url>http://www.arakhne.org/arakhneVmutils/</url>
+ <description>Java library that provides additional JVM-based tools.</description>
+ <parent>
+ <artifactId>afc</artifactId>
+ <groupId>org.arakhne.afc</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <scm>
+ <connection>scm:svn:svn+ssh://svn.tuxfamily.org/svnroot/arakhne/afc/arakhneVmutils</connection>
+ <developerConnection>scm:svn:svn+ssh://username@xxxxxxxxxxxxxxxxx/svnroot/arakhne/afc/arakhneVmutils</developerConnection>
+ <url>http://www.arakhne.org/websvn.php?project=afc&subproject=arakhneVmutils</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>with-dll.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <!-- executions>
+ <execution>
+ <id>make-vmutil-assembly</id>
+ <phase>install</phase>
+ <goals>
+ <goal>assembly</goal>
+ </goals>
+ </execution>
+ </executions -->
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>java</module>
+ <module>native</module>
+ </modules>
+
+</project>
Added: trunk/arakhneVmutils/with-dll.xml
===================================================================
--- trunk/arakhneVmutils/with-dll.xml (rev 0)
+++ trunk/arakhneVmutils/with-dll.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,31 @@
+<assembly>
+ <id>with-dll</id>
+ <formats>
+ <format>jar</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <moduleSets>
+ <moduleSet>
+ <includeSubModules>true</includeSubModules>
+ <includes>
+ <include>org.arakhne.afc:arakhneVmutils-java</include>
+ </includes>
+ <binaries>
+ <outputDirectory></outputDirectory>
+ <unpack>true</unpack>
+ </binaries>
+ </moduleSet>
+ </moduleSets>
+ <files>
+ <file>
+ <source>native/josuuid/linux/target/josuuid-linux.so</source>
+ <outputDirectory>org/arakhne/vmutil</outputDirectory>
+ <destName>libjosuuid.so</destName>
+ </file>
+ <file>
+ <source>native/josuuid/mingw/target/josuuid-mingw.dll</source>
+ <outputDirectory>org/arakhne/vmutil</outputDirectory>
+ <destName>josuuid.dll</destName>
+ </file>
+ </files>
+</assembly>
Added: trunk/pom.xml
===================================================================
--- trunk/pom.xml (rev 0)
+++ trunk/pom.xml 2008-10-07 14:32:10 UTC (rev 1)
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.arakhne.afc</groupId>
+ <artifactId>afc</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>Arakhnê Foundation Classes</name>
+ <inceptionYear>2007</inceptionYear>
+ <url>http://www.arakhne.org/</url>
+ <description>Java library that provides additional tools.</description>
+
+
+ <!-- ======================================= -->
+ <!-- ==== Project Information === -->
+ <!-- ======================================= -->
+
+ <modules>
+ <module>arakhneRefs</module>
+ <module>arakhneVmutils</module>
+ </modules>
+
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License v2.0</name>
+ <url>http://www.gnu.org/licenses/lgpl.html</url>
+ <distribution>manual</distribution>
+ </license>
+ </licenses>
+
+ <mailingLists>
+ <mailingList>
+ <name>dev@xxxxxxxxxxx</name>
+ <subscribe>mailto:dev-request@xxxxxxxxxxx</subscribe>
+ <unsubscribe>mailto:dev-request@xxxxxxxxxxx</unsubscribe>
+ <post>mailto:dev@xxxxxxxxxxx</post>
+ </mailingList>
+ </mailingLists>
+
+ <!-- ======================================= -->
+ <!-- ==== Organization Information === -->
+ <!-- ======================================= -->
+
+ <organization>
+ <name>Arakhnê.org Project</name>
+ <url>http://www.arakhne.org</url>
+ </organization>
+
+ <developers>
+ <developer>
+ <id>galland</id>
+ <name>Stephane Galland</name>
+ <email>galland@xxxxxxxxxxx</email>
+ <url>http://www.arakhne.org/homes/galland.html</url>
+ <organization />
+ <organizationUrl />
+ <roles>
+ <role>Founder</role>
+ <role>Architect</role>
+ <role>Developer</role>
+ </roles>
+ <timezone />
+ <properties />
+ </developer>
+ </developers>
+
+ <!-- ======================================= -->
+ <!-- ==== Devel Configuration === -->
+ <!-- ======================================= -->
+
+ <scm>
+ <connection>scm:svn:svn+ssh://svn.tuxfamily.org/svnroot/arakhne/afc</connection>
+ <developerConnection>scm:svn:svn+ssh://username@xxxxxxxxxxxxxxxxx/svnroot/arakhne/afc</developerConnection>
+ <url>http://www.arakhne.org/websvn.php?project=afc</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-scm-plugin</artifactId>
+ <version>1.0</version>
+ <configuration>
+ <goals>install</goals>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>2.0-beta-7</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.3</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- ======================================= -->
+ <!-- ==== Repositories === -->
+ <!-- ======================================= -->
+
+ <repositories>
+ <repository>
+ <id>Codehaus Snapshots</id>
+ <url>http://snapshots.repository.codehaus.org/</url>
+ </repository>
+ </repositories>
+
+ <!-- ======================================= -->
+ <!-- ==== Reports === -->
+ <!-- ======================================= -->
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>dashboard-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jxr-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>taglist-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ <configuration>
+ <threshold>Normal</threshold>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <configuration>
+ <targetjdk>1.5</targetjdk>
+ <rulesets>
+ <ruleset>/rulesets/basic.xml</ruleset>
+ <ruleset>/rulesets/controversial.xml</ruleset>
+ </rulesets>
+ <format>xml</format>
+ <linkXref>true</linkXref>
+ <sourceEncoding>utf-8</sourceEncoding>
+ <minimumTokens>100</minimumTokens>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+</project>