abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1186541 [3/8] - in /abdera/abdera2: ./ .settings/ activities/ activities/.settings/ activities/src/main/java/org/apache/abdera2/activities/client/ activities/src/main/java/org/apache/abdera2/activities/extra/ activities/src/main/java/org/a...
Date Wed, 19 Oct 2011 22:33:52 GMT
Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/WebLink.java Wed Oct 19 22:33:04 2011
@@ -15,14 +15,15 @@ import javax.activation.MimeType;
 
 import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.lang.Lang;
-import org.apache.abdera2.common.mediatype.MimeTypeParseException;
 import org.apache.abdera2.common.text.CharUtils;
 import org.apache.abdera2.common.text.Codec;
-import org.apache.abdera2.common.text.CharUtils.Profile;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
 
 import static org.apache.abdera2.common.text.CharUtils.scanFor;
 import static org.apache.abdera2.common.text.CharUtils.quotedIfNotToken;
-
+import static com.google.common.base.Preconditions.*;
 /**
  * Implements the HTTP Link Header
  * (http://tools.ietf.org/html/rfc5988)
@@ -40,6 +41,133 @@ public class WebLink implements Serializ
   public static final String MEDIA_AURAL = "aural";
   public static final String MEDIA_ALL = "all";
   
+  public static Builder make() {
+    return new Builder();
+  }
+  
+  public static Builder make(WebLink from) {
+    return new Builder(from);
+  }
+  
+  public static class Builder implements Supplier<WebLink> {
+
+    private IRI iri;
+    private final Set<String> rel = 
+      new LinkedHashSet<String>();
+    private IRI anchor;
+    private final Set<String> rev =
+      new LinkedHashSet<String>();
+    private Lang lang;
+    private final Set<String> media = 
+      new LinkedHashSet<String>();
+    private String title;
+    private MimeType mediaType;
+    private final Map<String,String> params = 
+      new HashMap<String,String>();
+
+    public Builder () {}
+    
+    public Builder(WebLink from) {
+      from(from);
+    }
+    
+    public WebLink get() {
+      return new WebLink(this);
+    }
+    
+    public Builder iri(IRI iri) {
+      this.iri = iri;
+      return this;
+    }
+    
+    public Builder from(WebLink link) {
+      this.iri = link.iri;
+      this.rel.clear();
+      this.rel.addAll(link.rel);
+      this.anchor = link.anchor;
+      this.rev.clear();
+      this.rev.addAll(link.rev);
+      this.lang = link.lang;
+      this.media.clear();
+      this.media.addAll(link.media);
+      this.title = link.title;
+      this.mediaType = link.mediaType;
+      this.params.clear();
+      this.params.putAll(link.params);
+      return this;
+    }
+    
+    public Builder iri(String iri) {
+      return iri(new IRI(iri));
+    }
+    
+    public Builder rel(String rel) {
+      this.rel.add(rel);
+      return this;
+    }
+    
+    public Builder anchor(IRI iri) {
+      this.anchor = iri;
+      return this;
+    }
+    
+    public Builder anchor(String iri) {
+      this.anchor = new IRI(iri);
+      return this;
+    }
+    
+    public Builder rev(String rev) {
+      this.rev.add(rev);
+      return this;
+    }
+    
+    public Builder lang(String lang) {
+      this.lang = new Lang(lang);
+      return this;
+    }
+    
+    public Builder lang(Lang lang) {
+      this.lang = lang;
+      return this;
+    }
+    
+    public Builder lang(Locale locale) {
+      this.lang = new Lang(locale);
+      return this;
+    }
+    
+    public Builder media(String media) {
+      this.media.add(media);
+      return this;
+    }
+    
+    public Builder param(String name, String value) {
+      checkNotNull(null);
+      checkArgument(!reserved(name));
+      this.params.put(name,value);
+      return this;
+    }
+    
+    public Builder title(String title) {
+      this.title = title;
+      return this;
+    }
+    
+    public Builder mediaType(String type) {
+      try {
+        this.mediaType = new MimeType(type);
+      } catch (javax.activation.MimeTypeParseException e) {
+        throw new org.apache.abdera2.common.mediatype.MimeTypeParseException(e);
+      }
+      return this;
+    }
+    
+    public Builder mediaType(MimeType type) {
+      this.mediaType = type;
+      return this;
+    }
+  }
+  
   private final IRI iri;
   private final Set<String> rel = 
     new LinkedHashSet<String>();
@@ -54,6 +182,18 @@ public class WebLink implements Serializ
   private final Map<String,String> params = 
     new HashMap<String,String>();
   
+  private WebLink(Builder builder) {
+    this.iri = builder.iri;
+    this.rel.addAll(builder.rel);
+    this.anchor = builder.anchor;
+    this.rev.addAll(builder.rev);
+    this.lang = builder.lang;
+    this.media.addAll(builder.media);
+    this.title = builder.title;
+    this.mediaType = builder.mediaType;
+    this.params.putAll(builder.params);
+  }
+  
   public WebLink(String iri) {
     this(new IRI(iri));
   }
@@ -63,8 +203,7 @@ public class WebLink implements Serializ
   }
   
   public WebLink(IRI iri, String rel) {
-    if (iri == null) 
-      throw new IllegalArgumentException();
+    checkNotNull(iri);
     this.iri = iri.normalize();
     if (rel != null) this.rel.add(rel); // verify
     this.anchor = null;
@@ -74,8 +213,7 @@ public class WebLink implements Serializ
   }
   
   public WebLink(IRI iri) {
-    if (iri == null) 
-      throw new IllegalArgumentException();
+    checkNotNull(iri);
     this.iri = iri;
     this.anchor = null;
     this.lang = null;
@@ -84,11 +222,13 @@ public class WebLink implements Serializ
   }
   
   public IRI getResolvedIri(IRI base) {
+    checkNotNull(base);
     IRI context = getContextIri(base);
     return context != null ? context.resolve(iri) : iri;
   }
   
   public IRI getContextIri(IRI base) {
+    checkNotNull(base);
     if (anchor == null) return base;
     return base != null ? base.resolve(anchor) : anchor;
   }
@@ -97,91 +237,34 @@ public class WebLink implements Serializ
     return iri;
   }
   
-  public void addRel(String rel) {
-    this.rel.add(new IRI(rel).toASCIIString());
-  }
-  
-  public void addRel(IRI rel) {
-    addRel(rel.toASCIIString());
-  }
-  
   public Iterable<String> getRel() {
-    return this.rel;
+    return Iterables.unmodifiableIterable(this.rel);
   }
   
   public IRI getAnchor() {
     return anchor;
   }
   
-  public void setAnchor(IRI iri) {
-    this.anchor = iri;
-  }
-  
-  public void setAnchor(String iri) {
-    setAnchor(new IRI(iri));
-  }
-  
-  public void addRev(String rev) {
-    this.rev.add(new IRI(rev).toASCIIString());
-  }
-  
-  public void addRev(IRI rev) {
-    addRev(rev.toASCIIString());
-  }
-  
   public Iterable<String> getRev() {
-    return this.rev;
+    return Iterables.unmodifiableIterable(this.rev);
   }
   
   public Lang getHrefLang() {
     return lang;
   }
   
-  public void setHrefLang(Lang lang) {
-    this.lang = lang;
-  }
-  
-  public void setHrefLang(String lang) {
-    setHrefLang(Lang.parse(lang));
-  }
-  
-  public void setHrefLang(Locale locale) {
-    setHrefLang(Lang.fromLocale(locale));
-  }
-  
-  public void addMedia(String media) {
-    CharUtils.verify(media, Profile.TOKEN);
-    this.media.add(media.toLowerCase());
-  }
-  
   public Iterable<String> getMedia() {
-    return this.media;
+    return Iterables.unmodifiableIterable(this.media);
   }
   
   public String getTitle() {
     return title;
   }
   
-  public void setTitle(String title) {
-    this.title = title;
-  }
-  
   public MimeType getMediaType() {
     return mediaType;
   }
   
-  public void setMediaType(MimeType mediaType) {
-    this.mediaType = mediaType;
-  }
-  
-  public void setMediaType(String mediaType) {
-    try {
-      setMediaType(new MimeType(mediaType));
-    } catch (javax.activation.MimeTypeParseException t) {
-      throw new MimeTypeParseException(t);
-    }
-  }
-  
   @Override
   public int hashCode() {
     final int prime = 31;
@@ -273,19 +356,9 @@ public class WebLink implements Serializ
     return reserved.contains(name);
   }
   
-  public void addParam(String name, String value) {
-    if (name == null || reserved(name)) 
-      throw new IllegalArgumentException();
-    if (value == null && params.containsKey(name))
-      params.remove(name);
-    else {
-      params.put(name, value);
-    }
-  }
-  
   public String getParam(String name) {
-    if (name == null || reserved(name))
-      throw new IllegalArgumentException();
+    checkNotNull(name);
+    checkArgument(!reserved(name));
     return params.get(name);
   }
   
@@ -392,7 +465,6 @@ public class WebLink implements Serializ
 
   public static Iterable<WebLink> parse(String text) {
     List<WebLink> links = new ArrayList<WebLink>();
-    WebLink weblink = null;
     if (text == null) return Collections.emptyList();
     
     int z = scanFor('<', text, 0, true);
@@ -404,7 +476,7 @@ public class WebLink implements Serializ
         throw new IllegalArgumentException();
       
       String uri = text.substring(s+1,e).trim();
-      weblink = new WebLink(uri);
+      WebLink.Builder maker = WebLink.make().iri(uri);
       
       s = scanFor(';', text,e+1,false);
       while(s != -1 && text.charAt(s) != ',') {
@@ -416,28 +488,28 @@ public class WebLink implements Serializ
         if (name.equalsIgnoreCase("rel")) {
           String[] vals = CharUtils.unquote(val).split("\\s+");
           for (String v : vals)
-            weblink.addRel(v);
+            maker.rel(v);
         } else if (name.equalsIgnoreCase("anchor")) {
-          weblink.setAnchor(CharUtils.unwrap(val, '<', '>'));
+          maker.anchor(CharUtils.unwrap(val, '<', '>'));
         } else if (name.equalsIgnoreCase("rev")) {
           String[] vals = CharUtils.unquote(val).split("\\s+");
           for (String v : vals)
-            weblink.addRev(v);
+            maker.rev(v);
         } else if (name.equalsIgnoreCase("hreflang")) {
-          weblink.setHrefLang(CharUtils.unquote(val));
+          maker.lang(CharUtils.unquote(val));
         } else if (name.equalsIgnoreCase("media")) {
           String[] vals = CharUtils.unquote(val).split("\\s+");
           for (String v : vals)
-            weblink.addMedia(v);
+            maker.media(v);
         } else if (name.equalsIgnoreCase("title")) {
-          weblink.setTitle(CharUtils.unquote(val));
+          maker.title(CharUtils.unquote(val));
         } else if (name.equalsIgnoreCase("type")) {
-          weblink.setMediaType(CharUtils.unquote(val));
+          maker.mediaType(CharUtils.unquote(val));
         } else {
-          weblink.addParam(name,CharUtils.unquote(val));
+          maker.param(name,CharUtils.unquote(val));
         }
       }
-      links.add(weblink);
+      links.add(maker.get());
       if (s == -1) break;
       z = scanFor('<', text, s+1, false);
     }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/CharsetSniffingInputStream.java Wed Oct 19 22:33:04 2011
@@ -27,17 +27,27 @@ import java.io.InputStream;
 public class CharsetSniffingInputStream extends FilterInputStream {
 
     public static enum Encoding {
-        UTF32be("UTF-32", true, new byte[] {0x00, 0x00, 0xFFFFFFFE, 0xFFFFFFFF}), UTF32le("UTF-32", true,
-            new byte[] {0xFFFFFFFF, 0xFFFFFFFE, 0x00, 0x00}), INVALID(null, true, new byte[] {0xFFFFFFFE, 0xFFFFFFFF,
-                                                                                              0x00, 0x00},
-            new byte[] {0x00, 0x00, 0xFFFFFFFF, 0xFFFFFFFE}), UTF16be("UTF-16", true, new byte[] {0xFFFFFFFE,
-                                                                                                  0xFFFFFFFF}), UTF16le(
-            "UTF-16", true, new byte[] {0xFFFFFFFF, 0xFFFFFFFE}), UTF8("UTF-8", true, new byte[] {0xFFFFFFEF,
-                                                                                                  0xFFFFFFBB,
-                                                                                                  0xFFFFFFBF}), UTF32be2(
-            "UTF-32be", false, new byte[] {0x00, 0x00, 0x00, 0x3C}), UTF32le2("UTF-32le", false,
-            new byte[] {0x3C, 0x00, 0x00, 0x00}), UTF16be2("UTF-16be", false, new byte[] {0x00, 0x3C, 0x00, 0x3F}), UTF16le2(
-            "UTF-16le", false, new byte[] {0x3C, 0x00, 0x3F, 0x00});
+        UTF32be("UTF-32", true, 
+            new byte[] {0x00, 0x00, 0xFFFFFFFE, 0xFFFFFFFF}), 
+        UTF32le("UTF-32", true,
+            new byte[] {0xFFFFFFFF, 0xFFFFFFFE, 0x00, 0x00}), 
+        INVALID(null, true, 
+            new byte[] {0xFFFFFFFE, 0xFFFFFFFF, 0x00, 0x00},
+            new byte[] {0x00, 0x00, 0xFFFFFFFF, 0xFFFFFFFE}), 
+        UTF16be("UTF-16", true, 
+            new byte[] {0xFFFFFFFE,0xFFFFFFFF}), 
+        UTF16le("UTF-16", true, 
+            new byte[] {0xFFFFFFFF, 0xFFFFFFFE}), 
+        UTF8("UTF-8", true, 
+            new byte[] {0xFFFFFFEF,0xFFFFFFBB,0xFFFFFFBF}), 
+        UTF32be2("UTF-32be", false, 
+            new byte[] {0x00, 0x00, 0x00, 0x3C}), 
+        UTF32le2("UTF-32le", false, 
+            new byte[] {0x3C, 0x00, 0x00, 0x00}), 
+        UTF16be2("UTF-16be", false, 
+            new byte[] {0x00, 0x3C, 0x00, 0x3F}), 
+        UTF16le2("UTF-16le", false, 
+            new byte[] {0x3C, 0x00, 0x3F, 0x00});
 
         private final String enc;
         private final byte[][] checks;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/Compression.java Wed Oct 19 22:33:04 2011
@@ -27,14 +27,14 @@ import java.util.zip.InflaterInputStream
 
 import org.apache.abdera2.common.text.CharUtils;
 
+import static com.google.common.base.Preconditions.*;
 public class Compression {
 
     public enum CompressionCodec {
         GZIP, XGZIP, DEFLATE;
 
         public static CompressionCodec value(String encoding) {
-            if (encoding == null)
-                throw new IllegalArgumentException();
+          checkNotNull(encoding);
             return valueOf(encoding.toUpperCase().replaceAll("-", ""));
         }
 
@@ -77,12 +77,8 @@ public class Compression {
         OutputStream out, 
         CompressionCodec... codecs)
         throws IOException {
-      if (out == null)
-        throw new IllegalArgumentException(
-            "OutputStream must not be null");
-      if (codecs.length == 0)
-        throw new IllegalArgumentException(
-            "At least one codec must be specified");
+      checkNotNull(out);
+      checkArgument(codecs.length > 0, "At least one codec must be specified");
       for (int n = codecs.length - 1; n >= 0; n--)
         out = codecs[n].wrap(out);
       return out;      
@@ -93,12 +89,8 @@ public class Compression {
         CompressionCodec codec,
         CompressionCodec... codecs)
         throws IOException {
-        if (out == null)
-          throw new IllegalArgumentException(
-              "OutputStream must not be null");
-        if (codec == null)
-          throw new IllegalArgumentException(
-              "At least one codec must be specified");
+        checkNotNull(out);
+        checkArgument(codec != null, "At least one codec must be specified");
         for (int n = codecs.length - 1; n >= 0; n--)
           out = codecs[n].wrap(out);
         out = codec.wrap(out);
@@ -109,12 +101,8 @@ public class Compression {
       InputStream in, 
       CompressionCodec... codecs)
     throws IOException {
-      if (in == null)
-        throw new IllegalArgumentException(
-            "InputStream must not be null");
-      if (codecs.length == 0)
-        throw new IllegalArgumentException(
-            "At least one codec must be specified");
+      checkNotNull(in);
+      checkArgument(codecs.length > 0, "At least one codec must be specified");
       for (int n = codecs.length - 1; n >= 0; n--)
         in = codecs[n].wrap(in);
       return in;
@@ -124,13 +112,9 @@ public class Compression {
         InputStream in, 
         CompressionCodec codec,
         CompressionCodec... codecs) 
-          throws IOException {
-        if (in == null)
-          throw new IllegalArgumentException(
-              "InputStream must not be null");
-        if (codec == null)
-          throw new IllegalArgumentException(
-              "At least one codec must be specified");
+          throws IOException {  
+        checkNotNull(in);
+        checkArgument(codec != null, "At least one codec must be specified");
         for (int n = codecs.length - 1; n >= 0; n--)
           in = codecs[n].wrap(in);
         in = codec.wrap(in);
@@ -141,19 +125,13 @@ public class Compression {
         InputStream in, 
         String ce) 
           throws IOException {
-        if (in == null)
-          throw new IllegalArgumentException(
-              "InputStream must not be null");
+        checkNotNull(in);
         String[] encodings = CharUtils.splitAndTrim(ce);
-        if (encodings.length == 0) 
-          throw new IllegalArgumentException(
-            "At least one codec must be specified");
+        checkArgument(encodings.length > 0, "At least one codec must be specified");
         for (int n = encodings.length - 1; n >= 0; n--) {
             CompressionCodec encoding = 
               getCodec(encodings[n]);
-            if (encoding == null) 
-              throw new IllegalArgumentException(
-                "Invalid Compression Codec");
+            checkNotNull(encoding,"Invalid Compression Codec");
             in = encoding.wrap(in);
         }
         return in;
@@ -162,9 +140,7 @@ public class Compression {
     public static String describe(
         CompressionCodec codec, 
         CompressionCodec... codecs) {
-        if (codec == null && codecs.length == 0)
-          throw new IllegalArgumentException(
-            "At least one codec must be specified");
+        checkArgument(codec != null || codecs.length > 0, "At least one codec must be specified");
         int i = 0;
         if (codec == null) {
           codec = codecs[0];

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/io/FilteredCharReader.java Wed Oct 19 22:33:04 2011
@@ -72,7 +72,7 @@ public class FilteredCharReader extends 
         super(in);
         this.profile = profile;
         this.replacement = replacement;
-        if (replacement != 0 && ((!Character.isValidCodePoint(replacement)) || profile.filter(replacement)))
+        if (replacement != 0 && ((!Character.isValidCodePoint(replacement)) || profile.apply(replacement)))
             throw new IllegalArgumentException();
     }
 
@@ -80,11 +80,11 @@ public class FilteredCharReader extends 
     public int read() throws IOException {
         int c = -1;
         if (replacement == 0) {
-            while (((c = super.read()) != -1 && profile.filter(c))) {
+            while (((c = super.read()) != -1 && profile.apply(c))) {
             }
         } else {
             c = super.read();
-            if (c != -1 && profile.filter(c))
+            if (c != -1 && profile.apply(c))
                 c = replacement;
         }
         return c;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/AbstractScheme.java Wed Oct 19 22:33:04 2011
@@ -16,7 +16,7 @@
  * directory of this distribution.
  */
 package org.apache.abdera2.common.iri;
