From 44d3664db420adfbf89919435c2d8b161aa10d2f Mon Sep 17 00:00:00 2001 From: curcuru Date: Tue, 6 Aug 2002 21:37:15 +0000 Subject: [PATCH] Updated to work with JDK 1.1.x properly: added try...catch and null checks for various places system properties, etc. may be unavailable on 1.1.x systems; Check for new JAXP related jars git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@225992 13f79535-47bb-0310-9956-ffa450edef68 --- java/src/org/apache/env/Which.java | 18 ++++++++++--- java/src/org/apache/env/WhichJar.java | 28 ++++++++++++++++++++ java/src/org/apache/env/WhichXmlCommons.java | 6 +++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/java/src/org/apache/env/Which.java b/java/src/org/apache/env/Which.java index 9277b86..7ef3d27 100644 --- a/java/src/org/apache/env/Which.java +++ b/java/src/org/apache/env/Which.java @@ -177,7 +177,6 @@ public class Which try { hash.put("java" + WhichConstant.TAG_VERSION, System.getProperty("java.version")); - hash.put("java.runtime.name", System.getProperty("java.runtime.name")); hash.put("file.encoding", System.getProperty("file.encoding")); hash.put("java.vendor", System.getProperty("java.vendor")); hash.put("os.name", System.getProperty("os.name")); @@ -185,6 +184,15 @@ public class Which catch (Exception e) { hash.put("Which" + WhichConstant.TAG_ERROR, "Accessing System.getProperty(...) threw: " + e.toString()); + } + try + { + // Not available on JDK 1.1.x + hash.put("java.runtime.name", System.getProperty("java.runtime.name")); + } + catch (Exception e) + { + hash.put("Which" + WhichConstant.TAG_ERROR + "11x", "Accessing System.getProperty(java.runtime.name) threw: " + e.toString()); } } @@ -230,11 +238,14 @@ public class Which Hashtable subHash = new Hashtable(); WhichProject proj = WhichFactory.newWhichProject(projName, options); - int tmpRetVal = proj.getInfo(subHash, options); + int subStatus = proj.getInfo(subHash, options); + + subHash.put(projName + WhichConstant.TAG_STATUS, + WhichConstant.ITEM_DESC[subStatus]); hash.put(projName + WhichConstant.TAG_HASHINFO, subHash); - retVal = Math.max(tmpRetVal, retVal); + retVal = Math.max(subStatus, retVal); } catch (Exception e) { @@ -243,6 +254,7 @@ public class Which hash.put(projName + WhichConstant.ITEM_DESC[WhichConstant.ITEM_ERROR], "newWhichProject threw: " + e.toString()); + e.printStackTrace(); retVal = Math.max(WhichConstant.ITEM_ERROR, retVal); } diff --git a/java/src/org/apache/env/WhichJar.java b/java/src/org/apache/env/WhichJar.java index 3603e98..c6bc7a5 100644 --- a/java/src/org/apache/env/WhichJar.java +++ b/java/src/org/apache/env/WhichJar.java @@ -157,6 +157,20 @@ public abstract class WhichJar // prevent instantiation; provide static service // Grab the actual path from the System String path = System.getProperty(pathName); + if (null == path) + { + // Protect cases where the path isn't found + hash.put( + jarName + + WhichConstant.ITEM_DESC[WhichConstant.ITEM_WARNING], + "searchPath [" + pathName + + "] not found!"); + + return (WhichConstant.isStrict(options) + ? WhichConstant.ITEM_WARNING + : WhichConstant.ITEM_NOTFOUND); + } + StringTokenizer st = new StringTokenizer(path, File.pathSeparator); int retVal = WhichConstant.ITEM_UNKNOWN; boolean jarFound = false; @@ -238,6 +252,20 @@ public abstract class WhichJar // prevent instantiation; provide static service // Grab the actual path(s) from the System String path = System.getProperty(pathName); + if (null == path) + { + // Protect cases where the path isn't found + hash.put( + jarName + + WhichConstant.ITEM_DESC[WhichConstant.ITEM_WARNING], + " searchDirs [" + pathName + + "] not found!"); + + return (WhichConstant.isStrict(options) + ? WhichConstant.ITEM_WARNING + : WhichConstant.ITEM_NOTFOUND); + } + StringTokenizer st = new StringTokenizer(path, File.pathSeparator); int retVal = WhichConstant.ITEM_UNKNOWN; diff --git a/java/src/org/apache/env/WhichXmlCommons.java b/java/src/org/apache/env/WhichXmlCommons.java index cc61a4e..2e86373 100644 --- a/java/src/org/apache/env/WhichXmlCommons.java +++ b/java/src/org/apache/env/WhichXmlCommons.java @@ -213,6 +213,12 @@ public class WhichXmlCommons implements WhichProject // Try to find older jaxp.jar in the classpath, etc. int ignored = WhichJar.searchClasspaths(hash, "jaxp.jar", options); + + // Also try to find varous Sun shipped classes from JAXP packs, etc. + ignored = WhichJar.searchClasspaths(hash, "dom.jar", options); + ignored = WhichJar.searchClasspaths(hash, "sax.jar", options); + ignored = WhichJar.searchClasspaths(hash, "jaxp-api.jar", options); + return status; }