Hi Erik,

Can you please test the fix and update the JIRA JDO-95 issue if the fix is ok?

Thanks,

Craig

Begin forwarded message:

From: clr@apache.org
Date: July 21, 2005 9:48:30 PM PDT
To: jdo-commits@db.apache.org
Subject: svn commit: r220237 - in /incubator/jdo/trunk/api20: src/java/javax/jdo/spi/JDOImplHelper.java test/java/javax/jdo/identity/ObjectIdentityTest.java
Reply-To: jdo-dev@db.apache.org


Author: clr
Date: Thu Jul 21 21:48:28 2005
New Revision: 220237

URL: http://svn.apache.org/viewcvs?rev=220237&view=rev
Log:
JDO-95 if Currency.class is not available, don't test or create helper instances for Currency

Modified:
    incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java?rev=220237&r1=220236&r2=220237&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/spi/JDOImplHelper.java Thu Jul 21 21:48:28 2005
@@ -555,19 +555,21 @@
      */
     static {
         JDOImplHelper helper = getInstance();
-        helper.registerStringConstructor(Currency.class, new StringConstructor() {
-            public Object construct(String s) {
-                try {
-                    return Currency.getInstance(s);
-                } catch (IllegalArgumentException ex) {
-                    throw new javax.jdo.JDOUserException(
-                        msg.msg("EXC_CurrencyStringConstructorIllegalArgument", s), ex); //NOI18N
-                } catch (Exception ex) {
-                    throw new JDOUserException(
-                        msg.msg("EXC_CurrencyStringConstructorException"), ex); //NOI18N
+        if (isClassLoadable("java.util.Currency")) {
+            helper.registerStringConstructor(Currency.class, new StringConstructor() {
+                public Object construct(String s) {
+                    try {
+                        return Currency.getInstance(s);
+                    } catch (IllegalArgumentException ex) {
+                        throw new javax.jdo.JDOUserException(
+                            msg.msg("EXC_CurrencyStringConstructorIllegalArgument", s), ex); //NOI18N
+                    } catch (Exception ex) {
+                        throw new JDOUserException(
+                            msg.msg("EXC_CurrencyStringConstructorException"), ex); //NOI18N
+                    }
                 }
-            }
-        });
+            });
+        }
         helper.registerStringConstructor(Locale.class, new StringConstructor() {
             public Object construct(String s) {
                 try {
@@ -590,6 +592,18 @@
                 return result;
             }
         });
+    }
+    
+    /**
+     * Determine if a class is loadable in the current environment.
+     */
+    public static boolean isClassLoadable(String className) {
+        try {
+            Class.forName(className);
+            return true;
+        } catch (ClassNotFoundException ex) {
+            return false;
+        }
     }

     /**

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java?rev=220237&r1=220236&r2=220237&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/identity/ObjectIdentityTest.java Thu Jul 21 21:48:28 2005
@@ -113,6 +113,7 @@
     }

     public void testCurrencyConstructor() {
+        if (!helper.isClassLoadable("java.util.Currency")) return;
         ObjectIdentity c1 = new ObjectIdentity(Object.class, 
                 Currency.getInstance(Locale.US));
         ObjectIdentity c2 = new ObjectIdentity(Object.class, 
@@ -251,11 +252,13 @@
     }

     public void testStringCurrencyConstructor() {
+        if (!helper.isClassLoadable("java.util.Currency")) return;
         Object c1 = new ObjectIdentity(Object.class, 
                     "java.util.Currency:USD");
     }

     public void testBadStringCurrencyConstructor() {
+        if (!helper.isClassLoadable("java.util.Currency")) return;
         try {
             ObjectIdentity c1 = new ObjectIdentity(Object.class, 
                     "java.util.Currency:NowhereInTheWorld");
@@ -303,6 +306,7 @@
     }

     public void testSerializedCurrency() {
+        if (!helper.isClassLoadable("java.util.Currency")) return;
         ObjectIdentity c1 = new ObjectIdentity(Object.class, Currency.getInstance(Locale.US));
         ObjectIdentity c2 = new ObjectIdentity(Object.class, Currency.getInstance(Locale.US));
         ObjectIdentity c3 = new ObjectIdentity(Object.class, Currency.getInstance(Locale.GERMANY));




Craig Russell

Architect, Sun Java Enterprise System http://java.sun.com/products/jdo

408 276-5638 mailto:Craig.Russell@sun.com

P.S. A good JDO? O, Gasp!