diff options
author | Kenneth Russel <[email protected]> | 2006-12-20 21:31:58 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-12-20 21:31:58 +0000 |
commit | 1f4c024d5dd562a5c2b1e1c1257648b732a105a9 (patch) | |
tree | 40cbcc38fba01180f50e76949e6952d6d2822d1d /src/classes/com/sun/opengl/util | |
parent | bd207dd065b5e2f506e5d3ae22e9102cba2be92e (diff) |
Fixed problem in JOGLAppletLauncher where if two different applets
(with different archive parameters, meaning two different class
loaders in the Sun applet implementation) loaded from the same web
site both used JOGL we would get an UnsatisfiedLinkError; now uniquify
the local install directory based on a hash of the archive tag
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1033 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/opengl/util')
-rwxr-xr-x | src/classes/com/sun/opengl/util/JOGLAppletLauncher.java | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java b/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java index f1d3461c2..28731ee41 100755 --- a/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java +++ b/src/classes/com/sun/opengl/util/JOGLAppletLauncher.java @@ -52,6 +52,8 @@ import java.applet.AppletStub; import java.applet.AppletContext; import java.io.*; import java.net.*; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.security.cert.*; import java.text.*; import java.util.*; @@ -224,6 +226,30 @@ public class JOGLAppletLauncher extends Applet { public JOGLAppletLauncher() { } + private static String md2Hash(String str) { + // Helps hash the jars in the "archive" tag into a hex value to + // avoid having too-long path names in the install directory's + // path name but also to have unique directories for each + // different archive set used (also meaning for each class loader + // loading something via the JOGLAppletLauncher) -- note that this + // is somewhat dependent on the Sun implementation of applets and + // their class loaders + MessageDigest md2 = null; + try { + md2 = MessageDigest.getInstance("MD2"); + } catch (NoSuchAlgorithmException e) { + return ""; + } + byte[] digest = md2.digest(str.getBytes()); + if (digest == null || (digest.length == 0)) + return ""; + StringBuffer res = new StringBuffer(); + for (int i = 0; i < digest.length; i++) { + res.append(Integer.toHexString(digest[i] & 0xFF)); + } + return res.toString(); + } + /** Applet initialization */ public void init() { @@ -242,10 +268,12 @@ public class JOGLAppletLauncher extends Applet { initLoaderLayout(); validate(); - String codeBase = getCodeBase().toExternalForm().substring(7); // minus http:// + String extForm = getCodeBase().toExternalForm(); + String codeBase = extForm.substring(extForm.indexOf(":") + 3); // minus http:// or https:// this.installDirectory = codeBase.replace(':', '_') - .replace('.', '_').replace('/', '_').replace('~','_'); // clean up the name + .replace('.', '_').replace('/', '_').replace('~','_') // clean up the name + + md2Hash(getParameter("archive")); // make it unique across different applet class loaders String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); @@ -902,11 +930,13 @@ public class JOGLAppletLauncher extends Applet { try { System.load(new File(installDir, nativeLibName).getPath()); } catch (UnsatisfiedLinkError ex) { - // should be safe to continue as long as the native is loaded by any loader - if (ex.getMessage().indexOf("already loaded") == -1) { - displayError("Unable to load " + nativeLibName); - throw ex; - } + // Note: if we have loaded this particular copy of the + // JOGL-related native library in another class loader, the + // steps taken above to ensure the installation directory name + // was unique have failed. We can't continue properly in this + // case, so just print and re-throw the exception. + ex.printStackTrace(); + throw ex; } } |