abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r429840 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/filter/ core/src/main/java/org/apache/abdera/parser/ core/src/main/java/org/apache/abdera/util/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Tue, 08 Aug 2006 21:53:54 GMT
Author: rooneg
Date: Tue Aug  8 14:53:53 2006
New Revision: 429840

URL: http://svn.apache.org/viewvc?rev=429840&view=rev
Log:
Fix tests by making the FOMParser hand out copies of its default
ParserOptions, not a reference to the underlying default options.

Also, while I'm here make FOMParser's handling of its options
thread safe.

* parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
  (options): Note how to correctly synchronize access to this field.
  (getDefaultParserOptions): Make synchronized, return a clone of the
   options.
  (setDefaultParserOptions): Make synchronized.

* core/src/main/java/org/apache/abdera/filter/ParseFilter.java
  Implement Cloneable.
  (clone): Implement so we can make this public.

* core/src/main/java/org/apache/abdera/filter/TextFilter.java
  Implement Cloneable.
  (clone): Implement so we can make this public.

* core/src/main/java/org/apache/abdera/parser/ParserOptions.java
  (clone): Add to interface so implementations are required to implement
   it.

* core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java
  Implement Cloneable.
  (clone): Implement, so that we can provide deep copies of the filters.

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java?rev=429840&r1=429839&r2=429840&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
Tue Aug  8 14:53:53 2006
@@ -29,10 +29,14 @@
  * within a parsed document.  They are set via the ParserOptions.setParseFilter
  * method.
  */
-public abstract class ParseFilter {
+public abstract class ParseFilter implements Cloneable {
   
   private List<QName> qnames = null;
   private Map<QName,List<QName>> attributes = null;
+  
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
+  }
   
   public void add(QName qname) {
     if (qnames == null) qnames = new ArrayList<QName>();

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java?rev=429840&r1=429839&r2=429840&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
Tue Aug  8 14:53:53 2006
@@ -26,8 +26,12 @@
  * from elements in the Atom feed, including unwanted text and
  * markup in HTML entries.
  */
-public abstract class TextFilter {
+public abstract class TextFilter implements Cloneable {
 
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
+  }
+  
   public String filterText(String text, Element parent) {
     return text;
   }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java?rev=429840&r1=429839&r2=429840&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/ParserOptions.java
Tue Aug  8 14:53:53 2006
@@ -28,6 +28,11 @@
 public interface ParserOptions {
 
   /**
+   * Return a duplicate of this options object.
+   */
+  Object clone() throws CloneNotSupportedException;
+
+  /**
    * Returns the factory the parser should use
    */
   Factory getFactory();

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java?rev=429840&r1=429839&r2=429840&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParserOptions.java
Tue Aug  8 14:53:53 2006
@@ -23,7 +23,7 @@
 import org.apache.abdera.parser.ParserOptions;
 
 public abstract class AbstractParserOptions 
-  implements ParserOptions {
+  implements ParserOptions, Cloneable {
 
   protected Factory factory = null;
   protected String charset = null;
@@ -37,7 +37,23 @@
 
   protected abstract void initFactory();
   protected abstract void checkFactory(Factory factory);
-  
+
+  public Object clone() throws CloneNotSupportedException {
+    AbstractParserOptions copy = (AbstractParserOptions) super.clone();
+   
+    // Object's clone implementation takes care of the rest, we just need
+    // deep copies of the two filters, in case they're carrying around some
+    // state with them.
+ 
+    if (parseFilter != null)
+      copy.parseFilter = (ParseFilter) parseFilter.clone();
+    
+    if (textFilter != null)
+      copy.textFilter = (TextFilter) textFilter.clone();
+    
+    return copy;
+  }
+
   public Factory getFactory() {
     if (factory == null) initFactory();
     return factory;

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java?rev=429840&r1=429839&r2=429840&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
Tue Aug  8 14:53:53 2006
@@ -37,7 +37,12 @@
 public class FOMParser 
   extends AbstractParser 
   implements Parser {
-  
+
+  /**
+   * The current set of default ParserOptions.
+   *
+   * This field is protected by synchronizing on "this".
+   */
   protected ParserOptions options = null;
   
   private FOMFactory getFomFactory(ParserOptions options) {
@@ -123,13 +128,21 @@
   }
   
   @Override
-  public ParserOptions getDefaultParserOptions() {
+  public synchronized ParserOptions getDefaultParserOptions() {
     if (options == null)
       options = new FOMParserOptions();
-    return options;
+    
+    try {
+      return (ParserOptions) options.clone();
+    } catch (CloneNotSupportedException cnse) {
+      // Nothing... 
+    }
+    
+    // About the best we can do if clone doesn't work :(
+    return new FOMParserOptions();
   }
 
-  public void setDefaultParserOptions(ParserOptions options) {
+  public synchronized void setDefaultParserOptions(ParserOptions options) {
     this.options = options;
   }
 



Mime
View raw message