From 27424d9f36659a09195eaae77cf774f7ba3c0eec Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 21 Feb 2013 14:03:38 +0100 Subject: Minor edits to JarUtil.Resolver functionality: Exception types, avoiding duplicate processing of strings etc. --- src/java/com/jogamp/common/util/JarUtil.java | 61 ++++++++++++++++++---------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'src/java/com/jogamp/common/util/JarUtil.java') diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index 7fa5dd0..cfdf126 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -53,35 +53,42 @@ public class JarUtil { private static final boolean DEBUG = Debug.debug("JarUtil"); /** - * This interface allows users to provide an URL resolver that will convert custom classloader - * URLs like Eclipse/OSGi "bundleresource:" URLs to normal "jar:" URLs. This is needed when - * the classloader has been customized. + * Interface allowing users to provide an URL resolver that will convert custom classloader + * URLs like Eclipse/OSGi bundleresource: URLs to normal jar: URLs. + *

+ * This might be required for custom classloader where the URL protocol is unknown + * to the standard runtime environment. + *

+ *

+ * Note: The provided resolver is only utilized if a given URL's protocol could not be resolved. + * I.e. it will not be invoked for known protocols like http, https, jar or file. + *

*/ public interface Resolver { URL resolve(URL url); } - /** If non-null, we use this to resolve class file URLs after querying them from the classloader. - * The resolver won't be used on an URL if it's already of a common type like file, jar, or http[s].*/ private static Resolver resolver; /** - * Setter. - * @param r Resolver to use after querying class file URLs from the classloader. - * @throws Error if the resolver has already been set. + * Setting a custom {@link Resolver} instance. + * + * @param r {@link Resolver} to use after querying class file URLs from the classloader. + * @throws IllegalArgumentException if the passed resolver is null + * @throws IllegalStateException if the resolver has already been set. * @throws SecurityException if the security manager doesn't have the setFactory * permission */ - public static void setResolver(Resolver r) { + public static void setResolver(Resolver r) throws IllegalArgumentException, IllegalStateException, SecurityException { if(r == null) { - return; + throw new IllegalArgumentException("Null Resolver passed"); } if(resolver != null) { - throw new Error("Resolver already set!"); + throw new IllegalStateException("Resolver already set!"); } - SecurityManager security = System.getSecurityManager(); + final SecurityManager security = System.getSecurityManager(); if(security != null) { security.checkSetFactory(); } @@ -129,18 +136,30 @@ public class JarUtil { if(null == clazzBinName || null == cl) { throw new IllegalArgumentException("null arguments: clazzBinName "+clazzBinName+", cl "+cl); } - URL url = IOUtil.getClassURL(clazzBinName, cl); - if( resolver != null - && !url.toString().startsWith("jar:") - && !url.toString().startsWith("file:") - && !url.toString().startsWith("http:") - && !url.toString().startsWith("https:")) { - url = resolver.resolve(url); + final URL url; + final String urlS; + { + final URL _url = IOUtil.getClassURL(clazzBinName, cl); + final String _urlS = _url.toExternalForm(); + if( resolver != null && + !_urlS.startsWith("jar:") && + !_urlS.startsWith("file:") && + !_urlS.startsWith("http:") && + !_urlS.startsWith("https:") ) + { + url = resolver.resolve(_url); + urlS = url.toExternalForm(); + if(DEBUG) { + System.out.println("getJarURL Resolver: "+_urlS+" -> "+urlS); + } + } else { + url = _url; + urlS = _urlS; + } } // test name .. - final String urlS = url.toExternalForm(); if(DEBUG) { - System.out.println("getJarURL "+url+", extForm: "+urlS); + System.out.println("getJarURL "+urlS); } if(!urlS.startsWith("jar:")) { throw new IllegalArgumentException("JAR URL doesn't start with 'jar:', got <"+urlS+">"); -- cgit v1.2.3