abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r442254 - in /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server: target/Target.java util/RegexTargetResolver.java
Date Mon, 11 Sep 2006 16:58:52 GMT
Author: jmsnell
Date: Mon Sep 11 09:58:51 2006
New Revision: 442254

URL: http://svn.apache.org/viewvc?view=rev&rev=442254
Log:
Make Target serializable.

Because Matcher is not serializable, implement custom serialization for 
RegexTargetResolver$RegexTarget

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/target/Target.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/target/Target.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/target/Target.java?view=diff&rev=442254&r1=442253&r2=442254
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/target/Target.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/target/Target.java
Mon Sep 11 09:58:51 2006
@@ -17,14 +17,26 @@
 */
 package org.apache.abdera.protocol.server.target;
 
+import java.io.Serializable;
+
 import org.apache.abdera.protocol.server.util.ResourceType;
 
-public interface Target extends Iterable<String> {
+public interface Target 
+  extends Iterable<String>, 
+          Serializable {
 
   ResourceType getResourceType();
   
+  /**
+   * Requests a target token value.  index=0 should always return the complete
+   * identifier of the target.
+   */
   String getValue(int index);
   
+  /**
+   * Determines whether or not the Target specifies the specified token value.
+   * MUST return true if index=0
+   */
   boolean hasValue(int index);
   
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java?view=diff&rev=442254&r1=442253&r2=442254
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/RegexTargetResolver.java
Mon Sep 11 09:58:51 2006
@@ -17,6 +17,9 @@
 */
 package org.apache.abdera.protocol.server.util;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -83,8 +86,9 @@
   
   public static class RegexTarget implements Target {
     
-    final Matcher matcher;
-    final ResourceType type;
+    private static final long serialVersionUID = 165211244926064449L;
+    transient Matcher matcher;
+    private ResourceType type;
     
     RegexTarget(ResourceType type, Matcher matcher) {
       this.type = type;
@@ -109,6 +113,24 @@
 
     public Iterator<String> iterator() {
       return new TargetIterator(this);
+    }
+    
+    private void writeObject(ObjectOutputStream out) 
+      throws IOException {
+        out.defaultWriteObject();
+        out.writeObject(matcher.pattern().pattern());
+        out.writeObject(matcher.group(0));
+    }
+
+    private void readObject(ObjectInputStream in) 
+      throws IOException, 
+             ClassNotFoundException {
+       in.defaultReadObject();
+       String p = (String) in.readObject();
+       String v = (String) in.readObject();
+       Pattern pattern = Pattern.compile(p);
+       matcher = pattern.matcher(v);
+       matcher.matches();
     }
   }
   



Mime
View raw message