-
+import static com.google.common.base.Preconditions.*;
 /**
  * Base implementation for IRI scheme providers
  */
@@ -27,8 +27,7 @@ public abstract class AbstractScheme imp
     protected final int port;
 
     protected AbstractScheme(String name, int port) {
-        if (name == null)
-          throw new IllegalArgumentException();
+        checkNotNull(name);
         this.name = name.toLowerCase();
         this.port = port;
     }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/iri/IRI.java Wed Oct 19 22:33:04 2011
@@ -24,7 +24,6 @@ import java.net.URISyntaxException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.abdera2.common.text.CharUtils;
 import org.apache.abdera2.common.text.InvalidCharacterException;
 import org.apache.abdera2.common.text.NormalizationForm;
 import org.apache.abdera2.common.text.UrlEncoding;
@@ -546,8 +545,8 @@ public final class IRI implements Serial
                     port = -1;
             }
             try {
-                CharUtils.verify(userinfo, Profile.IUSERINFO);
-                CharUtils.verify(host, Profile.IHOST);
+              Profile.IUSERINFO.verify(userinfo);
+              Profile.IHOST.verify(host);
             } catch (InvalidCharacterException e) {
                 throw new IRISyntaxException(e);
             }
@@ -566,10 +565,10 @@ public final class IRI implements Serial
                 fragment = irim.group(5);
                 parseAuthority();
                 try {
-                    CharUtils.verify(scheme, Profile.SCHEME);
-                    CharUtils.verify(path, Profile.IPATH);
-                    CharUtils.verify(query, Profile.IQUERY);
-                    CharUtils.verify(fragment, Profile.IFRAGMENT);
+                    Profile.SCHEME.verify(scheme);
+                    Profile.IPATH.verify(path);
+                    Profile.IQUERY.verify(query);
+                    Profile.IFRAGMENT.verify(fragment);
                 } catch (InvalidCharacterException e) {
                     throw new IRISyntaxException(e);
                 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeHelper.java Wed Oct 19 22:33:04 2011
@@ -31,8 +31,10 @@ import org.apache.abdera2.common.Constan
 /**
  * Utilities for working with MIME Media Types
  */
-public class MimeTypeHelper {
+public final class MimeTypeHelper {
 
+    private MimeTypeHelper() {}
+  
     private static final MimeType WILDCARD = createWildcard();
 
     public static String getCharset(String mediatype) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeParseException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeParseException.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeParseException.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/mediatype/MimeTypeParseException.java Wed Oct 19 22:33:04 2011
@@ -29,4 +29,7 @@ public class MimeTypeParseException exte
         super(cause);
     }
 
+    public static MimeTypeParseException wrap(javax.activation.MimeTypeParseException cause) {
+      return new MimeTypeParseException(cause);
+    }
 }

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractItemManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractItemManager.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractItemManager.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractItemManager.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,10 @@
+package org.apache.abdera2.common.misc;
+
+public abstract class AbstractItemManager<T, R> 
+  implements ItemManager<T, R> {
+
+  public T apply(R input) {
+    return get(input);
+  }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractItemManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractResolver.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractResolver.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractResolver.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,9 @@
+package org.apache.abdera2.common.misc;
+
+public abstract class AbstractResolver<T,R> 
+  implements Resolver<T, R> {
+
+  public T apply(R input) {
+    return resolve(input);
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/AbstractResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,92 @@
+package org.apache.abdera2.common.misc;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+
+import static com.google.common.base.Preconditions.*;
+
+public final class Chain<T,R> implements Function<T,R> {
+
+    private final Iterator<Task<T,R>> tasks;
+    private final Function<T,R> to;
+
+    public Chain(Function<T,R> to, Task<T,R>... tasks) {
+      this.to = to;
+      this.tasks = Arrays.asList(tasks).iterator();
+    }
+    
+    public Chain(Function<T,R> to, Iterable<Task<T,R>> tasks) {
+      this.tasks = tasks.iterator();
+      this.to = to;
+    }
+   
+    public R next(T input) {
+        return tasks.hasNext() ? 
+            tasks.next().apply(input, this) : 
+            to.apply(input);
+    }
+
+    public R apply(T input) {
+      return next(input);
+    }
+
+    public static <T,R>Builder<T,R> make() {
+      return new Builder<T,R>();
+    }
+    
+    public static class Builder<T,R> {
+      private final List<Task<T,R>> tasks = 
+        new ArrayList<Task<T,R>>();
+      private Function<T,R> finalTask;
+      private Builder() {}
+      public Builder<T,R> to(Function<T,R> finalTask) {
+        this.finalTask = finalTask;
+        return this;
+      }
+      public Builder<T,R> via(Task<T,R> task) {
+        this.tasks.add(task);
+        return this;
+      }
+      public Builder<T,R> via(Task<T,R>... tasks) {
+        for (Task<T,R> task : tasks)
+          via(task);
+        return this;
+      }
+      public Builder<T,R> via(Iterable<? extends Task<T,R>> tasks) {
+        for (Task<T,R> task : tasks)
+          via(task);
+        return this;
+      }
+      public Builder<T,R> via(Supplier<? extends Task<T,R>> task) {
+        via(task.get());
+        return this;
+      }
+      public Chain<T,R> get() {
+        checkNotNull(finalTask);
+        return new Chain<T,R>(finalTask,tasks);
+      }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Chain.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ExceptionHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ExceptionHelper.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ExceptionHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ExceptionHelper.java Wed Oct 19 22:33:04 2011
@@ -1,5 +1,7 @@
 package org.apache.abdera2.common.misc;
 
+import org.apache.abdera2.common.mediatype.MimeTypeParseException;
+
 public class ExceptionHelper {
 
   public static RuntimeException propogate(Throwable t) {
@@ -7,6 +9,9 @@ public class ExceptionHelper {
       throw (RuntimeException)t;
     else if (t instanceof Error)
       throw (Error)t;
+    else if (t instanceof javax.activation.MimeTypeParseException) 
+      throw MimeTypeParseException.wrap(
+        (javax.activation.MimeTypeParseException)t);
     else return new RuntimeException(t);
   }
   

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ItemManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ItemManager.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ItemManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ItemManager.java Wed Oct 19 22:33:04 2011
@@ -17,11 +17,13 @@
  */
 package org.apache.abdera2.common.misc;
 
+import com.google.common.base.Function;
+
 /**
  * ItemManager is an internal utility class that provides a simple get/release interface. It is used primarily to
  * control access to pooled resources.
  */
-public interface ItemManager<T,R> {
+public interface ItemManager<T,R> extends Function<R,T>{
 
     /**
      * Get an item based on the specified request

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePreconditions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePreconditions.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePreconditions.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePreconditions.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,24 @@
+package org.apache.abdera2.common.misc;
+
+public final class MorePreconditions  {
+
+  private MorePreconditions() {}
+  
+  public static void checkArguments(boolean... expressions) {
+    for (boolean expression : expressions)
+      if (!expression)
+        throw new IllegalArgumentException();
+  }
+  
+  public static void checkArgumentTypes(Object obj, Class<?>... types) {
+    for (Class<?> type : types) 
+      if (type.isInstance(obj))
+        throw new IllegalArgumentException();
+  }
+  
+  public static boolean checkArgument(boolean expression, String message) {
+    if (expression) return expression;
+    throw new IllegalArgumentException(message);
+  }
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePreconditions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePredicates.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePredicates.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePredicates.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePredicates.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,27 @@
+package org.apache.abdera2.common.misc;
+
+import com.google.common.base.Predicate; 
+import static com.google.common.base.Preconditions.*;
+
+public final class MorePredicates {
+
+  private MorePredicates() {}
+  
+  public static Predicate<String> equalsIgnoreCase(final String val) {
+    return new Predicate<String>() {
+      public boolean apply(String input) {
+        checkNotNull(input);
+        checkNotNull(val);
+        return input.equalsIgnoreCase(val);
+      }
+    };
+  }
+  
+  public static Predicate<String> notNullOrEmpty() {
+    return new Predicate<String>() {
+      public boolean apply(String input) {
+        return input != null && input.length() > 0;
+      }
+    };
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MorePredicates.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/PoolManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/PoolManager.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/PoolManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/PoolManager.java Wed Oct 19 22:33:04 2011
@@ -20,14 +20,15 @@ package org.apache.abdera2.common.misc;
 import java.util.Queue;
 import java.util.concurrent.ArrayBlockingQueue;
 
-
 /**
  * Implements a simple pool manager. By default, an upper limit to the pool is set at 25 entries. New items can always
  * be created, but if more than 25 entries are released back to the pool, extras are discarded. Items added to the
  * stack should never maintain any kind of state as it is entirely possible that different threads will be grabbing
  * items from the pool
  */
-public abstract class PoolManager<T,R> implements ItemManager<T,R> {
+public abstract class PoolManager<T,R> 
+  extends AbstractItemManager<T,R>
+  implements ItemManager<T,R> {
 
     private static final int DEFAULT_SIZE = 25;
     private final Queue<T> pool;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Resolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Resolver.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Resolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Resolver.java Wed Oct 19 22:33:04 2011
@@ -17,11 +17,13 @@
  */
 package org.apache.abdera2.common.misc;
 
+import com.google.common.base.Function;
+
 /**
  * The Resolver interface is a utility class used to resolve objects based on a request. It is used internally by Abdera
  * as the basis for Target and Subject resolvers.
  */
-public interface Resolver<T,R> {
+public interface Resolver<T,R> extends Function<R,T> {
 
     T resolve(R key);
 

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Task.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Task.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Task.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Task.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,28 @@
+package org.apache.abdera2.common.misc;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+public interface Task<T,R> {
+
+    /**
+     * Process the input. When done, the task must call flow.next(input) to 
+     * pass the request on to the next Task
+     */
+  R apply(T input, Chain<T,R> flow);
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Task.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractBaseRequestContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractBaseRequestContext.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractBaseRequestContext.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractBaseRequestContext.java Wed Oct 19 22:33:04 2011
@@ -31,12 +31,12 @@ public abstract class AbstractBaseReques
   implements RequestContext {
 
     protected final Provider provider;
-    protected Subject subject;
-    protected Principal principal;
-    protected Target target;
     protected final String method;
     protected final IRI requestUri;
     protected final IRI baseUri;
+    protected Subject subject;
+    protected Principal principal;
+    protected Target target;
     
     protected AbstractBaseRequestContext(
         Provider provider, 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java Wed Oct 19 22:33:04 2011
@@ -17,18 +17,19 @@
  */
 package org.apache.abdera2.common.protocol;
 
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.abdera2.common.text.UrlEncoding;
-import org.apache.abdera2.common.date.DateTime;
+import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.joda.time.DateTime;
 
 /**
- * Base CollectionAdapter implementation that provides a number of helper utility methods for adapter implementations.
+ * Base CollectionAdapter implementation that provides a number of helper 
+ * utility methods for adapter implementations.
  */
 @SuppressWarnings("unchecked")
 public abstract class AbstractCollectionAdapter 
@@ -37,10 +38,12 @@ public abstract class AbstractCollection
              Transactional,
              CollectionInfo {
 
-    private final static Log log = LogFactory.getLog(AbstractCollectionAdapter.class);
+    private final static Log log = 
+      LogFactory.getLog(AbstractCollectionAdapter.class);
 
     private String href;
-    private Map<String, Object> hrefParams = new HashMap<String, Object>();
+    private Map<String, Object> hrefParams = 
+      new HashMap<String, Object>();
 
     public AbstractCollectionAdapter() {
         super();
@@ -108,10 +111,10 @@ public abstract class AbstractCollection
      * Creates the ResponseContext for a HEAD entry request. By default, an EmptyResponseContext is returned. The Etag
      * header will be set.
      */
-    protected <S extends ResponseContext>S buildHeadEntryResponse(RequestContext request, String id, Date updated)
+    protected <S extends ResponseContext>S buildHeadEntryResponse(RequestContext request, String id, DateTime updated)
         throws ResponseContextException {
         EmptyResponseContext rc = new EmptyResponseContext(200);
-        rc.setEntityTag(EntityTag.generate(id, DateTime.format(updated)));
+        rc.setEntityTag(EntityTag.generate(id, DateTimes.format(updated)));
         return (S)rc;
     }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractMessage.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractMessage.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractMessage.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractMessage.java Wed Oct 19 22:33:04 2011
@@ -40,7 +40,7 @@ public abstract class AbstractMessage im
 
     public CacheControl getCacheControl() {
         String cc = getHeader("Cache-Control");
-        return cc != null ? new CacheControl(cc) : null;
+        return cc != null ? CacheControl.parse(cc) : null;
     }
 
     public String getContentLanguage() {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractServiceManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractServiceManager.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractServiceManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractServiceManager.java Wed Oct 19 22:33:04 2011
@@ -41,9 +41,6 @@ public abstract class AbstractServiceMan
 
     protected AbstractServiceManager() {}
 
-    /* (non-Javadoc)
-     * @see org.apache.abdera2.protocol.server.IServiceManager#newProcessorQueue(java.util.Map)
-     */
     public ProcessorQueue newProcessorQueue(Map<String, String> properties) {
       String instance = properties.get(PROCESSORQUEUE);
       if (instance == null)
@@ -53,9 +50,6 @@ public abstract class AbstractServiceMan
       return queue;
     }
     
-    /* (non-Javadoc)
-     * @see org.apache.abdera2.protocol.server.IServiceManager#newTaskExecutor(java.util.Map)
-     */
     public TaskExecutor newTaskExecutor(Map<String, String> properties) {
       String instance = properties.get(TASKEXECUTOR);
       if (instance == null)
@@ -66,9 +60,6 @@ public abstract class AbstractServiceMan
       return exec;
     }
     
-    /* (non-Javadoc)
-     * @see org.apache.abdera2.protocol.server.IServiceManager#newChannelManager(java.util.Map)
-     */
     public ChannelManager newChannelManager(Map<String, String> properties) {
       String instance = properties.get(CHANNELMANAGER);
       if (instance == null)

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseProvider.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseProvider.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseProvider.java Wed Oct 19 22:33:04 2011
@@ -79,6 +79,10 @@ public abstract class BaseProvider
 
     protected abstract Resolver<Target, RequestContext> getTargetResolver(RequestContext request);
 
+    public ResponseContext apply(RequestContext request) {
+      return process(request);
+    }
+    
     public <S extends ResponseContext>S process(RequestContext request) {
         Target target = request.getTarget();
         if (target == null || target.getType() == TargetType.TYPE_NOT_FOUND) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java Wed Oct 19 22:33:04 2011
@@ -26,24 +26,24 @@ import org.apache.abdera2.common.http.Qu
 import org.apache.abdera2.common.http.QualityHelper.QToken;
 import org.apache.abdera2.common.io.Compression;
 import org.apache.abdera2.common.io.Compression.CompressionCodec;
+import org.apache.abdera2.common.misc.Chain;
 
 /**
  * Abdera Filter implementation that selectively applies compression to the response payload
  */
 public class CompressionFilter implements Filter {
 
-    @SuppressWarnings("unchecked")
-    public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
+    public ResponseContext apply(RequestContext request, Chain<RequestContext,ResponseContext> chain) {
         String encoding = request.getHeader("Accept-Encoding");
         QToken[] encodings = encoding != null ? QualityHelper.orderByQ(encoding) : new QToken[0];
         for (QToken enc : encodings) {
             try {
                 CompressionCodec codec = CompressionCodec.valueOf(enc.token().toUpperCase());
-                return (S)new CompressingResponseContextWrapper(chain.next(request), codec);
+                return new CompressingResponseContextWrapper(chain.next(request), codec);
             } catch (Exception e) {
             }
         }
-        return (S)chain.next(request);
+        return chain.next(request);
     }
 
     /**

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java Wed Oct 19 22:33:04 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.common.protocol;
 
+import org.apache.abdera2.common.misc.Task;
+
 
 /**
  * Filters are invoked by AbderaServlet immediately before passing the request off to the Provider for processing The
@@ -25,12 +27,12 @@ package org.apache.abdera2.common.protoc
  * 
  * @author jasnell
  */
-public interface Filter {
+public interface Filter extends Task<RequestContext,ResponseContext> {
 
-    /**
-     * Process the filter request. The filter must call chain.next(request) to pass the request on to the next filter or
-     * the provider.
-     */
-  <S extends ResponseContext>S filter(RequestContext request, FilterChain chain);
+//    /**
+//     * Process the filter request. The filter must call chain.next(request) to pass the request on to the next filter or
+//     * the provider.
+//     */
+//  <S extends ResponseContext>S filter(RequestContext request, FilterChain chain);
 
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java Wed Oct 19 22:33:04 2011
@@ -17,16 +17,17 @@
  */
 package org.apache.abdera2.common.protocol;
 
-import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
+import org.apache.abdera2.common.misc.Chain;
 
 /**
  * Abdera Filter implementation that supports the use of the X-HTTP-Method-Override header used by GData.
  */
-@SuppressWarnings({ "unchecked"})
 public class MethodOverrideFilter implements Filter {
 
-    private String[] methods;
+    private Set<String> methods = new HashSet<String>();
 
     public MethodOverrideFilter() {
         this("DELETE", "PUT", "PATCH");
@@ -36,17 +37,17 @@ public class MethodOverrideFilter implem
         setMethods(methods);
     }
 
-    public String[] getMethods() {
+    public Iterable<String> getMethods() {
         return methods;
     }
 
     public void setMethods(String... methods) {
-        this.methods = methods;
-        Arrays.sort(methods);
+        for (String method : methods)
+          this.methods.add(method);
     }
 
-    public <S extends ResponseContext>S filter(RequestContext request, FilterChain chain) {
-        return (S)chain.next(new MethodOverrideRequestContext(request));
+    public ResponseContext apply(RequestContext request, Chain<RequestContext,ResponseContext> chain) {
+        return chain.next(new MethodOverrideRequestContext(request));
     }
 
     private class MethodOverrideRequestContext extends BaseRequestContextWrapper {
@@ -61,7 +62,7 @@ public class MethodOverrideFilter implem
                 xheader = getHeader("X-Method-Override");
             if (xheader != null)
                 xheader = xheader.toUpperCase().trim();
-            if (method.equals("POST") && xheader != null && Arrays.binarySearch(methods, xheader) > -1) {
+            if (method.equals("POST") && xheader != null && methods.contains(method)) {
                 method = xheader;
             }
             this.method = method;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java Wed Oct 19 22:33:04 2011
@@ -21,6 +21,8 @@ import java.util.Map;
 
 import javax.security.auth.Subject;
 
+import com.google.common.base.Function;
+
 /**
  * Providers are responsible for processing all requests to the Atompub server.<br>
  * Actual request processing is delegated to {@link AtompubRequestProcessor} implementations, depending on the request
@@ -28,9 +30,9 @@ import javax.security.auth.Subject;
  */
 @SuppressWarnings("rawtypes")
 public interface Provider
-  extends TargetBuilder {
+  extends TargetBuilder, Function<RequestContext,ResponseContext> {
 
-    /**
+    /**`
      * Initialize the Provider.
      */
     void init(Map<String, String> properties);

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RegexTargetResolver.java Wed Oct 19 22:33:04 2011
@@ -25,8 +25,13 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.abdera2.common.misc.AbstractResolver;
 import org.apache.abdera2.common.misc.Resolver;
 
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+import static org.apache.abdera2.common.misc.MorePredicates.*;
 /**
  * <p>
  * Provides a utility class helpful for determining which type of resource the client is requesting. Each resource type
@@ -52,19 +57,19 @@ import org.apache.abdera2.common.misc.Re
  * </pre>
  */
 public class RegexTargetResolver<R extends RequestContext>
+  extends AbstractResolver<Target,R>
   implements Resolver<Target,R> {
 
     protected final Map<Pattern, TargetType> patterns;
-    protected final Map<Pattern, String[]> fields;
+    protected final Multimap<Pattern,String> fields = 
+      LinkedHashMultimap.create();
 
     public RegexTargetResolver() {
         this.patterns = new HashMap<Pattern, TargetType>();
-        this.fields = new HashMap<Pattern, String[]>();
     }
 
     public RegexTargetResolver(Map<String, TargetType> patterns) {
         this.patterns = new HashMap<Pattern, TargetType>();
-        this.fields = new HashMap<Pattern, String[]>();
         for (String p : patterns.keySet()) {
             TargetType type = patterns.get(p);
             setPattern(p, type);
@@ -78,7 +83,7 @@ public class RegexTargetResolver<R exten
     public RegexTargetResolver<R> setPattern(String pattern, TargetType type, String... fields) {
         Pattern p = Pattern.compile(pattern);
         this.patterns.put(p, type);
-        this.fields.put(p, fields);
+        this.fields.putAll(p,Arrays.asList(fields));
         return this;
     }
 
@@ -88,14 +93,14 @@ public class RegexTargetResolver<R exten
             Matcher matcher = pattern.matcher(uri);
             if (matcher.matches()) {
                 TargetType type = this.patterns.get(pattern);
-                String[] fields = this.fields.get(pattern);
+                Iterable<String> fields = this.fields.get(pattern);
                 return getTarget(type, request, matcher, fields);
             }
         }
         return null;
     }
 
-    protected Target getTarget(TargetType type, RequestContext request, Matcher matcher, String[] fields) {
+    protected Target getTarget(TargetType type, RequestContext request, Matcher matcher, Iterable<String> fields) {
         return new RegexTarget(type, request, matcher, fields);
     }
 
@@ -104,8 +109,8 @@ public class RegexTargetResolver<R exten
         buf.append("Regex Target Resolver:\n");
         for (Pattern pattern : patterns.keySet()) {
             TargetType type = this.patterns.get(pattern);
-            String[] fields = this.fields.get(pattern);
-            buf.append(pattern.toString() + ", Type: " + type + ", Fields: " + Arrays.toString(fields));
+            Iterable<String> fields = this.fields.get(pattern);
+            buf.append(pattern.toString() + ", Type: " + type + ", Fields: " + fields);
         }
         return buf.toString();
     }
@@ -146,9 +151,13 @@ public class RegexTargetResolver<R exten
 
         private static final long serialVersionUID = 165211244926064449L;
         protected Matcher matcher;
-        protected String[] fields;
+        protected Iterable<String> fields;
 
-        public RegexTarget(TargetType type, RequestContext context, Matcher matcher, String[] fields) {
+        public RegexTarget(
+          TargetType type, 
+          RequestContext context, 
+          Matcher matcher, 
+          Iterable<String> fields) {
             super(type, context);
             this.matcher = matcher;
             this.fields = fields;
@@ -157,11 +166,9 @@ public class RegexTargetResolver<R exten
         public String getParameter(String name) {
             if (fields == null)
                 return super.getParameter(name);
-            int idx = 0;
-            for (int n = 0; n < fields.length; n++)
-                if (fields[n].equalsIgnoreCase(name))
-                    idx = n + 1;
-            return idx > 0 && idx <= matcher.groupCount() ? matcher.group(idx) : super.getParameter(name);
+            int idx = Iterables.indexOf(fields, equalsIgnoreCase(name));
+            return idx > -1 && idx <= matcher.groupCount()-1 ? 
+              matcher.group(idx+1) : super.getParameter(name);
         }
 
         public Iterable<String> getParameterNames() {
@@ -170,7 +177,7 @@ public class RegexTargetResolver<R exten
             for (String name : names)
               list.add(name);
             if (fields != null)
-                list.addAll(Arrays.asList(fields));
+                Iterables.addAll(list, fields);
             return list;
         }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RouteManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RouteManager.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RouteManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RouteManager.java Wed Oct 19 22:33:04 2011
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.abdera2.common.misc.AbstractResolver;
 import org.apache.abdera2.common.misc.Resolver;
 import org.apache.abdera2.common.templates.CachingContext;
 import org.apache.abdera2.common.templates.Context;
@@ -46,6 +47,7 @@ import org.apache.abdera2.common.templat
  * The RouteManager can be used by Provider implementations as the target resolver and target builder
  */
 public class RouteManager<T,X extends RequestContext> 
+  extends AbstractResolver<Target,X>
   implements Resolver<Target,X>, 
              TargetBuilder<T> {
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/SimpleSubjectResolver.java Wed Oct 19 22:33:04 2011
@@ -22,12 +22,14 @@ import java.security.Principal;
 
 import javax.security.auth.Subject;
 
+import org.apache.abdera2.common.misc.AbstractResolver;
 import org.apache.abdera2.common.misc.Resolver;
 
 /**
  * The default subject resolver implementation
  */
 public class SimpleSubjectResolver 
+  extends AbstractResolver<Subject,Request>
   implements Resolver<Subject,Request> {
 
     public static final Principal ANONYMOUS = new AnonymousPrincipal();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TemplateManagerTargetBuilder.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TemplateManagerTargetBuilder.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TemplateManagerTargetBuilder.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TemplateManagerTargetBuilder.java Wed Oct 19 22:33:04 2011
@@ -17,78 +17,50 @@
  */
 package org.apache.abdera2.common.protocol;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Map;
 
 import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.templates.Context;
 import org.apache.abdera2.common.templates.MapContext;
 import org.apache.abdera2.common.templates.ObjectContext;
+import org.apache.abdera2.common.templates.Template;
 import org.apache.abdera2.common.templates.TemplateManager;
 
 public class TemplateManagerTargetBuilder<T> 
   extends TemplateManager<T>
   implements TargetBuilder<T> {
 
-  public TemplateManagerTargetBuilder() {
-    super();
-  }
-
-  public TemplateManagerTargetBuilder(boolean iri) {
-    super(iri);
-  }
-
-  public TemplateManagerTargetBuilder(Context defaults) {
-    super(defaults);
-  }
-
-  public TemplateManagerTargetBuilder(IRI base, boolean iri) {
-    super(base, iri);
-  }
-
-  public TemplateManagerTargetBuilder(IRI base, Context defaults) {
-    super(base, defaults);
-  }
-
-  public TemplateManagerTargetBuilder(IRI base, Object defaults, boolean isiri) {
-    super(base, defaults, isiri);
-  }
-
-  public TemplateManagerTargetBuilder(IRI base, Object defaults) {
-    super(base, defaults);
-  }
-
-  public TemplateManagerTargetBuilder(IRI base) {
-    super(base);
+  public static <T>Builder<T> make() {
+    return new Builder<T>();
   }
-
-  public TemplateManagerTargetBuilder(Object defaults, boolean isiri) {
-    super(defaults, isiri);
-  }
-
-  public TemplateManagerTargetBuilder(Object defaults) {
-    super(defaults);
-  }
-
-  public TemplateManagerTargetBuilder(String base, boolean iri) {
-    super(base, iri);
-  }
-
-  public TemplateManagerTargetBuilder(String base, Context defaults) {
-    super(base, defaults);
-  }
-
-  public TemplateManagerTargetBuilder(String base, Object defaults,
-      boolean isiri) {
-    super(base, defaults, isiri);
-  }
-
-  public TemplateManagerTargetBuilder(String base, Object defaults) {
-    super(base, defaults);
-  }
-
-  public TemplateManagerTargetBuilder(String base) {
-    super(base);
+  
+  public static <T>TemplateManagerTargetBuilder<T> fromMap(Map<T,Object> map) {
+    checkNotNull(map);
+    Builder<T> b = make();
+    b.add(map);
+    return (TemplateManagerTargetBuilder<T>) b.get();
+  }
+  
+  public static class Builder<T> extends TemplateManager.Builder<T> {
+    public TemplateManager<T> get() {
+      return new TemplateManagerTargetBuilder<T>(
+        templates,isiri,base,contextDefaults);
+    }
+    public TemplateManagerTargetBuilder<T> getTargetBuilder() {
+      return (TemplateManagerTargetBuilder<T>) get();
+    }
   }
+  
+  TemplateManagerTargetBuilder(
+      Map<T,Template> templates, 
+      boolean isiri, 
+      IRI base, 
+      Context contextDefaults) {
+        super(templates,isiri,base,contextDefaults);
+    }
+  
 
   public String urlFor(Request request, T key, Object param) {
     RequestContext rc = (RequestContext) request;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/AbstractAbderaServlet.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/AbstractAbderaServlet.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/AbstractAbderaServlet.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/AbstractAbderaServlet.java Wed Oct 19 22:33:04 2011
@@ -32,9 +32,9 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.misc.Chain;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.FilterChain;
 import org.apache.abdera2.common.protocol.Provider;
 import org.apache.abdera2.common.protocol.ServiceManager;
 import org.apache.commons.logging.Log;
@@ -80,8 +80,11 @@ public abstract class AbstractAbderaServ
       HttpServletResponse response,
       ServletContext context) {
       RequestContext reqcontext = new ServletRequestContext(provider, request, context);
-      FilterChain chain = 
-        new FilterChain(provider, reqcontext);
+      Chain<RequestContext,ResponseContext> chain = 
+        Chain.<RequestContext,ResponseContext>make()
+        .to(provider)
+        .via(provider.getFilters(reqcontext))
+        .get();
       try {
           output(request, response, chain.next(reqcontext));
       } catch (Throwable t) {

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/async/AbderaTask.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/async/AbderaTask.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/async/AbderaTask.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/async/AbderaTask.java Wed Oct 19 22:33:04 2011
@@ -27,9 +27,9 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.misc.Chain;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.FilterChain;
 import org.apache.abdera2.common.protocol.Provider;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -95,8 +95,11 @@ public class AbderaTask {
     Provider provider,
     HttpServletRequest request,
     HttpServletResponse response) {
-    FilterChain chain = 
-      new FilterChain(provider, requestContext);
+    Chain<RequestContext,ResponseContext> chain =
+      Chain.<RequestContext,ResponseContext>make()
+      .to(provider)
+      .via(provider.getFilters(requestContext))
+      .get();
     try {
         log.debug(String.format("Using RequestContext: %s",requestContext.getClass().getName()));
         output(request, response, chain.next(requestContext), provider);

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/MapChannelManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/MapChannelManager.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/MapChannelManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/MapChannelManager.java Wed Oct 19 22:33:04 2011
@@ -20,7 +20,7 @@ package org.apache.abdera2.common.pusher
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
-
+import static com.google.common.base.Preconditions.*;
 
 /**
  * ChannelManager implementation based on an internal HashMap of Pusher/Receiver pairs
@@ -53,9 +53,7 @@ public abstract class MapChannelManager 
   }
   
   private synchronized Channel get(String channel, boolean skip) {
-    if (!skip && shuttingDown)
-      throw new IllegalStateException(
-        "Channel Manager is shutting down");
+    checkState(!(!skip && shuttingDown),"Channel Manager is shutting down");
     Channel c = map.get(channel);
     if (c == null) {
       c = createChannel();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorListener.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorListener.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorListener.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorListener.java Wed Oct 19 22:33:04 2011
@@ -21,11 +21,11 @@ import org.apache.abdera2.common.selecto
 public class SelectorListener<T> 
   implements Listener<T> {
 
-  private final Selector selector;
+  private final Selector<?> selector;
   private final Listener<T> listener;
 
   public SelectorListener(
-    Selector selector,
+    Selector<?> selector,
     Listener<T> listener) {
     this.selector = selector;
     this.listener = listener;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorPusher.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorPusher.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorPusher.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/pusher/SelectorPusher.java Wed Oct 19 22:33:04 2011
@@ -23,10 +23,10 @@ public class SelectorPusher<T> 
   extends AbstractPusher<T> {
 
   private final Pusher<T> pusher;
-  private final Selector selector;
+  private final Selector<?> selector;
   
   public SelectorPusher(
-      Selector selector, 
+      Selector<?> selector, 
       Pusher<T> pusher) {
     this.selector = selector;
     this.pusher = pusher;

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java Wed Oct 19 22:33:04 2011
@@ -13,8 +13,10 @@ import org.apache.abdera2.common.misc.Ex
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.binary.Hex;
 
-public class HashHelper {
+public final class HashHelper {
 
+  private HashHelper() {}
+  
   public static String sig(PrivateKey key, String alg, byte[] mat) {
     try {
       Signature sig = Signature.getInstance(alg);

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/KeyHelper.java Wed Oct 19 22:33:04 2011
@@ -45,8 +45,10 @@ import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Hex;
 
-public class KeyHelper {
+public final class KeyHelper {
 
+  private KeyHelper() {}
+  
     public static void saveKeystore(KeyStore ks, String file, String password) throws KeyStoreException,
         NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException {
         ks.store(new FileOutputStream(file), password.toCharArray());

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,34 @@
+package org.apache.abdera2.common.selector;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Constraint;
+
+public abstract class AbstractSelector<X> 
+  implements Selector<X> {
+
+  public boolean apply(X item) {
+    return select(item);
+  }
+  
+  public X checkElement(X element) {
+    if (apply(element))
+      return element;
+    throw new IllegalArgumentException();
+  }
+
+  public Function<X,Boolean> asFunction() {
+    return Utils.asFunction(this);
+  }
+  
+  public Predicate<X> asPredicate() {
+    return this;
+  }
+  public Constraint<X> asConstraint() {
+    return this;
+  }
+  public <Y>Selector<Y> compose(Function<Y,X> transform) {
+    return Utils.compose(this, transform);
+  }
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/AbstractSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/InvertedSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/InvertedSelector.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/InvertedSelector.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/InvertedSelector.java Wed Oct 19 22:33:04 2011
@@ -3,12 +3,13 @@ package org.apache.abdera2.common.select
 /**
  * Selector that inverts the results of the wrapped selector
  */
-public class InvertedSelector 
-  implements Selector {
+public class InvertedSelector<X> 
+  extends AbstractSelector<X>
+  implements Selector<X> {
 
-  private final Selector selector;
+  private final Selector<X> selector;
   
-  public InvertedSelector(Selector selector) {
+  public InvertedSelector(Selector<X> selector) {
     this.selector = selector;
   }
   

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/MultiSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/MultiSelector.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/MultiSelector.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/MultiSelector.java Wed Oct 19 22:33:04 2011
@@ -22,21 +22,25 @@ package org.apache.abdera2.common.select
  * invoked in order. By default, the selector will accept the item unless one 
  * of the selectors rejects it. 
  */
-public class MultiSelector 
-  implements Selector {
+public final class MultiSelector<X> 
+  extends AbstractSelector<X>
+  implements Selector<X> {
 
   private static final long serialVersionUID = 5257601171344714824L;
-  private final Selector[] selectors;
+  private final Selector<X>[] selectors;
   
-  public MultiSelector(Selector... selectors) {
+  public MultiSelector(Selector<X>... selectors) {
     this.selectors = selectors;
   }
   
   public boolean select(Object item) {
-    for (Selector selector : selectors)
+    for (Selector<X> selector : selectors)
         if (!selector.select(item))
             return false;
     return true;
   }
 
+  public static <X>Selector<X> with(Selector<X>... selectors) {
+    return new MultiSelector<X>(selectors);
+  }
 }

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/PropertySelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/PropertySelector.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/PropertySelector.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/PropertySelector.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,56 @@
+package org.apache.abdera2.common.selector;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.abdera2.common.misc.ExceptionHelper;
+
+import com.google.common.base.Predicate;
+import static com.google.common.base.Preconditions.*;
+
+public final class PropertySelector<X> 
+  extends AbstractSelector<X>
+  implements Selector<X> {
+
+  private final Method method;
+  private final Predicate<? super Object> predicate;
+  private final boolean matchnull;
+  
+  PropertySelector(Method method, Predicate<? super Object> predicate, boolean matchnull) {
+    this.method = method;
+    this.predicate = predicate;
+    this.matchnull = matchnull;
+    checkNotNull(method);
+    checkNotNull(predicate);
+    checkArgument(this.method.getParameterTypes().length == 0, "Checked property must have no arguments!");
+  }
+  
+  public boolean select(Object item) {
+    try {
+      Object obj = method.invoke(item);
+      if (obj != null)
+        return predicate.apply(obj);
+      else return matchnull;
+    } catch (Throwable e) {
+      throw ExceptionHelper.propogate(e);
+    } 
+  }
+
+  @SuppressWarnings({ "rawtypes" })
+  public static <X>PropertySelector<X> create(Class<X> _class, String method, Predicate predicate) {
+    return create(_class,method,predicate,false);
+  }
+  
+  @SuppressWarnings({ "unchecked", "rawtypes" })
+  public static <X>PropertySelector<X> create(Class<X> _class, String method, Predicate predicate, boolean matchnull) {
+    try {
+      Method m = _class.getMethod(method);
+      int mods = m.getModifiers();
+      checkArgument(!Modifier.isPrivate(mods),"Checked property must not be private!");
+      checkArgument(!Modifier.isStatic(mods), "Checked property must not be static!");
+      return new PropertySelector(m, predicate, matchnull);
+    } catch (Throwable e) {
+      throw ExceptionHelper.propogate(e);
+    } 
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/PropertySelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/Selector.java Wed Oct 19 22:33:04 2011
@@ -17,13 +17,81 @@
  */
 package org.apache.abdera2.common.selector;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Constraint;
+
 /**
  * Utility interface that is used as a Filter in several places 
  * throughout the Abdera API.
  */
-public interface Selector {
+public interface Selector<X>
+  extends Predicate<X>, Constraint<X> {
 
     /** Returns true the item is to be selected **/
     boolean select(Object item);
 
+    public Function<X,Boolean> asFunction();
+    public Predicate<X> asPredicate();
+    public Constraint<X> asConstraint();
+    public <Y>Selector<Y> compose(Function<Y,X> transform);
+    
+    public static class Utils {
+      
+      public static <X,Y>Selector<Y> compose(Selector<X> selector, Function<Y,X> transform) {
+        TransformSelector<Y,X> tsel = 
+          new TransformSelector<Y,X>(selector,transform);
+        return tsel;
+      }
+      
+      public static <X>Function<X,Boolean> asFunction(final Selector<X> selector) {
+        return new Function<X,Boolean>() {
+          public Boolean apply(X input) {
+            return selector.apply(input);
+          }
+        };
+      }
+      
+      public static <X>Selector<X> negate(Selector<X> selector) {
+        return new InvertedSelector<X>(selector);
+      }
+      
+      public static <X>Selector<X> forPredicate(
+        Predicate<X> predicate) {
+          return new PredicateSelector<X>(predicate);
+      }
+      
+      public static <X>Selector<X> forConstraint(
+        Constraint<X> constraint) {
+          return new ConstraintSelector<X>(constraint);
+      }
+      
+    }
+    
+    public static class ConstraintSelector<X>
+      extends AbstractSelector<X> {
+      private final Constraint<X> internal;
+      ConstraintSelector(Constraint<X> internal) {
+        this.internal = internal;
+      }
+      @SuppressWarnings("unchecked")
+      public boolean select(Object item) {
+        return internal.checkElement((X)item) == item;
+      }
+      public X checkElement(X element) {
+        return internal.checkElement(element);
+      }
+    }
+    
+    public static class PredicateSelector<X> 
+      extends AbstractSelector<X> {
+      private final Predicate<X> internal;
+      PredicateSelector(Predicate<X> internal) {
+        this.internal = internal;
+      }
+      @SuppressWarnings("unchecked")
+      public boolean select(Object item) {
+        return this.internal.apply((X)item);
+      }
+    }
 }

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/TransformSelector.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/TransformSelector.java?rev=1186541&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/TransformSelector.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/TransformSelector.java Wed Oct 19 22:33:04 2011
@@ -0,0 +1,24 @@
+package org.apache.abdera2.common.selector;
+
+import com.google.common.base.Function;
+
+
+public class TransformSelector<X,Y>
+  extends AbstractSelector<X> {
+
+  private final Selector<Y> inner;
+  private final Function<X,Y> function;
+  
+  public TransformSelector(
+    Selector<Y> selector, 
+    Function<X,Y> transform) {
+      this.inner = selector;
+      this.function = transform;
+  }
+  
+  @SuppressWarnings("unchecked")
+  public boolean select(Object item) {
+    return inner.select((Y)function.apply((X)item));
+  }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/selector/TransformSelector.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/AnnotationContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/AnnotationContext.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/AnnotationContext.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/AnnotationContext.java Wed Oct 19 22:33:04 2011
@@ -1,6 +1,7 @@
 package org.apache.abdera2.common.templates;
 
 import org.apache.abdera2.common.anno.Param;
+import static com.google.common.base.Preconditions.*;
 
 public class AnnotationContext extends MapContext {
 
@@ -16,15 +17,14 @@ public class AnnotationContext extends M
   }
   
   public AnnotationContext(Object object) {
+    checkNotNull(object);
     org.apache.abdera2.common.anno.Context context = getContext(object);
-    if (object == null)
-      throw new IllegalArgumentException();
-    else process(context);
+    checkNotNull(context);
+    process(context);
   }
   
   public static org.apache.abdera2.common.anno.Context getContext(Object object) {
-    if (object == null) 
-      throw new IllegalArgumentException();
+    checkNotNull(object);
     Class<?> _class = 
       object instanceof Class<?> ? 
           (Class<?>)object : object.getClass();

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/CachingContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/CachingContext.java?rev=1186541&r1=1186540&r2=1186541&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/CachingContext.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/templates/CachingContext.java Wed Oct 19 22:33:04 2011
@@ -30,7 +30,8 @@ public abstract class CachingContext ext
 
     private static final long serialVersionUID = 8912954163958644811L;
     
-    private Map<String, Object> cache = new HashMap<String, Object>();
+    private Map<String, Object> cache = 
+      new HashMap<String, Object>();
 
     public <T> T resolve(String var) {
         T t = (T)cache.get(var);



Mime
View raw message