Author: michiel
Date: 2009-07-06 17:32:41 +0200 (Mon, 06 Jul 2009)
New Revision: 36588

Modified:
   mmbase/trunk/core/src/main/java/org/mmbase/util/LocaleCollator.java
Log:
should be serializable to satisfy rmmci

Modified: mmbase/trunk/core/src/main/java/org/mmbase/util/LocaleCollator.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/util/LocaleCollator.java 
2009-07-06 15:18:04 UTC (rev 36587)
+++ mmbase/trunk/core/src/main/java/org/mmbase/util/LocaleCollator.java 
2009-07-06 15:32:41 UTC (rev 36588)
@@ -11,16 +11,20 @@
 
 import java.text.*;
 import java.util.*;
+import java.io.*;
 
 /**
- * This class wraps a {...@link java.text.Collator} and associates it with a 
{...@link java.util.Locale}.
+ * This class wraps a {...@link java.text.Collator} and associates it with a 
{...@link
+ * java.util.Locale}. Also, it is {...@link java.io.Serializable} (mostly to 
help RMMC).
  *
  * @author Michiel Meeuwissen
  * @version $Id$
  * @since MMBase-1.9.2
  */
-public class LocaleCollator  extends Collator {
+public class LocaleCollator  extends Collator implements Serializable {
 
+    private static final long serialVersionUID = 1L;
+
     public static enum Strength {
         IDENTICAL(Collator.IDENTICAL),
         PRIMARY(Collator.PRIMARY),
@@ -95,7 +99,7 @@
         return collator;
     }
 
-    private final Collator wrapped;
+    private transient Collator wrapped;
     private final Locale locale;
     private LocaleCollator(Locale loc) {
         locale = loc;
@@ -184,8 +188,30 @@
         return true;
     }
 
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeUTF(wrapped.getClass().getName());
+        if (wrapped instanceof RuleBasedCollator) {
+            out.writeUTF(((RuleBasedCollator) wrapped).getRules());
+        } else {
+            throw new IOException("Don't know how to serialize " + wrapped);
+        }
 
+    }
+    private void readObject(ObjectInputStream in) throws IOException, 
ClassNotFoundException {
+        in.defaultReadObject();
+        String clazz = in.readUTF(); // ignore for now
+        try {
+            wrapped = new RuleBasedCollator(in.readUTF());
+        } catch (ParseException pe) {
+            throw new IOException(pe);
+        }
 
+
+    }
+
+
+
     public static void main(String[] argv) throws Exception {
         Collator col = getInstance(argv[0]);
 

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to