abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1187599 [3/4] - in /abdera/abdera2: activities/src/main/java/org/apache/abdera2/activities/client/ activities/src/main/java/org/apache/abdera2/activities/protocol/ activities/src/main/java/org/apache/abdera2/activities/protocol/basic/ acti...
Date Fri, 21 Oct 2011 23:47:53 GMT
Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java (original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java Fri Oct 21 23:47:50 2011
@@ -25,9 +25,9 @@ import java.util.List;
 
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.common.misc.Chain;
+import org.apache.abdera2.common.misc.Task;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.Filter;
 import org.apache.abdera2.model.Document;
 import org.apache.abdera2.model.Element;
 import org.apache.abdera2.parser.ParseException;
@@ -38,7 +38,7 @@ import org.apache.abdera2.security.Encry
 import org.apache.abdera2.security.EncryptionOptions;
 
 @SuppressWarnings("unchecked")
-public abstract class AbstractEncryptedRequestFilter implements Filter {
+public abstract class AbstractEncryptedRequestFilter implements Task<RequestContext,ResponseContext> {
 
     // The methods that allow encrypted bodies
     protected final List<String> methods = new ArrayList<String>();

Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java (original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java Fri Oct 21 23:47:50 2011
@@ -26,9 +26,9 @@ import java.security.Security;
 
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.common.misc.Chain;
+import org.apache.abdera2.common.misc.Task;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.Filter;
 import org.apache.abdera2.model.Document;
 import org.apache.abdera2.model.Element;
 import org.apache.abdera2.protocol.server.AtompubResponseContext;
@@ -38,7 +38,7 @@ import org.apache.abdera2.security.Encry
 import org.apache.abdera2.security.EncryptionOptions;
 import org.apache.abdera2.writer.Writer;
 
-public abstract class AbstractEncryptedResponseFilter implements Filter {
+public abstract class AbstractEncryptedResponseFilter implements Task<RequestContext,ResponseContext> {
 
     public AbstractEncryptedResponseFilter() {
         initProvider();

Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java (original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java Fri Oct 21 23:47:50 2011
@@ -19,9 +19,9 @@ package org.apache.abdera2.security.util
 
 import org.apache.abdera2.common.Localizer;
 import org.apache.abdera2.common.misc.Chain;
+import org.apache.abdera2.common.misc.Task;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.Filter;
 import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.model.Document;
 import org.apache.abdera2.model.Element;
@@ -33,7 +33,7 @@ import org.apache.abdera2.security.Signa
  * Servlet Filter that verifies that an Atom document received by the server via PUT or POST contains a valid XML
  * Digital Signature.
  */
-public class SignedRequestFilter implements Filter {
+public class SignedRequestFilter implements Task<RequestContext,ResponseContext> {
 
     public static final String VALID = "org.apache.abdera.security.util.servlet.SignedRequestFilter.valid";
     public static final String CERTS = "org.apache.abdera.security.util.servlet.SignedRequestFilter.certs";

Modified: abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedResponseFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedResponseFilter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedResponseFilter.java (original)
+++ abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedResponseFilter.java Fri Oct 21 23:47:50 2011
@@ -28,9 +28,9 @@ import java.security.cert.X509Certificat
 
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.common.misc.Chain;
+import org.apache.abdera2.common.misc.Task;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
-import org.apache.abdera2.common.protocol.Filter;
 import org.apache.abdera2.model.Document;
 import org.apache.abdera2.model.Element;
 import org.apache.abdera2.protocol.server.AtompubResponseContext;
@@ -82,7 +82,7 @@ import org.apache.abdera2.writer.Writer;
  * &lt;/filter-mapping>
  * </pre>
  */
-public class SignedResponseFilter implements Filter {
+public class SignedResponseFilter implements Task<RequestContext,ResponseContext> {
 
     private static final String keystoreType = "JKS";
 

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubCollectionAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubCollectionAdapter.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubCollectionAdapter.java Fri Oct 21 23:47:50 2011
@@ -18,6 +18,9 @@
 package org.apache.abdera2.protocol.server.impl;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.factory.Factory;
 import org.apache.abdera2.common.protocol.AbstractCollectionAdapter;
@@ -30,8 +33,6 @@ import org.apache.abdera2.model.Entry;
 import org.apache.abdera2.model.Feed;
 import org.apache.abdera2.parser.ParseException;
 import org.apache.abdera2.parser.Parser;
-import org.apache.abdera2.protocol.server.AtompubCollectionAdapter;
-import org.apache.abdera2.protocol.server.AtompubMediaCollectionAdapter;
 import org.apache.abdera2.protocol.server.context.AtompubRequestContext;
 import org.apache.abdera2.protocol.server.context.FOMResponseContext;
 import org.apache.abdera2.protocol.server.model.AtompubCategoriesInfo;
@@ -44,66 +45,61 @@ import org.joda.time.DateTime;
 @SuppressWarnings("unchecked")
 public abstract class AbstractAtompubCollectionAdapter 
   extends AbstractCollectionAdapter
-  implements AtompubCollectionAdapter, 
-             AtompubMediaCollectionAdapter,
-             AtompubCollectionInfo {
-
-      public String[] getAccepts(RequestContext request) {
-        return new String[] {"application/atom+xml;type=entry"};
-      }
-    
-    public AtompubCategoriesInfo[] getCategoriesInfo(RequestContext request) {
-        return null;
+  implements AtompubCollectionInfo {
+
+    public AbstractAtompubCollectionAdapter(String href) {
+    super(href);
+  }
+
+    public Iterable<String> getAccepts(RequestContext request) {
+      return Arrays.<String>asList("application/atom+xml;type=entry");
     }
     
-    public <S extends ResponseContext>S getCategories(RequestContext request) {
-        return null;
+    public Iterable<AtompubCategoriesInfo> getCategoriesInfo(RequestContext request) {
+      return Collections.<AtompubCategoriesInfo>emptySet();
     }
-  
+    
     /**
      * Creates the ResponseContext for a newly created entry. By default, a BaseResponseContext is returned. The
      * Location, Content-Location, Etag and status are set appropriately.
      */
-    protected <S extends ResponseContext>S buildCreateEntryResponse(String link, Entry entry) {
-        FOMResponseContext<Entry> rc = new FOMResponseContext<Entry>(entry);
-        rc.setLocation(link);
-        rc.setContentLocation(rc.getLocation().toString());
-        rc.setEntityTag(AbstractAtompubProvider.calculateEntityTag(entry));
-        rc.setStatus(201);
-        return (S)rc;
+    protected ResponseContext buildCreateEntryResponse(String link, Entry entry) {
+        return new FOMResponseContext<Entry>(entry)
+          .setLocation(link)
+          .setContentLocation(link)
+          .setEntityTag(AbstractAtompubProvider.calculateEntityTag(entry))
+          .setStatus(201);
     }
 
     /**
      * Creates the ResponseContext for a newly created entry. By default, a BaseResponseContext is returned. The
      * Location, Content-Location, Etag and status are set appropriately.
      */
-    protected <S extends ResponseContext>S buildPostMediaEntryResponse(String link, Entry entry) {
-        return (S)buildCreateEntryResponse(link, entry);
+    protected ResponseContext buildPostMediaEntryResponse(String link, Entry entry) {
+      return buildCreateEntryResponse(link, entry);
     }
 
     /**
      * Creates the ResponseContext for a GET entry request. By default, a BaseResponseContext is returned. The Entry
      * will contain an appropriate atom:source element and the Etag header will be set.
      */
-    protected <S extends ResponseContext>S buildGetEntryResponse(RequestContext request, Entry entry)
+    protected ResponseContext buildGetEntryResponse(RequestContext request, Entry entry)
         throws ResponseContextException {
         Feed feed = createFeedBase(request);
         entry.setSource(feed.getAsSource());
         Document<Entry> entry_doc = entry.getDocument();
-        FOMResponseContext<Document<Entry>> rc = new FOMResponseContext<Document<Entry>>(entry_doc);
-        rc.setEntityTag(AbstractAtompubProvider.calculateEntityTag(entry));
-        return (S)rc;
+        return new FOMResponseContext<Document<Entry>>(entry_doc)
+          .setEntityTag(AbstractAtompubProvider.calculateEntityTag(entry));
     }
 
     /**
      * Creates the ResponseContext for a GET feed request. By default, a BaseResponseContext is returned. The Etag
      * header will be set.
      */
-    protected <S extends ResponseContext>S buildGetFeedResponse(Feed feed) {
+    protected ResponseContext buildGetFeedResponse(Feed feed) {
         Document<Feed> document = feed.getDocument();
-        FOMResponseContext<Document<Feed>> rc = new FOMResponseContext<Document<Feed>>(document);
-        rc.setEntityTag(AbstractAtompubProvider.calculateEntityTag(document.getRoot()));
-        return (S)rc;
+        return new FOMResponseContext<Document<Feed>>(document)
+          .setEntityTag(AbstractAtompubProvider.calculateEntityTag(document.getRoot()));
     }
 
     /**

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubProvider.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubProvider.java Fri Oct 21 23:47:50 2011
@@ -20,6 +20,8 @@ package org.apache.abdera2.protocol.serv
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
+
+import javax.activation.MimeType;
 import javax.xml.namespace.QName;
 
 import org.apache.abdera2.Abdera;
@@ -37,11 +39,13 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.EntryRequestProcessor;
 import org.apache.abdera2.common.protocol.MediaRequestProcessor;
 import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.RequestProcessor;
 import org.apache.abdera2.common.protocol.ResponseContext;
 import org.apache.abdera2.common.protocol.Provider;
 import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.common.protocol.TargetType;
 import org.apache.abdera2.common.protocol.WorkspaceInfo;
+import org.apache.abdera2.common.protocol.WorkspaceManager;
 import org.apache.abdera2.model.Base;
 import org.apache.abdera2.model.Content;
 import org.apache.abdera2.model.Document;
@@ -67,6 +71,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.joda.time.DateTime;
 
+import com.google.common.base.Predicate;
+
 /**
  * Base Provider implementation that provides the core implementation details for all Providers. This class provides the
  * basic request routing logic.
@@ -77,17 +83,45 @@ public abstract class AbstractAtompubPro
 
     private final static Log log = LogFactory.getLog(AbstractAtompubProvider.class);
     protected Abdera abdera;
+    protected WorkspaceManager workspaceManager;
+    public static final Predicate<RequestContext> IS_ATOM = 
+      new Predicate<RequestContext>() {
+        public boolean apply(RequestContext input) {
+          MimeType ct = input.getContentType();
+          if (ct == null) return false;
+          return MimeTypeHelper.isAtom(ct.toString());
+        }
+    };
 
-    protected AbstractAtompubProvider() {
-        this.requestProcessors.put(TargetType.TYPE_SERVICE, new ServiceRequestProcessor());
-        this.requestProcessors.put(TargetType.TYPE_CATEGORIES, new CategoriesRequestProcessor());
-        this.requestProcessors.put(TargetType.TYPE_COLLECTION, new CollectionRequestProcessor() {
-          protected boolean isAcceptableItemType(RequestContext context) {
-            return ProviderHelper.isAtom(context);
-          }
-        });
-        this.requestProcessors.put(TargetType.TYPE_ENTRY, new EntryRequestProcessor());
-        this.requestProcessors.put(TargetType.TYPE_MEDIA, new MediaRequestProcessor());
+    protected AbstractAtompubProvider(
+      WorkspaceManager workspaceManager) {
+      this.workspaceManager = workspaceManager;
+        this.requestProcessors.put(
+          TargetType.TYPE_SERVICE, 
+          RequestProcessor.forClass(
+            ServiceRequestProcessor.class, 
+            workspaceManager));
+        this.requestProcessors.put(
+          TargetType.TYPE_CATEGORIES, 
+          RequestProcessor.forClass(
+            CategoriesRequestProcessor.class,
+            workspaceManager));
+        this.requestProcessors.put(
+          TargetType.TYPE_COLLECTION, 
+          RequestProcessor.forClass(
+            CollectionRequestProcessor.class,
+            workspaceManager,
+            ProviderHelper.isAtom()));
+        this.requestProcessors.put(
+          TargetType.TYPE_ENTRY, 
+          RequestProcessor.forClass(
+            EntryRequestProcessor.class,
+            workspaceManager));
+        this.requestProcessors.put(
+          TargetType.TYPE_MEDIA, 
+          RequestProcessor.forClass(
+            MediaRequestProcessor.class, 
+            workspaceManager));
     }
 
     public void init(Abdera abdera, Map<String, String> properties) {
@@ -101,7 +135,7 @@ public abstract class AbstractAtompubPro
 
     protected Service getServiceElement(RequestContext request) {
         Service service = abdera.newService();
-        for (WorkspaceInfo wi : getWorkspaceManager(request).getWorkspaces(request)) {
+        for (WorkspaceInfo wi : getWorkspaceManager().getWorkspaces(request)) {
             if (wi instanceof AtompubWorkspaceInfo) {
               AtompubWorkspaceInfo awi = (AtompubWorkspaceInfo) wi;
               service.addWorkspace(awi.asWorkspaceElement(request));
@@ -110,9 +144,12 @@ public abstract class AbstractAtompubPro
         return service;
     }
     
-    @SuppressWarnings("unchecked")
-    public <S extends ResponseContext>S createErrorResponse(int code, String message, Throwable t) {
-      return (S)createErrorResponse(abdera,code,message,t);
+    public WorkspaceManager getWorkspaceManager() {
+      return workspaceManager;
+  }
+    
+    public ResponseContext createErrorResponse(int code, String message, Throwable t) {
+      return createErrorResponse(abdera,code,message,t);
     }
     
     public static Abdera getAbdera(RequestContext context) {
@@ -273,19 +310,22 @@ public abstract class AbstractAtompubPro
         FOMResponseContext<Base> response = new FOMResponseContext<Base>(base);
         response.setStatus(status);
         if (lastModified != null)
-            response.setLastModified(lastModified.toDate());
+            response.setLastModified(lastModified);
         // response.setContentType(MimeTypeHelper.getMimeType(base));
         Document<?> doc = base instanceof Document ? (Document<?>)base : ((Element)base).getDocument();
         if (doc.getEntityTag() != null) {
             response.setEntityTag(doc.getEntityTag());
         } else if (doc.getLastModified() != null) {
-            response.setLastModified(doc.getLastModified().toDate());
+            response.setLastModified(doc.getLastModified());
         }
         return response;
     }
 
     @Override
-    public <S extends ResponseContext> S process(RequestContext request) {
-      return super.<S>process(request instanceof AtompubRequestContext?request:new AtompubRequestContext(request));
+    public ResponseContext apply(RequestContext request) {
+      return super.apply(
+        request instanceof AtompubRequestContext ? 
+          request : 
+          new AtompubRequestContext(request));
     }
 }

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubWorkspaceProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubWorkspaceProvider.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubWorkspaceProvider.java Fri Oct 21 23:47:50 2011
@@ -26,15 +26,14 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.MediaRequestProcessor;
 import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.RequestProcessor;
 import org.apache.abdera2.common.protocol.ResponseContext;
 import org.apache.abdera2.common.protocol.TargetType;
 import org.apache.abdera2.protocol.server.AtompubProvider;
 import org.apache.abdera2.protocol.server.context.AtompubRequestContext;
 import org.apache.abdera2.protocol.server.model.AtompubWorkspaceManager;
-import org.apache.abdera2.protocol.server.processors.CategoriesRequestProcessor;
 import org.apache.abdera2.protocol.server.processors.ServiceRequestProcessor;
 
-@SuppressWarnings("unchecked")
 public abstract class AbstractAtompubWorkspaceProvider 
   extends AbstractWorkspaceProvider
   implements AtompubProvider, 
@@ -43,15 +42,32 @@ public abstract class AbstractAtompubWor
  protected Abdera abdera;
   
   protected AbstractAtompubWorkspaceProvider() {
-    this.requestProcessors.put(TargetType.TYPE_SERVICE, new ServiceRequestProcessor());
-    this.requestProcessors.put(TargetType.TYPE_CATEGORIES, new CategoriesRequestProcessor());
-    this.requestProcessors.put(TargetType.TYPE_COLLECTION, new CollectionRequestProcessor() {
-      protected boolean isAcceptableItemType(RequestContext context) {
-        return ProviderHelper.isAtom(context);
-      }
-    });
-    this.requestProcessors.put(TargetType.TYPE_ENTRY, new EntryRequestProcessor());
-    this.requestProcessors.put(TargetType.TYPE_MEDIA, new MediaRequestProcessor());
+    this.requestProcessors.put(
+      TargetType.TYPE_SERVICE, 
+      RequestProcessor.forClass(
+        ServiceRequestProcessor.class,
+        this));
+    this.requestProcessors.put(
+      TargetType.TYPE_CATEGORIES, 
+      RequestProcessor.forClass(
+        ServiceRequestProcessor.class, 
+        this));
+    this.requestProcessors.put(
+      TargetType.TYPE_COLLECTION,
+      RequestProcessor.forClass(
+        CollectionRequestProcessor.class,
+        this,
+        ProviderHelper.isAtom()));
+    this.requestProcessors.put(
+      TargetType.TYPE_ENTRY, 
+      RequestProcessor.forClass(
+        EntryRequestProcessor.class,
+        this));
+    this.requestProcessors.put(
+      TargetType.TYPE_MEDIA, 
+      RequestProcessor.forClass(
+        MediaRequestProcessor.class,
+        this));
   }
   
   public void init(Abdera abdera, Map<String, String> properties) {
@@ -63,12 +79,15 @@ public abstract class AbstractAtompubWor
     return abdera;
   }
 
-  public <S extends ResponseContext>S createErrorResponse(int code, String message, Throwable t) {
-    return (S)AbstractAtompubProvider.createErrorResponse(abdera,code,message,t);
+  public ResponseContext createErrorResponse(int code, String message, Throwable t) {
+    return AbstractAtompubProvider.createErrorResponse(abdera,code,message,t);
   }
   
   @Override
-  public <S extends ResponseContext> S process(RequestContext request) {
-    return (S)super.process(request instanceof AtompubRequestContext?request:new AtompubRequestContext(request));
+  public ResponseContext apply(RequestContext request) {
+    return super.apply(
+      request instanceof AtompubRequestContext ? 
+        request:
+        new AtompubRequestContext(request));
   }
 }
\ No newline at end of file

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractEntityCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractEntityCollectionAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractEntityCollectionAdapter.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractEntityCollectionAdapter.java Fri Oct 21 23:47:50 2011
@@ -43,22 +43,39 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.MediaResponseContext;
 import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.common.protocol.ResponseContextException;
+import org.apache.abdera2.common.protocol.TargetType;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.joda.time.DateTime;
 
+import com.google.common.base.Function;
+
 /**
  * By extending this class it becomes easy to build Collections which are backed by a set of entities - such as a
  * database row, domain objects, or files.
  * 
  * @param <T> The entity that this is backed by.
  */
-@SuppressWarnings("unchecked")
 public abstract class AbstractEntityCollectionAdapter<T> 
   extends AbstractAtompubCollectionAdapter {
 
   private final static Log log = LogFactory.getLog(AbstractEntityCollectionAdapter.class);
 
+  public AbstractEntityCollectionAdapter(String href) {
+    super(href);
+    putHandler(TargetType.TYPE_COLLECTION,"POST",handlePost());
+    putHandler(TargetType.TYPE_COLLECTION,"GET",getItemList());
+    putHandler(TargetType.TYPE_COLLECTION,"HEAD",getItemList());
+    putHandler(TargetType.TYPE_MEDIA,"PUT",putMedia());
+    putHandler(TargetType.TYPE_MEDIA,"DELETE",deleteMedia());
+    putHandler(TargetType.TYPE_MEDIA, "HEAD", headMedia());
+    putHandler(TargetType.TYPE_MEDIA, "GET", getMedia());
+    putHandler(TargetType.TYPE_ENTRY,"DELETE",deleteItem());
+    putHandler(TargetType.TYPE_ENTRY,"GET",getItem());
+    putHandler(TargetType.TYPE_ENTRY,"HEAD",headItem());
+    putHandler(TargetType.TYPE_ENTRY,"PUT",putItem());
+  }
+  
     /**
      * Create a new entry
      * 
@@ -78,25 +95,29 @@ public abstract class AbstractEntityColl
                                 Content content,
                                 RequestContext request) throws ResponseContextException;
 
-    @Override
-    public <S extends ResponseContext>S postMedia(RequestContext request) {
-        return (S)createMediaEntry(request);
-    }
-
-    @Override
-    public <S extends ResponseContext>S putMedia(RequestContext request) {
-        try {
-            String id = getResourceName(request);
-            T entryObj = getEntry(id, request);
-
-            putMedia(entryObj, request.getContentType(), request.getSlug(), request.getInputStream(), request);
-
-            return (S)new EmptyResponseContext(200);
-        } catch (IOException e) {
-            return (S)new EmptyResponseContext(500);
-        } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+    private Function<RequestContext,ResponseContext> postMedia() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createMediaEntry(input);
+        }
+      };
+    }
+    
+    private Function<RequestContext,ResponseContext> putMedia() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            String id = getResourceName(input);
+            T entryObj = getEntry(id, input);
+            putMedia(entryObj, input.getContentType(), input.getSlug(), input.getInputStream(), input);
+            return new EmptyResponseContext(200);
+          } catch (IOException e) {
+              return new EmptyResponseContext(500);
+          } catch (ResponseContextException e) {
+              return createErrorResponse(e);
+          }
         }
+      };
     }
 
     /**
@@ -114,10 +135,24 @@ public abstract class AbstractEntityColl
         throw new ResponseContextException(ProviderHelper.notallowed(request));
     }
 
-    public <S extends ResponseContext>S postItem(RequestContext request) {
-        return (S)createNonMediaEntry(request);
+    private Function<RequestContext,ResponseContext> postItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createNonMediaEntry(input);
+        }
+      };
+    }
+    
+    private Function<RequestContext,ResponseContext> handlePost() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return AbstractAtompubProvider.IS_ATOM.apply(input) ?
+            postItem().apply(input) :
+            postMedia().apply(input);
+        }
+      };
     }
-
+    
     protected String getLink(T entryObj, IRI feedIri, RequestContext request) throws ResponseContextException {
         return getLink(entryObj, feedIri, request, false);
     }
@@ -168,21 +203,23 @@ public abstract class AbstractEntityColl
         throws ResponseContextException {
         throw new UnsupportedOperationException();
     }
-
-    public <S extends ResponseContext>S deleteItem(RequestContext request) {
-        String id = getResourceName(request);
-        if (id != null) {
-
-            try {
-                deleteEntry(id, request);
-            } catch (ResponseContextException e) {
-                return (S)createErrorResponse(e);
-            }
-
-            return (S)new EmptyResponseContext(204);
-        } else {
-            return (S)new EmptyResponseContext(404);
+    
+    private Function<RequestContext,ResponseContext> deleteItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          String id = getResourceName(input);
+          if (id != null) {
+              try {
+                  deleteEntry(id, input);
+              } catch (ResponseContextException e) {
+                  return createErrorResponse(e);
+              }
+              return new EmptyResponseContext(204);
+          } else {
+            return new EmptyResponseContext(404);
+          }
         }
+      };
     }
 
     /**
@@ -193,20 +230,22 @@ public abstract class AbstractEntityColl
      */
     public abstract void deleteEntry(String resourceName, RequestContext request) throws ResponseContextException;
 
-    public <S extends ResponseContext>S deleteMedia(RequestContext request) {
-        String resourceName = getResourceName(request);
-        if (resourceName != null) {
-
-            try {
-                deleteMedia(resourceName, request);
-            } catch (ResponseContextException e) {
-                return (S)createErrorResponse(e);
-            }
-
-            return (S)new EmptyResponseContext(204);
-        } else {
-            return (S)new EmptyResponseContext(404);
+    private Function<RequestContext,ResponseContext> deleteMedia() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          String resourceName = getResourceName(input);
+          if (resourceName != null) {
+              try {
+                  deleteMedia(resourceName, input);
+              } catch (ResponseContextException e) {
+                  return createErrorResponse(e);
+              }
+              return new EmptyResponseContext(204);
+          } else {
+              return new EmptyResponseContext(404);
+          }
         }
+      };
     }
 
     /**
@@ -244,19 +283,23 @@ public abstract class AbstractEntityColl
      */
     public abstract Iterable<T> getEntries(RequestContext request) throws ResponseContextException;
 
-    public <S extends ResponseContext>S getItem(RequestContext request) {
-        try {
-            Entry entry = getEntryFromCollectionProvider(request);
+    private Function<RequestContext,ResponseContext> getItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            Entry entry = getEntryFromCollectionProvider(input);
             if (entry != null) {
-                return (S)buildGetEntryResponse(request, entry);
+                return buildGetEntryResponse(input, entry);
             } else {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
+        }
         }
+      };
     }
-
+   
     /**
      * Get a specific entry
      * 
@@ -265,48 +308,58 @@ public abstract class AbstractEntityColl
      */
     public abstract T getEntry(String resourceName, RequestContext request) throws ResponseContextException;
 
-    public <S extends ResponseContext>S headItem(RequestContext request) {
-        try {
-            String resourceName = getResourceName(request);
-            T entryObj = getEntry(resourceName, request);
-
+    private Function<RequestContext,ResponseContext> headItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            String resourceName = getResourceName(input);
+            T entryObj = getEntry(resourceName, input);
             if (entryObj != null) {
-                return (S)buildHeadEntryResponse(request, resourceName, getUpdated(entryObj));
+                return buildHeadEntryResponse(input, resourceName, getUpdated(entryObj));
             } else {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
         }
+        }
+      };
     }
-
-    public <S extends ResponseContext>S headMedia(RequestContext request) {
-        try {
-            String resourceName = getResourceName(request);
-            T entryObj = getEntry(resourceName, request);
+    
+    private Function<RequestContext,ResponseContext> headMedia() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            String resourceName = getResourceName(input);
+            T entryObj = getEntry(resourceName, input);
 
             if (entryObj != null) {
-                return (S)buildHeadEntryResponse(request, resourceName, getUpdated(entryObj));
+                return buildHeadEntryResponse(input, resourceName, getUpdated(entryObj));
             } else {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
         }
+        }
+      };
     }
 
-    public <S extends ResponseContext>S getItemList(RequestContext request) {
-        try {
-            Feed feed = createFeedBase(request);
-
-            addFeedDetails(feed, request);
-
-            return (S)buildGetFeedResponse(feed);
+    public Function<RequestContext,ResponseContext> getItemList() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            Feed feed = createFeedBase(input);
+            addFeedDetails(feed, input);
+            return buildGetFeedResponse(feed);
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
+        }
         }
+      };
     }
 
+
     /**
      * Adds the selected entries to the Feed document. By default, this will set the feed's atom:updated element to the
      * current date and time
@@ -344,38 +397,39 @@ public abstract class AbstractEntityColl
      */
     public abstract String getId(T entry) throws ResponseContextException;
 
-    public <S extends ResponseContext>S getMedia(RequestContext request) {
-        try {
-            String resource = getResourceName(request);
-            T entryObj = getEntry(resource, request);
-
+    private Function<RequestContext,ResponseContext> getMedia() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            String resource = getResourceName(input);
+            T entryObj = getEntry(resource, input);
             if (entryObj == null) {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
-
-            return (S)buildGetMediaResponse(resource, entryObj);
+            return buildGetMediaResponse(resource, entryObj);
         } catch (ParseException pe) {
-            return (S)new EmptyResponseContext(415);
+            return new EmptyResponseContext(415);
         } catch (ClassCastException cce) {
-            return (S)new EmptyResponseContext(415);
+            return new EmptyResponseContext(415);
         } catch (ResponseContextException e) {
-            return (S)e.getResponseContext();
+            return e.getResponseContext();
         } catch (Exception e) {
             log.warn(e.getMessage(), e);
-            return (S)new EmptyResponseContext(400);
+            return new EmptyResponseContext(400);
+        }
         }
+      };
     }
-
+    
     /**
      * Creates a ResponseContext for a GET media request. By default, this returns a MediaResponseContext containing the
      * media resource. The last-modified header will be set.
      */
-    protected <S extends ResponseContext>S buildGetMediaResponse(String id, T entryObj) throws ResponseContextException {
+    protected ResponseContext buildGetMediaResponse(String id, T entryObj) throws ResponseContextException {
         DateTime updated = getUpdated(entryObj);
-        MediaResponseContext ctx = new MediaResponseContext(getMediaStream(entryObj), updated.toDate(), 200);
-        ctx.setContentType(getContentType(entryObj));
-        ctx.setEntityTag(EntityTag.generate(id, DateTimes.format(updated)));
-        return (S)ctx;
+        return new MediaResponseContext(getMediaStream(entryObj), updated, 200)
+          .setContentType(getContentType(entryObj))
+          .setEntityTag(EntityTag.generate(id, DateTimes.format(updated)));
     }
 
     /**
@@ -415,53 +469,56 @@ public abstract class AbstractEntityColl
         return false;
     }
 
-    public <S extends ResponseContext>S putItem(RequestContext request) {
-        try {
-            String id = getResourceName(request);
-            T entryObj = getEntry(id, request);
+    private Function<RequestContext,ResponseContext> putItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
+            String id = getResourceName(input);
+            T entryObj = getEntry(id, input);
 
             if (entryObj == null) {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
 
             Entry orig_entry =
-                getEntryFromCollectionProvider(entryObj, new IRI(getFeedIriForEntry(entryObj, request)), request);
+                getEntryFromCollectionProvider(entryObj, new IRI(getFeedIriForEntry(entryObj, input)), input);
             if (orig_entry != null) {
 
-                MimeType contentType = request.getContentType();
+                MimeType contentType = input.getContentType();
                 if (contentType != null && !MimeTypeHelper.isAtom(contentType.toString()))
-                    return (S)new EmptyResponseContext(415);
+                    return new EmptyResponseContext(415);
 
-                Entry entry = getEntryFromRequest(request);
+                Entry entry = getEntryFromRequest(input);
                 if (entry != null) {
                     if (!entry.getId().equals(orig_entry.getId()))
-                        return (S)new EmptyResponseContext(409);
+                        return new EmptyResponseContext(409);
 
                     if (!AbstractAtompubProvider.isValidEntry(entry))
-                        return (S)new EmptyResponseContext(400);
+                        return new EmptyResponseContext(400);
 
                     putEntry(entryObj, entry.getTitle(), DateTime.now(), entry.getAuthors(), entry.getSummary(), entry
-                        .getContentElement(), request);
-                    return (S)new EmptyResponseContext(204);
+                        .getContentElement(), input);
+                    return new EmptyResponseContext(204);
                 } else {
-                    return (S)new EmptyResponseContext(400);
+                    return new EmptyResponseContext(400);
                 }
             } else {
-                return (S)new EmptyResponseContext(404);
+                return new EmptyResponseContext(404);
             }
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
         } catch (ParseException pe) {
-            return (S)new EmptyResponseContext(415);
+            return new EmptyResponseContext(415);
         } catch (ClassCastException cce) {
-            return (S)new EmptyResponseContext(415);
+            return new EmptyResponseContext(415);
         } catch (Exception e) {
             log.warn(e.getMessage(), e);
-            return (S)new EmptyResponseContext(400);
+            return new EmptyResponseContext(400);
         }
-
+        }
+      };
     }
-
+    
     /**
      * Get the Feed IRI
      */
@@ -564,7 +621,7 @@ public abstract class AbstractEntityColl
      * 
      * @param request The request context
      */
-    protected <S extends ResponseContext>S createMediaEntry(RequestContext request) {
+    protected ResponseContext createMediaEntry(RequestContext request) {
         try {
             T entryObj = postMedia(request.getContentType(), request.getSlug(), request.getInputStream(), request);
 
@@ -575,11 +632,13 @@ public abstract class AbstractEntityColl
             addMediaContent(feedUri, entry, entryObj, request);
 
             String location = getLink(entryObj, feedUri, request, true);
-            return (S)buildPostMediaEntryResponse(location, entry);
+            return buildPostMediaEntryResponse(location, entry);
+        } catch (UnsupportedOperationException e) {
+          return UNSUPPORTED_TYPE.apply(request);
         } catch (IOException e) {
-            return (S)new EmptyResponseContext(500);
+            return new EmptyResponseContext(500);
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
         }
     }
 
@@ -588,12 +647,12 @@ public abstract class AbstractEntityColl
      * 
      * @param request The request context
      */
-    protected <S extends ResponseContext>S createNonMediaEntry(RequestContext request) {
+    protected ResponseContext createNonMediaEntry(RequestContext request) {
         try {
             Entry entry = getEntryFromRequest(request);
             if (entry != null) {
                 if (!AbstractAtompubProvider.isValidEntry(entry))
-                    return (S)new EmptyResponseContext(400);
+                    return new EmptyResponseContext(400);
 
                 entry.setUpdated(DateTime.now());
 
@@ -609,12 +668,12 @@ public abstract class AbstractEntityColl
                 entry.addLink(link, "edit");
 
                 String location = getLink(entryObj, feedUri, request, true);
-                return (S)buildCreateEntryResponse(location, entry);
+                return buildCreateEntryResponse(location, entry);
             } else {
-                return (S)new EmptyResponseContext(400);
+                return new EmptyResponseContext(400);
             }
         } catch (ResponseContextException e) {
-            return (S)createErrorResponse(e);
+            return createErrorResponse(e);
         }
     }
 

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/DefaultAtompubProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/DefaultAtompubProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/DefaultAtompubProvider.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/DefaultAtompubProvider.java Fri Oct 21 23:47:50 2011
@@ -39,7 +39,6 @@ import org.apache.abdera2.common.protoco
 public class DefaultAtompubProvider 
   extends AbstractAtompubProvider {
 
-    protected WorkspaceManager workspaceManager;
     protected Resolver<Target,RequestContext> targetResolver;
     protected Resolver<Subject,Request> subjectResolver;
     protected TargetBuilder<?> targetBuilder;
@@ -51,19 +50,17 @@ public class DefaultAtompubProvider 
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public DefaultAtompubProvider(String base) {
-        if (base == null) {
-            base = "/";
-        }
-        workspaceManager = new DefaultWorkspaceManager();
-        routeManager =
-            new RouteManager()
-              .addRoute("service", base, TargetType.TYPE_SERVICE)
-              .addRoute("feed", base + ":collection", TargetType.TYPE_COLLECTION)
-              .addRoute("entry", base + ":collection/:entry", TargetType.TYPE_ENTRY)
-              .addRoute("categories", base + ":collection/:entry;categories", TargetType.TYPE_CATEGORIES);
-
-        targetBuilder = routeManager;
-        targetResolver = routeManager;
+      super(new DefaultWorkspaceManager());
+      if (base == null)
+        base = "/";
+      routeManager =
+          new RouteManager()
+            .addRoute("service", base, TargetType.TYPE_SERVICE)
+            .addRoute("feed", base + ":collection", TargetType.TYPE_COLLECTION)
+            .addRoute("entry", base + ":collection/:entry", TargetType.TYPE_ENTRY)
+            .addRoute("categories", base + ":collection/:entry;categories", TargetType.TYPE_CATEGORIES);
+      targetBuilder = routeManager;
+      targetResolver = routeManager;
     }
 
     @SuppressWarnings("rawtypes")
@@ -95,10 +92,6 @@ public class DefaultAtompubProvider 
         return subjectResolver;
     }
 
-    protected WorkspaceManager getWorkspaceManager(RequestContext request) {
-        return getWorkspaceManager();
-    }
-
     public WorkspaceManager getWorkspaceManager() {
         return workspaceManager;
     }

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java Fri Oct 21 23:47:50 2011
@@ -27,8 +27,43 @@ import org.apache.abdera2.model.Categori
 import org.apache.abdera2.protocol.server.model.AtompubCategoriesInfo;
 import org.apache.abdera2.protocol.server.model.AtompubCategoryInfo;
 
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterators;
+
 public class SimpleCategoriesInfo implements AtompubCategoriesInfo, Serializable {
 
+    public static Generator make() {
+      return new Generator();
+    }
+  
+    public static class Generator implements Supplier<AtompubCategoriesInfo> {
+      private String href;
+      private String scheme;
+      private boolean fixed;
+      private final List<AtompubCategoryInfo> list = 
+        new ArrayList<AtompubCategoryInfo>();
+      public Generator href(String href) {
+        this.href = href;
+        return this;
+      }
+      public Generator scheme(String scheme) {
+        this.scheme = scheme;
+        return this;
+      }
+      public Generator fixed() {
+        this.fixed = true;
+        return this;
+      }
+      public Generator category(AtompubCategoryInfo info) {
+        this.list.add(info);
+        return this;
+      }
+      public AtompubCategoriesInfo get() {
+        return new SimpleCategoriesInfo(this);
+      }
+      
+    }
+  
     private static final long serialVersionUID = 8732335394387909260L;
 
     private final String href;
@@ -36,27 +71,13 @@ public class SimpleCategoriesInfo implem
     private final boolean fixed;
     private final List<AtompubCategoryInfo> list = new ArrayList<AtompubCategoryInfo>();
 
-    public SimpleCategoriesInfo() {
-        this(null, false);
+    protected SimpleCategoriesInfo(Generator gen) {
+      this.href = gen.href;
+      this.scheme = gen.scheme;
+      this.fixed = gen.fixed;
+      this.list.addAll(gen.list);
     }
-
-    public SimpleCategoriesInfo(boolean fixed) {
-        this(null, fixed);
-    }
-
-    public SimpleCategoriesInfo(String href) {
-        this.href = href;
-        this.scheme = null;
-        this.fixed = false;
-    }
-
-    public SimpleCategoriesInfo(String scheme, boolean fixed, AtompubCategoryInfo... categories) {
-        this.href = null;
-        this.scheme = scheme;
-        this.fixed = fixed;
-        addCategoryInfo(categories);
-    }
-
+    
     public String getHref(RequestContext request) {
         return href;
     }
@@ -70,18 +91,7 @@ public class SimpleCategoriesInfo implem
     }
 
     public Iterator<AtompubCategoryInfo> iterator() {
-        return list.iterator();
-    }
-
-    public SimpleCategoriesInfo addCategoryInfo(AtompubCategoryInfo... categories) {
-        for (AtompubCategoryInfo cat : categories)
-            list.add(cat);
-        return this;
-    }
-
-    public SimpleCategoriesInfo setCategoryInfo(AtompubCategoryInfo... categories) {
-        list.clear();
-        return addCategoryInfo(categories);
+        return Iterators.<AtompubCategoryInfo>unmodifiableIterator(list.iterator());
     }
 
     public int hashCode() {

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java Fri Oct 21 23:47:50 2011
@@ -23,26 +23,47 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.model.Category;
 import org.apache.abdera2.protocol.server.model.AtompubCategoryInfo;
 
+import com.google.common.base.Supplier;
+
 public class SimpleCategoryInfo implements AtompubCategoryInfo, Serializable {
 
+    public static Generator make() {
+      return new Generator();
+    }
+  
+    public static class Generator implements Supplier<AtompubCategoryInfo> {
+      private String label;
+      private String term;
+      private String scheme;
+      public Generator label(String label) {
+        this.label = label;
+        return this;
+      }
+      public Generator term(String term) {
+        this.term = term;
+        return this;
+      }
+      public Generator scheme(String scheme) {
+        this.scheme = scheme;
+        return this;
+      }
+      public AtompubCategoryInfo get() {
+        return new SimpleCategoryInfo(this);
+      }
+      
+    }
+  
     private static final long serialVersionUID = -4013333222147077975L;
     private final String label;
     private final String term;
     private final String scheme;
 
-    public SimpleCategoryInfo(String term) {
-        this(term, null, null);
-    }
-
-    public SimpleCategoryInfo(String term, String scheme) {
-        this(term, scheme, null);
-    }
-
-    public SimpleCategoryInfo(String term, String scheme, String label) {
-        this.term = term;
-        this.scheme = scheme;
-        this.label = label;
+    protected SimpleCategoryInfo(Generator gen) {
+      this.label = gen.label;
+      this.term = gen.term;
+      this.scheme = gen.scheme;
     }
+    
 
     public String getLabel(RequestContext request) {
         return label;

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java Fri Oct 21 23:47:50 2011
@@ -19,14 +19,19 @@ package org.apache.abdera2.protocol.serv
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 
+import org.apache.abdera2.common.protocol.CollectionInfo;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.BasicCollectionInfo;
 import org.apache.abdera2.model.Collection;
 import org.apache.abdera2.protocol.server.model.AtompubCategoriesInfo;
 import org.apache.abdera2.protocol.server.model.AtompubCollectionInfo;
 
+import com.google.common.collect.Iterables;
+
 public class SimpleCollectionInfo 
   extends BasicCollectionInfo
   implements AtompubCollectionInfo, 
@@ -34,25 +39,32 @@ public class SimpleCollectionInfo 
 
     private static final long serialVersionUID = 8026455829158149510L;
 
-    private final List<AtompubCategoriesInfo> catinfos = 
-      new ArrayList<AtompubCategoriesInfo>();
-
-    public SimpleCollectionInfo(String title, String href, String... accepts) {
-        super(title,href,accepts);
+    public static Generator make() {
+      return new Generator();
     }
-
-    public AtompubCategoriesInfo[] getCategoriesInfo(RequestContext request) {
-        return catinfos.toArray(new AtompubCategoriesInfo[catinfos.size()]);
+    
+    public static class Generator extends BasicCollectionInfo.Generator {
+      private final Set<AtompubCategoriesInfo> catinfos =
+        new LinkedHashSet<AtompubCategoriesInfo>();
+      public Generator category(AtompubCategoriesInfo info) {
+        this.catinfos.add(info);
+        return this;
+      }
+      public CollectionInfo get() {
+        return new SimpleCollectionInfo(this);
+      }
     }
+    
+    private final List<AtompubCategoriesInfo> catinfos = 
+      new ArrayList<AtompubCategoriesInfo>();
 
-    public void addCategoriesInfo(AtompubCategoriesInfo... catinfos) {
-        for (AtompubCategoriesInfo catinfo : catinfos)
-            this.catinfos.add(catinfo);
+    protected SimpleCollectionInfo(Generator generator) {
+      super(generator);
+      this.catinfos.addAll(generator.catinfos);
     }
 
-    public void setCategoriesInfo(AtompubCategoriesInfo... catinfos) {
-        this.catinfos.clear();
-        addCategoriesInfo(catinfos);
+    public Iterable<AtompubCategoriesInfo> getCategoriesInfo(RequestContext request) {
+        return Iterables.<AtompubCategoriesInfo>unmodifiableIterable(catinfos);
     }
 
     @Override

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleWorkspaceInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleWorkspaceInfo.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleWorkspaceInfo.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleWorkspaceInfo.java Fri Oct 21 23:47:50 2011
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.BasicWorkspaceInfo;
 import org.apache.abdera2.common.protocol.CollectionInfo;
+import org.apache.abdera2.common.protocol.WorkspaceInfo;
 import org.apache.abdera2.model.Workspace;
 import org.apache.abdera2.protocol.server.model.AtompubCollectionInfo;
 import org.apache.abdera2.protocol.server.model.AtompubWorkspaceInfo;
@@ -32,7 +33,18 @@ public class SimpleWorkspaceInfo 
 
     private static final long serialVersionUID = -8459688584319762878L;
 
-    public SimpleWorkspaceInfo() {
+    public static Generator make() {
+      return new Generator();
+    }
+    
+    public static class Generator extends BasicWorkspaceInfo.Generator {
+      public WorkspaceInfo get() {
+        return new SimpleWorkspaceInfo(this);
+      } 
+    }
+    
+    public SimpleWorkspaceInfo(Generator generator) {
+      super(generator);
     }
 
     public SimpleWorkspaceInfo(String title) {

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/model/AtompubCollectionInfo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/model/AtompubCollectionInfo.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/model/AtompubCollectionInfo.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/model/AtompubCollectionInfo.java Fri Oct 21 23:47:50 2011
@@ -32,7 +32,7 @@ public interface AtompubCollectionInfo
      * Return the collection of CategoriesInfo objects for the app:collection element's app:categories elements. These
      * tell a client which atom:category elements are defined for use in the collections atom:entries
      */
-    AtompubCategoriesInfo[] getCategoriesInfo(RequestContext request);
+    Iterable<AtompubCategoriesInfo> getCategoriesInfo(RequestContext request);
 
     /**
      * Converts this to an instance of the FOM Collection interface

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/multipart/AbstractMultipartCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/multipart/AbstractMultipartCollectionAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/multipart/AbstractMultipartCollectionAdapter.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/multipart/AbstractMultipartCollectionAdapter.java Fri Oct 21 23:47:50 2011
@@ -44,9 +44,16 @@ import org.apache.abdera2.common.mediaty
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.commons.codec.binary.Base64;
 
+import com.google.common.collect.Iterables;
+
 @SuppressWarnings("unchecked")
-public abstract class AbstractMultipartCollectionAdapter extends AbstractAtompubCollectionAdapter implements
-    MultipartRelatedCollectionInfo {
+public abstract class AbstractMultipartCollectionAdapter 
+  extends AbstractAtompubCollectionAdapter 
+  implements MultipartRelatedCollectionInfo {
+
+    public AbstractMultipartCollectionAdapter(String href) {
+    super(href);
+  }
 
     private static final String CONTENT_TYPE_HEADER = "content-type";
     private static final String CONTENT_ID_HEADER = "content-id";
@@ -56,9 +63,9 @@ public abstract class AbstractMultipartC
 
     protected Map<String, String> accepts;
 
-    public String[] getAccepts(RequestContext request) {
+    public Iterable<String> getAccepts(RequestContext request) {
         Collection<String> acceptKeys = getAlternateAccepts(request).keySet();
-        return acceptKeys.toArray(new String[acceptKeys.size()]);
+        return Iterables.unmodifiableIterable(acceptKeys);
     }
 
     protected MultipartRelatedPost getMultipartRelatedData(RequestContext request) throws IOException, ParseException,

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/CategoriesRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/CategoriesRequestProcessor.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/CategoriesRequestProcessor.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/CategoriesRequestProcessor.java Fri Oct 21 23:47:50 2011
@@ -17,34 +17,30 @@
  */
 package org.apache.abdera2.protocol.server.processors;
 
-import org.apache.abdera2.common.protocol.RequestContext;
-import org.apache.abdera2.common.protocol.ResponseContext;
 import org.apache.abdera2.common.protocol.CollectionAdapter;
-import org.apache.abdera2.common.protocol.ProviderHelper;
+import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.RequestProcessor;
 import org.apache.abdera2.common.protocol.WorkspaceManager;
-import org.apache.abdera2.protocol.server.AtompubCollectionAdapter;
+
+import com.google.common.base.Predicate;
 
 /**
  * {@link org.apache.AtompubRequestProcessor.protocol.server.RequestProcessor} implementation which processes requests for categories
  * documents.
  */
-public class CategoriesRequestProcessor implements RequestProcessor {
-
-    @SuppressWarnings("unchecked")
-    public <S extends ResponseContext>S process(RequestContext context,
-                                   WorkspaceManager workspaceManager,
-                                   CollectionAdapter collectionAdapter) {
-        if (collectionAdapter == null || !(collectionAdapter instanceof AtompubCollectionAdapter)) {
-            return (S)ProviderHelper.notfound(context);
-        } else {
-            return (S)this.processCategories(context, collectionAdapter);
-        }
-    }
+public class CategoriesRequestProcessor 
+  extends RequestProcessor {
 
-    @SuppressWarnings("unchecked")
-    protected <S extends ResponseContext>S processCategories(RequestContext context, CollectionAdapter adapter) {
-          return (S)(context.getMethod().equalsIgnoreCase("GET") ? 
-            ((AtompubCollectionAdapter)adapter).getCategories(context) : null);
+  public CategoriesRequestProcessor(
+    WorkspaceManager manager,
+    CollectionAdapter adapter) {
+      super(manager,adapter);
+  }
+  
+  public CategoriesRequestProcessor(
+      WorkspaceManager manager,
+      CollectionAdapter adapter,
+      Predicate<RequestContext> predicate) {
+        super(manager,adapter,predicate);
     }
 }

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/MultipartRelatedServiceRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/MultipartRelatedServiceRequestProcessor.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/MultipartRelatedServiceRequestProcessor.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/MultipartRelatedServiceRequestProcessor.java Fri Oct 21 23:47:50 2011
@@ -18,10 +18,10 @@
 package org.apache.abdera2.protocol.server.processors;
 
 import java.io.IOException;
-import java.util.Collection;
 import java.util.Map;
 
 import org.apache.abdera2.common.Constants;
+import org.apache.abdera2.common.protocol.CollectionAdapter;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContext;
 import org.apache.abdera2.common.protocol.CollectionInfo;
@@ -42,12 +42,16 @@ import org.apache.abdera2.writer.StreamW
 public class MultipartRelatedServiceRequestProcessor 
   extends ServiceRequestProcessor {
 
-    @SuppressWarnings("unchecked")
-    @Override
-    protected <S extends ResponseContext>S getServiceDocument(
+    protected MultipartRelatedServiceRequestProcessor(
+      WorkspaceManager workspaceManager, 
+      CollectionAdapter adapter) {
+        super(workspaceManager, adapter);
+    }
+
+    protected ResponseContext getServiceDocument(
       final RequestContext request, 
       final WorkspaceManager workspaceManager) {
-        return (S)new StreamWriterResponseContext(
+        return new StreamWriterResponseContext(
             AbstractAtompubProvider.getAbdera(request)) {
 
             @Override
@@ -55,7 +59,7 @@ public class MultipartRelatedServiceRequ
                 sw.startDocument().startService();
                 for (WorkspaceInfo wi : workspaceManager.getWorkspaces(request)) {
                     sw.startWorkspace().writeTitle(wi.getTitle(request));
-                    Collection<CollectionInfo> collections = wi.getCollections(request);
+                    Iterable<CollectionInfo> collections = wi.getCollections(request);
 
                     if (collections != null) {
                         for (CollectionInfo c : collections) {
@@ -74,7 +78,7 @@ public class MultipartRelatedServiceRequ
                             } else {
                                 sw.writeAccepts(ci.getAccepts(request));
                             }
-                            AtompubCategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
+                            Iterable<AtompubCategoriesInfo> catinfos = ci.getCategoriesInfo(request);
                             if (catinfos != null) {
                                 for (AtompubCategoriesInfo catinfo : catinfos) {
                                     String cathref = catinfo.getHref(request);

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/ServiceRequestProcessor.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/ServiceRequestProcessor.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/ServiceRequestProcessor.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/ServiceRequestProcessor.java Fri Oct 21 23:47:50 2011
@@ -18,8 +18,6 @@
 package org.apache.abdera2.protocol.server.processors;
 
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Date;
 
 import org.apache.abdera2.common.Constants;
 import org.apache.abdera2.common.http.EntityTag;
@@ -36,37 +34,42 @@ import org.apache.abdera2.protocol.serve
 import org.apache.abdera2.protocol.server.model.AtompubCategoryInfo;
 import org.apache.abdera2.protocol.server.model.AtompubCollectionInfo;
 import org.apache.abdera2.writer.StreamWriter;
+import org.joda.time.DateTime;
 
 /**
  * {@link org.apache.AtompubRequestProcessor.protocol.server.RequestProcessor} implementation which processes requests for service
  * documents.
  */
-@SuppressWarnings("unchecked")
 public class ServiceRequestProcessor 
-  implements RequestProcessor {
+  extends RequestProcessor {
 
-    public <S extends ResponseContext> S process(
-        RequestContext request, WorkspaceManager workspaceManager,
-        CollectionAdapter collectionAdapter) {
-      return (S)this.processService(request, workspaceManager);
+    protected ServiceRequestProcessor(
+      WorkspaceManager workspaceManager,
+      CollectionAdapter adapter) {
+        super(workspaceManager, adapter);
+    }
+
+    public ResponseContext apply(
+        RequestContext request) {
+      return processService(request, workspaceManager);
     }
   
-    private <S extends ResponseContext>S processService(
+    private ResponseContext processService(
         RequestContext context, 
         WorkspaceManager workspaceManager) {
         String method = context.getMethod();
         if (method.equalsIgnoreCase("GET")) {
-            return (S)this.getServiceDocument(context, workspaceManager);
+            return this.getServiceDocument(context, workspaceManager);
         } else {
             return null;
         }
     }
 
-    protected <S extends ResponseContext>S getServiceDocument(
+    protected ResponseContext getServiceDocument(
         final RequestContext request, 
         final WorkspaceManager workspaceManager) {
  
-        return (S)new StreamWriterResponseContext(
+        return new StreamWriterResponseContext(
             AbstractAtompubProvider.getAbdera(request)) {
 
           // JIRA: https://issues.apache.org/jira/browse/ABDERA-255
@@ -78,8 +81,8 @@ public class ServiceRequestProcessor 
 
           // JIRA: https://issues.apache.org/jira/browse/ABDERA-255
           @Override
-          public Date getLastModified() {
-            Date lm = workspaceManager.getLastModified();
+          public DateTime getLastModified() {
+            DateTime lm = workspaceManager.getLastModified();
             return lm != null ? lm : super.getLastModified();
           }
 
@@ -87,13 +90,13 @@ public class ServiceRequestProcessor 
                 sw.startDocument().startService();
                 for (WorkspaceInfo wi : workspaceManager.getWorkspaces(request)) {
                     sw.startWorkspace().writeTitle(wi.getTitle(request));
-                    Collection<CollectionInfo> collections = wi.getCollections(request);
+                    Iterable<CollectionInfo> collections = wi.getCollections(request);
                     if (collections != null) {
                         for (CollectionInfo c : collections) {
                             AtompubCollectionInfo ci = (AtompubCollectionInfo) c;
                             sw.startCollection(ci.getHref(request)).writeTitle(ci.getTitle(request)).writeAccepts(ci
                                 .getAccepts(request));
-                            AtompubCategoriesInfo[] catinfos = ci.getCategoriesInfo(request);
+                            Iterable<AtompubCategoriesInfo> catinfos = ci.getCategoriesInfo(request);
                             if (catinfos != null) {
                                 for (AtompubCategoriesInfo catinfo : catinfos) {
                                     String cathref = catinfo.getHref(request);

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/basic/BasicAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/basic/BasicAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/basic/BasicAdapter.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/basic/BasicAdapter.java Fri Oct 21 23:47:50 2011
@@ -35,8 +35,11 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.ResponseContext;
 import org.apache.abdera2.common.protocol.ProviderHelper;
 import org.apache.abdera2.common.protocol.Target;
+import org.apache.abdera2.common.protocol.TargetType;
 import org.joda.time.DateTime;
 
+import com.google.common.base.Function;
+
 /**
  * The BasicAdapter provides a simplistic interface for working with Atompub collections with a restricted set of
  * options/features. The idea of the basic adapter is to make it easy to provide a minimally capable Atompub server
@@ -44,10 +47,20 @@ import org.joda.time.DateTime;
 @SuppressWarnings("unchecked")
 public abstract class BasicAdapter extends ManagedCollectionAdapter {
 
-    public static Logger logger = Logger.getLogger(BasicAdapter.class.getName());
+    public static Logger logger = 
+      Logger.getLogger(BasicAdapter.class.getName());
 
     protected BasicAdapter(Abdera abdera, FeedConfiguration config) {
         super(abdera,config);
+        putHandler(TargetType.TYPE_CATEGORIES,"GET",getCategories());
+        putHandler(TargetType.TYPE_CATEGORIES,"HEAD",getCategories());
+        putHandler(TargetType.TYPE_COLLECTION,"GET",getItemList());
+        putHandler(TargetType.TYPE_COLLECTION,"HEAD",getItemList());
+        putHandler(TargetType.TYPE_COLLECTION,"POST",postItem());
+        putHandler(TargetType.TYPE_ENTRY,"GET",getItem());
+        putHandler(TargetType.TYPE_ENTRY,"HEAD",getItem());
+        putHandler(TargetType.TYPE_ENTRY,"PUT",putItem());
+        putHandler(TargetType.TYPE_ENTRY,"DELETE",deleteItem());
     }
 
     public String getProperty(String key) throws Exception {
@@ -116,54 +129,74 @@ public abstract class BasicAdapter exten
         }
     }
 
-    public <S extends ResponseContext>S postItem(RequestContext request) {
-        return (S)createOrUpdateEntry(request, true);
-    }
-
-    public <S extends ResponseContext>S deleteItem(RequestContext request) {
-        Target target = request.getTarget();
-        String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
-        try {
-            return (S)(deleteEntry(entryId) ? ProviderHelper.nocontent() : ProviderHelper.notfound(request));
-        } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), e);
-        }
-    }
-
-    public <S extends ResponseContext>S putItem(RequestContext request) {
-        return (S)createOrUpdateEntry(request, false);
-    }
-
-    public <S extends ResponseContext>S getItem(RequestContext request) {
-        Target target = request.getTarget();
-        String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
-        try {
+    private Function<RequestContext,ResponseContext> postItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createOrUpdateEntry(input,true);
+        }
+      };
+    }
+    
+    private Function<RequestContext,ResponseContext> deleteItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          Target target = input.getTarget();
+          String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
+          try {
+            return deleteEntry(entryId) ? 
+              ProviderHelper.nocontent() : 
+              ProviderHelper.notfound(input);
+          } catch (Exception e) {
+            return ProviderHelper.servererror(input, e.getMessage(), e);
+          }  
+        }
+      };
+    }
+
+    private Function<RequestContext,ResponseContext> putItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createOrUpdateEntry(input,false);
+        }
+      };
+    }
+
+    private Function<RequestContext,ResponseContext> getItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          Target target = input.getTarget();
+          String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
+          try {
             Entry entry = getEntry(entryId);
-            return (S)(entry != null ? AbstractAtompubProvider.returnBase(entry.getDocument(), 200, null) : ProviderHelper
-                .notfound(request));
-        } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), e);
-        }
+            return entry != null ? 
+              AbstractAtompubProvider.returnBase(entry.getDocument(), 200, null) : 
+              ProviderHelper.notfound(input);
+          } catch (Exception e) {
+            return ProviderHelper.servererror(input, e.getMessage(), e);
+          }
+        }
+      };
     }
 
-    public <S extends ResponseContext>S getItemList(RequestContext request) {
-        try {
+    private Function<RequestContext,ResponseContext> getItemList() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
             Feed feed = getFeed();
-            return feed != null ? (S)AbstractAtompubProvider.returnBase(feed.getDocument(), 200, null) : 
-              (S)ProviderHelper.notfound(request);
-        } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), e);
+            return feed != null ? 
+              AbstractAtompubProvider.returnBase(feed.getDocument(), 200, null) : 
+              ProviderHelper.notfound(input);
+          } catch (Exception e) {
+            return ProviderHelper.servererror(input, e.getMessage(), e);
+          }
         }
+      };
     }
 
-    public <S extends ResponseContext>S extensionRequest(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request, ProviderHelper.getDefaultMethods(request));
-    }
-
-    public <S extends ResponseContext>S getCategories(RequestContext request) {
-        return (S)ProviderHelper.notfound(request);
+    private Function<RequestContext,ResponseContext> getCategories() {
+      return NOT_FOUND;
     }
-
+    
     public abstract Feed getFeed() throws Exception;
 
     public abstract Entry getEntry(Object entryId) throws Exception;

Modified: abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/CollectionAdapterManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/CollectionAdapterManager.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/CollectionAdapterManager.java (original)
+++ abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/CollectionAdapterManager.java Fri Oct 21 23:47:50 2011
@@ -27,14 +27,15 @@ import java.util.Map;
 import java.util.logging.Logger;
 
 import org.apache.abdera2.Abdera;
-import org.apache.abdera2.protocol.server.AtompubCollectionAdapter;
+import org.apache.abdera2.common.protocol.CollectionAdapter;
 
 public class CollectionAdapterManager {
 
     public static Logger logger = Logger.getLogger(CollectionAdapterManager.class.getName());
 
     // maps a feed id to an adapter instance
-    protected static Map<String, AtompubCollectionAdapter> adapterInstanceMap = new HashMap<String, AtompubCollectionAdapter>();
+    protected static Map<String, CollectionAdapter> adapterInstanceMap = 
+      new HashMap<String, CollectionAdapter>();
 
     protected final Abdera abdera;
     protected final ServerConfiguration config;
@@ -44,7 +45,7 @@ public class CollectionAdapterManager {
         this.config = config;
     }
 
-    public AtompubCollectionAdapter getAdapter(String feedId) throws Exception {
+    public CollectionAdapter getAdapter(String feedId) throws Exception {
         FeedConfiguration feedConfiguration = config.loadFeedConfiguration(feedId);
         return createAdapterInstance(feedConfiguration, abdera);
     }
@@ -85,9 +86,9 @@ public class CollectionAdapterManager {
         return config.loadFeedConfiguration(feedId);
     }
 
-    protected static synchronized AtompubCollectionAdapter createAdapterInstance(FeedConfiguration config, Abdera abdera)
+    protected static synchronized CollectionAdapter createAdapterInstance(FeedConfiguration config, Abdera abdera)
         throws Exception {
-        AtompubCollectionAdapter basicAdapter = adapterInstanceMap.get(config.getFeedId());
+        CollectionAdapter basicAdapter = adapterInstanceMap.get(config.getFeedId());
         if (basicAdapter != null) {
             return basicAdapter;
         }
@@ -99,7 +100,7 @@ public class CollectionAdapterManager {
         }
         Constructor<?> c = adapterClass.getConstructor(new Class[] {Abdera.class, FeedConfiguration.class});
         c.setAccessible(true);
-        AtompubCollectionAdapter adapterInstance = (AtompubCollectionAdapter)c.newInstance(abdera, config);
+        CollectionAdapter adapterInstance = (CollectionAdapter)c.newInstance(abdera, config);
 
         // put this adapter instance in adapterInstanceMap
         adapterInstanceMap.put(config.getFeedId(), adapterInstance);



Mime
View raw message