db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r225412 - in /incubator/jdo/trunk/api20: src/java/javax/jdo/identity/CharIdentity.java src/java/javax/jdo/spi/JDOImplHelper.java test/java/javax/jdo/identity/ObjectIdentityTest.java
Date Tue, 26 Jul 2005 22:39:15 GMT
Author: clr
Date: Tue Jul 26 15:39:10 2005
New Revision: 225412

URL: http://svn.apache.org/viewcvs?rev=225412&view=rev
Log:
JDO-95 JDO2API doesn't run with JRE 1.3 due to classes and methods added since 1.4

Modified:
    incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java
    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/identity/CharIdentity.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java?rev=225412&r1=225411&r2=225412&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/identity/CharIdentity.java Tue Jul 26 15:39:10
2005
@@ -94,7 +94,7 @@
      * @return the String form of the key
      */
     public String toString () {
-        return Character.toString(key);
+        return String.valueOf(key);
     }
 
     /** Determine if the other object represents the same object id.

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=225412&r1=225411&r2=225412&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 Tue Jul 26 15:39:10
2005
@@ -573,7 +573,7 @@
         helper.registerStringConstructor(Locale.class, new StringConstructor() {
             public Object construct(String s) {
                 try {
-                    return new Locale(s);
+                    return getLocale(s);
                 } catch (Exception ex) {
                     throw new JDOUserException(
                         msg.msg("EXC_LocaleStringConstructorException"), ex); //NOI18N
@@ -582,18 +582,46 @@
         });
         helper.registerStringConstructor(Date.class, new StringConstructor() {
             public synchronized Object construct(String s) {
-                ParsePosition pp = new ParsePosition(0);
-                Date result = dateFormat.parse(s, pp);
-                if (result == null) {
-                    throw new JDOUserException (
-                        msg.msg("EXC_DateStringConstructor", new Object[] //NOI18N
-                        {s, new Integer(pp.getErrorIndex()), dateFormatPattern}));
+                try {
+                    // first, try the String as a Long
+                    return new Date(Long.parseLong(s));
+                } catch (NumberFormatException ex) {
+                    // not a Long; try the formatted date
+                    ParsePosition pp = new ParsePosition(0);
+                    Date result = dateFormat.parse(s, pp);
+                    if (result == null) {
+                        throw new JDOUserException (
+                            msg.msg("EXC_DateStringConstructor", new Object[] //NOI18N
+                            {s, new Integer(pp.getErrorIndex()), dateFormatPattern}));
+                    }
+                    return result;
                 }
-                return result;
             }
         });
     }
     
+    /**
+     * Parse the String to a Locale.
+     */
+    private static Locale getLocale(String s) {
+        String lang = s;
+        int firstUnderbar = s.indexOf('_');
+        if (firstUnderbar == -1) {
+            // nothing but language
+            return new Locale(lang);
+        }
+        lang = s.substring(0, firstUnderbar);
+        String country;
+        int secondUnderbar = s.indexOf('_', firstUnderbar + 1);
+        if (secondUnderbar == -1) {
+            // nothing but language, country
+            country = s.substring(firstUnderbar + 1);
+            return new Locale(lang, country);
+        }
+        country = s.substring(firstUnderbar + 1, secondUnderbar);
+        String variant = s.substring(secondUnderbar + 1);
+        return new Locale(lang, country, variant);
+    }
     /**
      * Determine if a class is loadable in the current environment.
      */

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=225412&r1=225411&r2=225412&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 Tue Jul
26 15:39:10 2005
@@ -246,14 +246,34 @@
         fail ("Failed to catch expected Exception.");
     }
 
-    public void testStringLocaleConstructor() {
-        Object c1 = new ObjectIdentity(Object.class, 
-                    "java.util.Locale:en_us");
+    public void testStringLocaleConstructorLanguage() {
+        if (!helper.isClassLoadable("java.util.Currency")) return;
+        SingleFieldIdentity c1 = new ObjectIdentity(Object.class, 
+                    "java.util.Locale:en");
+        assertEquals(new Locale("en"), c1.getKeyAsObject());
+    }
+
+    public void testStringLocaleConstructorCountry() {
+        SingleFieldIdentity c1 = new ObjectIdentity(Object.class, 
+                    "java.util.Locale:_US");
+        assertEquals(new Locale("","US"), c1.getKeyAsObject());
+    }
+
+    public void testStringLocaleConstructorLanguageCountry() {
+        SingleFieldIdentity c1 = new ObjectIdentity(Object.class, 
+                    "java.util.Locale:en_US");
+        assertEquals(new Locale("en","US"), c1.getKeyAsObject());
+    }
+
+    public void testStringLocaleConstructorLanguageCountryVariant() {
+        SingleFieldIdentity c1 = new ObjectIdentity(Object.class, 
+                    "java.util.Locale:en_US_MAC");
+        assertEquals(new Locale("en","US","MAC"), c1.getKeyAsObject());
     }
 
     public void testStringCurrencyConstructor() {
         if (!helper.isClassLoadable("java.util.Currency")) return;
-        Object c1 = new ObjectIdentity(Object.class, 
+        SingleFieldIdentity c1 = new ObjectIdentity(Object.class, 
                     "java.util.Currency:USD");
     }
 
@@ -326,7 +346,7 @@
     
     public void testSerializedDate() {
         ObjectIdentity c1 = new ObjectIdentity(Object.class, new Date(1));
-        ObjectIdentity c2 = new ObjectIdentity(Object.class, new Date(1));
+        ObjectIdentity c2 = new ObjectIdentity(Object.class, "java.util.Date:1");
         ObjectIdentity c3 = new ObjectIdentity(Object.class, new Date(2));
         Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
         Object sc1 = scis[0];
@@ -343,9 +363,9 @@
     }
     
     public void testSerializedLocale() {
-        ObjectIdentity c1 = new ObjectIdentity(Object.class, new Locale("EN_US"));
-        ObjectIdentity c2 = new ObjectIdentity(Object.class, new Locale("en_us"));
-        ObjectIdentity c3 = new ObjectIdentity(Object.class, new Locale("EN_GB"));
+        ObjectIdentity c1 = new ObjectIdentity(Object.class, Locale.US);
+        ObjectIdentity c2 = new ObjectIdentity(Object.class, Locale.US);
+        ObjectIdentity c3 = new ObjectIdentity(Object.class, Locale.GERMANY);
         Object[] scis = writeReadSerialized(new Object[] {c1, c2, c3});
         Object sc1 = scis[0];
         Object sc2 = scis[1];



Mime
View raw message