abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1187599 [1/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
Author: jmsnell
Date: Fri Oct 21 23:47:50 2011
New Revision: 1187599

URL: http://svn.apache.org/viewvc?rev=1187599&view=rev
Log:
Ok, major update, part 3... this is a significant refactoring of the fundamental server code. The focus is on cleaning up the design, increasing flexibility, and modernizing everything. For people who have built on top of the BasicProvider interface, very little change will be noticeable... however, if you've implemented custom CollectionAdapters or Providers, then you need to pay close attention to these changes because they are significant. Overall, the new design is a major improvement and introduces a number of compelling new options. This has not been fully tested and it is quite likely that test cases are broken. I will get to fixing those either this weekend or early next week.

Added:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Functions.java   (with props)
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TargetFunctionResolver.java   (with props)
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/TransactionalRequestProcessor.java   (with props)
Removed:
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Filter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaCollectionAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/PatchMediaAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/AtompubCollectionAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/AtompubMediaCollectionAdapter.java
Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivitiesSession.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesRequestContext.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/FeedConfiguration.java
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/ManagedCollectionAdapter.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaClientResponseImpl.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java
    abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/ExceptionHelper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractCollectionAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractRequest.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponse.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceManager.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceProvider.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseProvider.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseRequestContextWrapper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BaseResponseContextWrapper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicCollectionInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/BasicWorkspaceInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionAdapter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CollectionRequestProcessor.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/CompressionFilter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/DefaultWorkspaceManager.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/EntryRequestProcessor.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaRequestProcessor.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MediaResponseContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Message.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/MethodOverrideFilter.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Provider.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ProviderHelper.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Request.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/RequestProcessor.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Response.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ResponseContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/ResponseContextException.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/Target.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/WorkspaceInfo.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/WorkspaceManager.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/AbstractAbderaServlet.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/ServletRequestContext.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/servlet/async/AbderaTask.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/model/Collection.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/parser/axiom/FOMCollection.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/AbstractEntityProvider.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/protocol/EntityProvider.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/writer/AbstractStreamWriter.java
    abdera/abdera2/core/src/main/java/org/apache/abdera2/writer/StreamWriter.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/appserver/employee/AppServer.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/appserver/employee/EmployeeCollectionAdapter.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java
    abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedRequestFilter.java
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/AbstractEncryptedResponseFilter.java
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedRequestFilter.java
    abdera/abdera2/security/src/main/java/org/apache/abdera2/security/util/filters/SignedResponseFilter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubCollectionAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubProvider.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractAtompubWorkspaceProvider.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/AbstractEntityCollectionAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/DefaultAtompubProvider.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoriesInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCategoryInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleCollectionInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/impl/SimpleWorkspaceInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/model/AtompubCollectionInfo.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/multipart/AbstractMultipartCollectionAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/CategoriesRequestProcessor.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/MultipartRelatedServiceRequestProcessor.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/processors/ServiceRequestProcessor.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/basic/BasicAdapter.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/CollectionAdapterManager.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/FeedConfiguration.java
    abdera/abdera2/server/src/main/java/org/apache/abdera2/protocol/server/provider/managed/ManagedCollectionAdapter.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/client/AppTest.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/CustomProvider.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/security/filter/SimpleAdapter.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/CustomProvider.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/custom/SimpleAdapter.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/customer/CustomerAdapter.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/customer/CustomerAdapterTest.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/multipart/MultipartRelatedAdapter.java
    abdera/abdera2/test/src/main/java/org/apache/abdera2/test/server/multipart/MultipartRelatedTest.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivitiesSession.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivitiesSession.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivitiesSession.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/client/ActivitiesSession.java Fri Oct 21 23:47:50 2011
@@ -1,7 +1,5 @@
 package org.apache.abdera2.activities.client;
 
-import java.util.Date;
-
 import javax.activation.MimeType;
 
 import org.apache.abdera2.activities.model.ASBase;
@@ -146,9 +144,9 @@ public class ActivitiesSession 
     EntityTag etag = resp.getEntityTag();
     if (etag != null)
         base.setEntityTag(etag);
-    Date lm = resp.getLastModified();
+    DateTime lm = resp.getLastModified();
     if (lm != null)
-        base.setLastModified(new DateTime(lm));
+        base.setLastModified(lm);
     MimeType mt = resp.getContentType();
     if (mt != null)
         base.setContentType(mt.toString());

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesCollectionAdapter.java Fri Oct 21 23:47:50 2011
@@ -18,6 +18,7 @@
 package org.apache.abdera2.activities.protocol;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
@@ -32,18 +33,21 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.ResponseContextException;
 import org.joda.time.DateTime;
 
-@SuppressWarnings("unchecked")
 public abstract class AbstractActivitiesCollectionAdapter
   extends AbstractCollectionAdapter
   implements CollectionAdapter, 
              CollectionInfo {
 
-  public String[] getAccepts(RequestContext request) {
-    return new String[] {"application/json"};
+  public AbstractActivitiesCollectionAdapter(String href) {
+    super(href);
+  }
+
+  public Iterable<String> getAccepts(RequestContext request) {
+    return Arrays.asList("application/json");
   }
   
-  protected <S extends ResponseContext>S buildCreateEntryResponse(String link, ASBase base) {
-    return (S)
+  protected ResponseContext buildCreateEntryResponse(String link, ASBase base) {
+    return
       new ActivitiesResponseContext<ASBase>(base)
         .setLocation(link)
         .setContentLocation(link)
@@ -51,16 +55,16 @@ public abstract class AbstractActivities
         .setStatus(201);
   }
 
-  protected <S extends ResponseContext>S buildGetEntryResponse(RequestContext request, ASObject base)
+  protected ResponseContext buildGetEntryResponse(RequestContext request, ASObject base)
       throws ResponseContextException {
       base.setSource(createSourceObject(request));
-      return (S)
+      return 
         new ActivitiesResponseContext<ASObject>(base)
          .setEntityTag(AbstractActivitiesProvider.calculateEntityTag(base));
   }
 
-  protected <S extends ResponseContext>S buildGetFeedResponse(Collection<ASObject> collection) {
-      return (S) 
+  protected ResponseContext buildGetFeedResponse(Collection<ASObject> collection) {
+      return 
         new ActivitiesResponseContext<Collection<ASObject>>(collection)
           .setEntityTag(AbstractActivitiesProvider.calculateEntityTag(collection));
   }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesProvider.java Fri Oct 21 23:47:50 2011
@@ -27,34 +27,36 @@ import org.apache.abdera2.activities.mod
 import org.apache.abdera2.activities.model.TypeAdapter;
 import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
-import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 import org.apache.abdera2.common.protocol.BaseProvider;
 import org.apache.abdera2.common.protocol.CollectionRequestProcessor;
 import org.apache.abdera2.common.protocol.EntryRequestProcessor;
 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.common.protocol.WorkspaceManager;
 
-@SuppressWarnings("unchecked")
 public abstract class AbstractActivitiesProvider 
   extends BaseProvider
   implements ActivitiesProvider {
 
   protected Set<TypeAdapter<?>> typeAdapters = new HashSet<TypeAdapter<?>>();
+  protected final WorkspaceManager workspaceManager;
   
-  protected AbstractActivitiesProvider() {
+  protected AbstractActivitiesProvider(
+    WorkspaceManager workspaceManager) {
+    this.workspaceManager = workspaceManager;
     this.requestProcessors.put(
       TargetType.TYPE_COLLECTION, 
-      new CollectionRequestProcessor() {
-        protected boolean isAcceptableItemType(RequestContext context) {
-          return MimeTypeHelper.isMatch(
-            context.getContentType().toString(), 
-            "application/json");
-        }        
-      });
+      RequestProcessor.forClass(
+        CollectionRequestProcessor.class,
+        workspaceManager,
+        AbstractActivitiesWorkspaceProvider.isJson()));
     this.requestProcessors.put(
       TargetType.TYPE_ENTRY, 
-      new EntryRequestProcessor());
+      RequestProcessor.forClass(
+        EntryRequestProcessor.class,
+        workspaceManager));
   }
   
   public void addTypeAdapter(TypeAdapter<?> typeAdapter) {
@@ -69,11 +71,11 @@ public abstract class AbstractActivities
     return typeAdapters;
   }
   
-  public <S extends ResponseContext> S createErrorResponse(
+  public ResponseContext createErrorResponse(
     int code,
     String message, 
     Throwable t) {
-      return (S) 
+      return
         new ActivitiesResponseContext<ErrorObject>(
             ErrorObject
             .makeError()
@@ -85,8 +87,8 @@ public abstract class AbstractActivities
   }
 
   @Override
-  public <S extends ResponseContext> S process(RequestContext request) {
-    return (S)super.process(
+  public ResponseContext apply(RequestContext request) {
+    return super.apply(
       request instanceof ActivitiesRequestContext?
         request:
         new ActivitiesRequestContext(request));

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/AbstractActivitiesWorkspaceProvider.java Fri Oct 21 23:47:50 2011
@@ -27,10 +27,13 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.EntryRequestProcessor;
 import org.apache.abdera2.common.protocol.Provider;
 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.common.protocol.WorkspaceManager;
 
+import com.google.common.base.Predicate;
+
 public abstract class AbstractActivitiesWorkspaceProvider 
   extends AbstractWorkspaceProvider
   implements Provider, 
@@ -39,16 +42,25 @@ public abstract class AbstractActivities
   
   protected Set<TypeAdapter<?>> typeAdapters = new HashSet<TypeAdapter<?>>();
   
+  public static Predicate<RequestContext> isJson() {
+    return new Predicate<RequestContext>() {
+      public boolean apply(RequestContext input) {
+        return MimeTypeHelper.isJson(input.getContentType().toString());
+      }
+    };
+  }
+  
   protected AbstractActivitiesWorkspaceProvider() {
-    this.requestProcessors.put(TargetType.TYPE_COLLECTION, 
-        new CollectionRequestProcessor() {
-          protected boolean isAcceptableItemType(RequestContext context) {
-            return MimeTypeHelper.isMatch(
-                context.getContentType().toString(), 
-                "application/json");
-          }
-    });
-    this.requestProcessors.put(TargetType.TYPE_ENTRY, new EntryRequestProcessor());
+    this.requestProcessors.put(
+      TargetType.TYPE_COLLECTION, 
+      RequestProcessor.forClass(
+        CollectionRequestProcessor.class, 
+        this,isJson()));
+    this.requestProcessors.put(
+      TargetType.TYPE_ENTRY, 
+      RequestProcessor.forClass(
+        EntryRequestProcessor.class,
+        this));
   }
   
   public void addTypeAdapter(TypeAdapter<?> typeAdapter) {
@@ -63,7 +75,7 @@ public abstract class AbstractActivities
     return typeAdapters;
   }
   
-  public <S extends ResponseContext> S createErrorResponse(
+  public ResponseContext createErrorResponse(
     int code,
     String message, 
     Throwable t) {
@@ -77,11 +89,10 @@ public abstract class AbstractActivities
         .setStatus(code)
         .setStatusText(message);
   }
-  
-  @SuppressWarnings("unchecked")
+
   @Override
-  public <S extends ResponseContext> S process(RequestContext request) {
-    return (S)super.process(
+  public ResponseContext apply(RequestContext request) {
+    return super.apply(
       request instanceof ActivitiesRequestContext?
         request:
         new ActivitiesRequestContext(request));

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesRequestContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesRequestContext.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesRequestContext.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesRequestContext.java Fri Oct 21 23:47:50 2011
@@ -19,7 +19,6 @@ package org.apache.abdera2.activities.pr
 
 import java.io.IOException;
 import java.io.Reader;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -71,9 +70,9 @@ public class ActivitiesRequestContext ex
     String etag = getHeader("ETag");
     if (etag != null)
         base.setEntityTag(etag);
-    Date lm = getDateHeader("Last-Modified");
+    DateTime lm = getDateHeader("Last-Modified");
     if (lm != null)
-        base.setLastModified(new DateTime(lm));
+        base.setLastModified(lm);
     MimeType mt = getContentType();
     if (mt != null)
         base.setContentType(mt.toString());

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/DefaultActivitiesProvider.java Fri Oct 21 23:47:50 2011
@@ -35,7 +35,6 @@ import org.apache.abdera2.common.protoco
 public class DefaultActivitiesProvider
   extends AbstractActivitiesProvider {
 
-  protected WorkspaceManager workspaceManager;
   protected Resolver<Target,RequestContext> targetResolver;
   protected Resolver<Subject,Request> subjectResolver;
   protected TargetBuilder<?> targetBuilder;
@@ -47,8 +46,8 @@ public class DefaultActivitiesProvider
   
   @SuppressWarnings({ "unchecked", "rawtypes" })
   public DefaultActivitiesProvider(String base) {
+    super(new DefaultWorkspaceManager());
     if (base == null) base = "/";
-    workspaceManager = new DefaultWorkspaceManager();
     routeManager =
         new RouteManager()
           .addRoute("stream", base + ":stream", TargetType.TYPE_COLLECTION)
@@ -95,10 +94,6 @@ public class DefaultActivitiesProvider
       return workspaceManager;
   }
 
-  public void setWorkspaceManager(WorkspaceManager workspaceManager) {
-      this.workspaceManager = workspaceManager;
-  }
-
   @SuppressWarnings("rawtypes")
   public TargetBuilder getTargetBuilder() {
       return (TargetBuilder)targetBuilder;

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicAdapter.java Fri Oct 21 23:47:50 2011
@@ -44,6 +44,8 @@ import org.apache.abdera2.common.pusher.
 import org.apache.abdera2.common.pusher.Pusher;
 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
@@ -55,6 +57,13 @@ public abstract class BasicAdapter exten
 
     protected BasicAdapter(FeedConfiguration config) {
         super(config);
+        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,"DELETE",deleteItem());
+        putHandler(TargetType.TYPE_ENTRY,"PUT",putItem());
     }
 
     public String getProperty(String key) throws Exception {
@@ -115,13 +124,13 @@ public abstract class BasicAdapter exten
       }
     }
     
-    private <S extends ResponseContext>S createOrUpdateObject(RequestContext context, boolean createFlag) {
+    private ResponseContext createOrUpdateObject(RequestContext context, boolean createFlag) {
         try {
             ActivitiesRequestContext request = (ActivitiesRequestContext) context;
             MimeType mimeType = request.getContentType();
             String contentType = mimeType == null ? null : mimeType.toString();
             if (contentType != null && !MimeTypeHelper.isJson(contentType))
-                return (S)ProviderHelper.notsupported(request);
+                return ProviderHelper.notsupported(request);
             
             ASBase base = (ASBase)request.getEntity();
             Target target = request.getTarget();
@@ -143,7 +152,7 @@ public abstract class BasicAdapter exten
                   retl.addItem(err);
                 }
               }
-              return (S)
+              return
                 new ActivitiesResponseContext<Collection<ASObject>>(retl)
                   .setStatus(createFlag?201:200);
             } else if (base instanceof ASObject){
@@ -157,73 +166,88 @@ public abstract class BasicAdapter exten
                     new ActivitiesResponseContext<ASObject>(newEntry);
                   rc.setStatus(createFlag?201:200);
                   rc.setLocation(loc);
-                  return (S)rc;
+                  return rc;
               } else {
-                  return (S)ProviderHelper.notfound(request);
+                  return ProviderHelper.notfound(request);
               }
             } else {
-              return (S)ProviderHelper.notallowed(request);
+              return ProviderHelper.notallowed(request);
             }
             
         } catch (Exception e) {
-            return (S)ProviderHelper.servererror(context, e.getMessage(), e);
+            return ProviderHelper.servererror(context, e.getMessage(), e);
         }
     }
 
-    public <S extends ResponseContext>S postItem(RequestContext request) {
-        return (S)createOrUpdateObject(request, true);
-    }
-
-    public <S extends ResponseContext>S deleteItem(RequestContext request) {
-        Target target = request.getTarget();
-        String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
-        try {
-            return (S)(deleteItem(entryId) ? ProviderHelper.nocontent() : ProviderHelper.notfound(request));
-        } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), e);
+    private Function<RequestContext,ResponseContext> postItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createOrUpdateObject(input,true);
         }
+      };
     }
-
-    public <S extends ResponseContext>S putItem(RequestContext request) {
-        return (S)createOrUpdateObject(request, false);
+    
+    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 deleteItem(entryId) ? 
+                ProviderHelper.nocontent() : 
+                ProviderHelper.notfound(input);
+          } catch (Exception e) {
+              return ProviderHelper.servererror(
+                input, e.getMessage(), e);
+          }
+        }
+      };
     }
 
-    public <S extends ResponseContext>S getItem(RequestContext request) {
-        Target target = request.getTarget();
-        String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
-        try {
-            ASObject object = getItem(entryId);
-            if (object != null) {
-              return (S) 
-                new ActivitiesResponseContext<ASObject>(object)
-                  .setStatus(200);
-            } else return (S)ProviderHelper.notfound(request);       
-        } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), e);
+    private Function<RequestContext,ResponseContext> putItem() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return createOrUpdateObject(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 {
+              ASObject object = getItem(entryId);
+              if (object != null) {
+                return 
+                  new ActivitiesResponseContext<ASObject>(object)
+                    .setStatus(200);
+              } else return ProviderHelper.notfound(input);       
+          } catch (Exception e) {
+              return ProviderHelper.servererror(input, e.getMessage(), e);
+          }
         }
+      };
     }
 
-    public <S extends ResponseContext>S getItemList(RequestContext request) {
-        try {
+    public Function<RequestContext,ResponseContext> getItemList() {
+      return new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          try {
             Collection<ASObject> collection = 
               getCollection();
 
             if (collection != null) { 
-              return (S) 
+              return 
                 new ActivitiesResponseContext<Collection<ASObject>>(collection)
                   .setStatus(200);
-            } else return (S)ProviderHelper.notfound(request);
+            } else return ProviderHelper.notfound(input);
         } catch (Exception e) {
-            return (S)ProviderHelper.servererror(request, e.getMessage(), 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);
+        }
+      };
     }
 
     public abstract Collection<ASObject> getCollection() throws Exception;

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/basic/BasicProvider.java Fri Oct 21 23:47:50 2011
@@ -59,7 +59,8 @@ public class BasicProvider extends Manag
     public CollectionAdapter getCollectionAdapter(RequestContext request) {
         try {
             return getCollectionAdapterManager(request)
-              .getAdapter(request.getTarget().getParameter(PARAM_FEED));
+              .getAdapter(
+                request.getTarget().getParameter(PARAM_FEED));
         } catch (Exception e) {
             return null;
         }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/FeedConfiguration.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/FeedConfiguration.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/FeedConfiguration.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/FeedConfiguration.java Fri Oct 21 23:47:50 2011
@@ -17,12 +17,16 @@
  */
 package org.apache.abdera2.activities.protocol.managed;
 
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.abdera2.common.protocol.CollectionInfo;
 import org.apache.abdera2.common.protocol.RequestContext;
 
+import com.google.common.base.Supplier;
+
 public class FeedConfiguration extends Configuration implements CollectionInfo {
     public static final String PROP_NAME_ADAPTER_CLASS = "adapterClassName";
     public static final String PROP_SUB_URI_NAME = "subUri";
@@ -39,46 +43,127 @@ public class FeedConfiguration extends C
     public static final String ENTRY_ELEM_NAME_UPDATED = "updated";
     public static final String ENTRY_ELEM_NAME_LINK = "link";
 
+    public static class Generator implements Supplier<FeedConfiguration> {
+
+      private String feedId;
+      private String subUri;
+      private String adapterClassName;
+      private String feedConfigLocation;
+      private ServerConfiguration serverConfiguration;
+      private String feedTitle = "unknown";
+      private String feedAuthor = "unknown";
+      private final Map<Object, Object> optionalProperties = 
+        new HashMap<Object,Object>();
+      private CollectionAdapterConfiguration adapterConfiguration;      
+      
+      public Generator id(String id) {
+        this.feedId = id;
+        return this;
+      }
+      
+      public Generator subUri(String uri) {
+        this.subUri = uri;
+        return this;
+      }
+      
+      public Generator adapter(String className) {
+        this.adapterClassName = className;
+        return this;
+      }
+      
+      public Generator location(String location) {
+        this.feedConfigLocation = location;
+        return this;
+      }
+      
+      public Generator serverConfig(ServerConfiguration config) {
+        this.serverConfiguration = config;
+        return this;
+      }
+      
+      public Generator title(String title) {
+        this.feedTitle = title;
+        return this;
+      }
+      
+      public Generator author(String author) {
+        this.feedAuthor = author;
+        return this;
+      }
+      
+      public Generator set(Object key, Object val) {
+        this.optionalProperties.put(key, val);
+        return this;
+      }
+      
+      public Generator setAll(Map<Object,Object> props) {
+        this.optionalProperties.putAll(props);
+        return this;
+      }
+      
+      public Generator adapterConfif(CollectionAdapterConfiguration config) {
+        this.adapterConfiguration = config;
+        return this;
+      }
+      
+      public FeedConfiguration get() {
+        return new FeedConfiguration(this);
+      }
+      
+    }
+    
+    public static Generator make() {
+      return new Generator();
+    }
+    
     private final String feedId;
     private final String subUri;
     private final String adapterClassName;
     private final String feedConfigLocation;
     private final ServerConfiguration serverConfiguration;
-    private String feedTitle = "unknown";
-    private String feedAuthor = "unknown";
-    private Map<Object, Object> optionalProperties;
+    private final String feedTitle;
+    private final String feedAuthor;
+    private final Map<Object, Object> optionalProperties = 
+      new HashMap<Object,Object>();
     private final CollectionAdapterConfiguration adapterConfiguration;
 
-    public FeedConfiguration(String feedId,
-                             String subUri,
-                             String adapterClassName,
-                             String feedConfigLocation,
-                             ServerConfiguration serverConfiguration) {
-        this.feedId = feedId;
-        this.subUri = subUri;
-        this.adapterClassName = adapterClassName;
-        this.feedConfigLocation = feedConfigLocation;
-        this.adapterConfiguration = new CollectionAdapterConfiguration(serverConfiguration, feedConfigLocation);
-        this.serverConfiguration = serverConfiguration;
-    }
-
-    public static FeedConfiguration getFeedConfiguration(String feedId,
-                                                         Properties properties,
-                                                         ServerConfiguration serverConfiguration) {
-        FeedConfiguration feedConfiguration =
-            new FeedConfiguration(feedId, Configuration.getProperty(properties, PROP_SUB_URI_NAME), Configuration
-                .getProperty(properties, PROP_NAME_ADAPTER_CLASS), Configuration
-                .getProperty(properties, PROP_FEED_CONFIG_LOCATION_NAME), serverConfiguration);
-        if (properties.containsKey(PROP_AUTHOR_NAME)) {
-            feedConfiguration.setFeedAuthor(Configuration.getProperty(properties, PROP_AUTHOR_NAME));
-        }
-
-        if (properties.containsKey(PROP_TITLE_NAME)) {
-            feedConfiguration.setFeedTitle(Configuration.getProperty(properties, PROP_TITLE_NAME));
-        }
-        feedConfiguration.optionalProperties = properties;
-        return feedConfiguration;
-    }
+    protected FeedConfiguration(Generator gen) {
+      this.feedId = gen.feedId;
+      this.subUri = gen.subUri;
+      this.adapterClassName = gen.adapterClassName;
+      this.feedConfigLocation = gen.feedConfigLocation;
+      this.serverConfiguration = gen.serverConfiguration;
+      this.feedTitle = gen.feedTitle;
+      this.feedAuthor = gen.feedAuthor;
+      this.optionalProperties.putAll(gen.optionalProperties);
+      this.adapterConfiguration = gen.adapterConfiguration;
+    }
+
+    public static FeedConfiguration getFeedConfiguration(
+        String feedId,
+        Properties properties,
+        ServerConfiguration serverConfiguration) {
+        
+        String author = "unknown";
+        String title = "unknown";
+        
+        if (properties.containsKey(PROP_AUTHOR_NAME))
+          author = Configuration.getProperty(properties, PROP_AUTHOR_NAME);
+        if (properties.containsKey(PROP_TITLE_NAME))
+          title = Configuration.getProperty(properties, PROP_TITLE_NAME);
+        
+        return FeedConfiguration
+          .make()
+            .id(feedId)
+            .subUri(Configuration.getProperty(properties, PROP_SUB_URI_NAME))
+            .adapter(Configuration.getProperty(properties, PROP_NAME_ADAPTER_CLASS))
+            .location(Configuration.getProperty(properties, PROP_FEED_CONFIG_LOCATION_NAME))
+            .serverConfig(serverConfiguration)
+            .title(title)
+            .author(author)
+            .setAll(properties)
+          .get();
+      }
 
     public String getAdapterClassName() {
         return adapterClassName;
@@ -104,14 +189,6 @@ public class FeedConfiguration extends C
         return subUri;
     }
 
-    public void setFeedAuthor(String feedAuthor) {
-        this.feedAuthor = feedAuthor;
-    }
-
-    public void setFeedTitle(String feedTitle) {
-        this.feedTitle = feedTitle;
-    }
-
     public String getFeedUri() {
         return serverConfiguration.getServerUri() + "/" + getSubUri();
     }
@@ -128,11 +205,13 @@ public class FeedConfiguration extends C
         return adapterConfiguration;
     }
     
-    public String[] getAccepts(RequestContext request) {
+    public Iterable<String> getAccepts(RequestContext request) {
         Object accepts = optionalProperties.get(PROP_ACCEPTS);
+        String[] arr = null;
         if (accepts == null || !(accepts instanceof String))
-            return new String[] {"application/json"};
-        return ((String)accepts).split("\\s*,\\s*");
+            arr = new String[] {"application/json"};
+        arr = ((String)accepts).split("\\s*,\\s*");
+        return Arrays.<String>asList(arr);
     }
 
     public String getHref(RequestContext request) {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/ManagedCollectionAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/ManagedCollectionAdapter.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/ManagedCollectionAdapter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/managed/ManagedCollectionAdapter.java Fri Oct 21 23:47:50 2011
@@ -29,6 +29,7 @@ public abstract class ManagedCollectionA
     protected final FeedConfiguration config;
 
     protected ManagedCollectionAdapter(FeedConfiguration config) {
+      super(null);
         this.config = config;
     }
 

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaClientResponseImpl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaClientResponseImpl.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaClientResponseImpl.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaClientResponseImpl.java Fri Oct 21 23:47:50 2011
@@ -17,8 +17,6 @@
  */
 package org.apache.abdera2.protocol.client;
 
-import java.util.Date;
-
 import javax.activation.MimeType;
 
 import org.apache.abdera2.common.http.EntityTag;
@@ -76,9 +74,9 @@ class AbderaClientResponseImpl 
       EntityTag etag = getEntityTag();
       if (etag != null)
           doc.setEntityTag(etag);
-      Date lm = getLastModified();
+      DateTime lm = getLastModified();
       if (lm != null)
-          doc.setLastModified(new DateTime(lm));
+          doc.setLastModified(lm);
       MimeType mt = getContentType();
       if (mt != null)
           doc.setContentType(mt.toString());

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java Fri Oct 21 23:47:50 2011
@@ -17,7 +17,6 @@
  */
 package org.apache.abdera2.protocol.client;
 
-import java.util.Date;
 import org.apache.abdera2.Abdera;
 import org.apache.abdera2.model.Base;
 import org.apache.abdera2.model.Document;
@@ -30,6 +29,7 @@ import org.apache.abdera2.common.http.En
 import org.apache.abdera2.common.http.Method;
 import org.apache.abdera2.common.http.ResponseType;
 import org.apache.http.entity.mime.content.ContentBody;
+import org.joda.time.DateTime;
 
 /**
  * A client session. Session's MUST NOT be used by more
@@ -141,7 +141,7 @@ public class AbderaSession extends Sessi
             if (etag != null)
                 options.setIfMatch(etag);
             else {
-                Date lm = provider.getLastModified();
+                DateTime lm = provider.getLastModified();
                 if (lm != null)
                     options.setIfUnmodifiedSince(lm);
             }
@@ -168,7 +168,7 @@ public class AbderaSession extends Sessi
                 if (d.getEntityTag() != null)
                     options.setIfMatch(d.getEntityTag());
                 else if (d.getLastModified() != null)
-                    options.setIfUnmodifiedSince(d.getLastModified().toDate());
+                    options.setIfUnmodifiedSince(d.getLastModified());
             }
         }
         return (T)wrap(execute("PUT", uri, new AbderaEntity(base), options));

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java Fri Oct 21 23:47:50 2011
@@ -21,10 +21,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
-import java.util.Date;
 
 import org.apache.abdera2.common.http.Method;
 import org.apache.abdera2.common.protocol.Response;
+import org.joda.time.DateTime;
 
 public interface ClientResponse extends Response {
 
@@ -64,7 +64,7 @@ public interface ClientResponse extends 
     /**
      * Return the server-specified date returned in the response
      */
-    Date getServerDate();
+    DateTime getServerDate();
 
     /**
      * Return the character set encoding specified in the ContentType header, if any

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java Fri Oct 21 23:47:50 2011
@@ -24,7 +24,6 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -52,6 +51,7 @@ import org.apache.http.impl.cookie.DateU
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.EntityUtils;
+import org.joda.time.DateTime;
 
 class ClientResponseImpl 
   implements ClientResponse {
@@ -94,7 +94,7 @@ class ClientResponseImpl 
     return response.getStatusLine().getReasonPhrase();
   }
 
-  public Date getLastModified() {
+  public DateTime getLastModified() {
     return getDateHeader("Last-Modified");
   }
 
@@ -121,7 +121,7 @@ class ClientResponseImpl 
     return a != null ? Long.parseLong(a) : -1;
   }
 
-  public Date getExpires() {
+  public DateTime getExpires() {
     return getDateHeader("Expires");
   }
 
@@ -184,10 +184,10 @@ class ClientResponseImpl 
     return ct != null ? new Lang(ct).toString() : null;
   }
 
-  public Date getDateHeader(String name) {
+  public DateTime getDateHeader(String name) {
     try {
       String ct = getHeader(name);
-      return ct != null ? DateUtils.parseDate(ct) : null;
+      return ct != null ? new DateTime(DateUtils.parseDate(ct)) : null;
     } catch (Throwable t) {
       throw new RuntimeException(t);
     }
@@ -257,7 +257,7 @@ class ClientResponseImpl 
     return reader;
   }
 
-  public Date getServerDate() {
+  public DateTime getServerDate() {
     return getDateHeader("Date");
   }
 

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java Fri Oct 21 23:47:50 2011
@@ -4,7 +4,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
-import java.util.Date;
 
 import javax.activation.MimeType;
 
@@ -16,6 +15,7 @@ import org.apache.abdera2.common.http.Pr
 import org.apache.abdera2.common.http.ResponseType;
 import org.apache.abdera2.common.http.WebLink;
 import org.apache.abdera2.common.iri.IRI;
+import org.joda.time.DateTime;
 
 public class ClientResponseWrapper 
   implements ClientResponse {
@@ -42,7 +42,7 @@ public class ClientResponseWrapper 
     return internal.getStatusText();
   }
 
-  public Date getLastModified() {
+  public DateTime getLastModified() {
     return internal.getLastModified();
   }
 
@@ -62,7 +62,7 @@ public class ClientResponseWrapper 
     return internal.getAge();
   }
 
-  public Date getExpires() {
+  public DateTime getExpires() {
     return internal.getExpires();
   }
 
@@ -102,7 +102,7 @@ public class ClientResponseWrapper 
     return internal.getContentLanguage();
   }
 
-  public Date getDateHeader(String name) {
+  public DateTime getDateHeader(String name) {
     return internal.getDateHeader(name);
   }
 
@@ -150,7 +150,7 @@ public class ClientResponseWrapper 
     return internal.getReader(charset);
   }
 
-  public Date getServerDate() {
+  public DateTime getServerDate() {
     return internal.getServerDate();
   }
 

Modified: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java (original)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/RequestOptions.java Fri Oct 21 23:47:50 2011
@@ -17,7 +17,6 @@
  */
 package org.apache.abdera2.protocol.client;
 
-import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
@@ -39,6 +38,7 @@ import org.apache.abdera2.common.http.Pr
 import org.apache.abdera2.common.http.WebLink;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
+import org.joda.time.DateTime;
 
 /**
  * The RequestOptions class allows a variety of options affecting the execution of the request to be modified.
@@ -67,7 +67,7 @@ public class RequestOptions extends Abst
      * 
      * @param ifModifiedSince
      */
-    public RequestOptions(Date ifModifiedSince) {
+    public RequestOptions(DateTime ifModifiedSince) {
         this();
         setIfModifiedSince(ifModifiedSince);
     }
@@ -98,7 +98,7 @@ public class RequestOptions extends Abst
      * @param ifModifiedSince
      * @param IfNoneMatch
      */
-    public RequestOptions(Date ifModifiedSince, String ifNoneMatch) {
+    public RequestOptions(DateTime ifModifiedSince, String ifNoneMatch) {
         this();
         setIfModifiedSince(ifModifiedSince);
         setIfNoneMatch(ifNoneMatch);
@@ -110,7 +110,7 @@ public class RequestOptions extends Abst
      * @param ifModifiedSince
      * @param IfNoneMatch
      */
-    public RequestOptions(Date ifModifiedSince, String etag, String... ifNoneMatch) {
+    public RequestOptions(DateTime ifModifiedSince, String etag, String... ifNoneMatch) {
         this();
         setIfModifiedSince(ifModifiedSince);
         setIfNoneMatch(etag, ifNoneMatch);
@@ -228,8 +228,11 @@ public class RequestOptions extends Abst
     /**
      * Set the date value of the specified HTTP header
      */
-    public RequestOptions setDateHeader(String header, Date value) {
-        return value != null ? setHeader(header, DateUtils.formatDate(value)) : removeHeaders(header);
+    public RequestOptions setDateHeader(String header, DateTime value) {
+        return value != null ? setHeader(
+          header, 
+          DateUtils.formatDate(value.toDate())) : 
+            removeHeaders(header);
     }
 
     /**
@@ -284,10 +287,10 @@ public class RequestOptions extends Abst
     /**
      * Similar to setDateHeader but allows for multiple instances of the specified header
      */
-    public RequestOptions addDateHeader(String header, Date value) {
+    public RequestOptions addDateHeader(String header, DateTime value) {
         if (value == null)
             return this;
-        return addHeader(header, DateUtils.formatDate(value));
+        return addHeader(header, DateUtils.formatDate(value.toDate()));
     }
 
     /**
@@ -309,10 +312,10 @@ public class RequestOptions extends Abst
     /**
      * Returns the date value of the specified header
      */
-    public Date getDateHeader(String header) {
+    public DateTime getDateHeader(String header) {
         String val = getHeader(header);
         try {
-            return (val != null) ? DateUtils.parseDate(val) : null;
+            return (val != null) ? new DateTime(DateUtils.parseDate(val)) : null;
         } catch (DateParseException e) {
             throw new RuntimeException(e);
         }
@@ -384,14 +387,14 @@ public class RequestOptions extends Abst
     /**
      * Sets the value of the HTTP If-Modified-Since header
      */
-    public RequestOptions setIfModifiedSince(Date date) {
+    public RequestOptions setIfModifiedSince(DateTime date) {
         return setDateHeader("If-Modified-Since", date);
     }
 
     /**
      * Sets the value of the HTTP If-Unmodified-Since header
      */
-    public RequestOptions setIfUnmodifiedSince(Date date) {
+    public RequestOptions setIfUnmodifiedSince(DateTime date) {
         return setDateHeader("If-Unmodified-Since", date);
     }
 

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=1187599&r1=1187598&r2=1187599&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 Fri Oct 21 23:47:50 2011
@@ -1,6 +1,9 @@
 package org.apache.abdera2.common.misc;
 
+import org.apache.abdera2.common.http.ResponseType;
 import org.apache.abdera2.common.mediatype.MimeTypeParseException;
+import org.apache.abdera2.common.protocol.ResponseContextException;
+import org.apache.commons.logging.Log;
 
 public class ExceptionHelper {
 
@@ -15,4 +18,21 @@ public class ExceptionHelper {
     else return new RuntimeException(t);
   }
   
+  public static void log(Log log, Throwable t) {
+    if (t instanceof ResponseContextException) {
+      ResponseContextException rce = 
+        (ResponseContextException)t;
+        if (rce.getResponseType() == ResponseType.CLIENT_ERROR)
+            log.info(t);
+        else
+            log.error(t);
+    } else log.error(t);
+  }
+  
+  public static void responseLog(Log log, ResponseContextException t) {
+    if (log.isDebugEnabled())
+      log.debug("A ResponseException was thrown.", t);
+    else if (t.getResponseContext().getType() == ResponseType.SERVER_ERROR)
+      log.warn("A ResponseException was thrown.", t);
+  }
 }

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Functions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Functions.java?rev=1187599&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Functions.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/Functions.java Fri Oct 21 23:47:50 2011
@@ -0,0 +1,66 @@
+package org.apache.abdera2.common.misc;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+public class Functions {
+  
+  public static <T,X>Function<Iterable<T>,Iterable<X>> each(
+    final Function<T,X> apply) {
+      return new Function<Iterable<T>,Iterable<X>>() {
+        public Iterable<X> apply(Iterable<T> input) {
+          return each(input, apply);
+        }
+      };
+  }
+  
+  public static <T,X>Function<Iterable<T>,Iterable<X>> each(
+    final Function<T,X> apply,
+    final Predicate<T> predicate) {
+      return new Function<Iterable<T>,Iterable<X>>() {
+        public Iterable<X> apply(Iterable<T> input) {
+          return each(input, apply, predicate);
+        }
+      };
+  }
+  
+  public static <T,X>Iterable<X> each(Iterable<T> i, Function<T,X> apply) {
+    List<X> list = new ArrayList<X>();
+    for (T t : i) {
+      try {
+        list.add(apply.apply(t));
+      } catch (Throwable e) {
+        throw ExceptionHelper.propogate(e);
+      }
+    }
+    return Iterables.<X>unmodifiableIterable(list);
+  }
+  
+  public static <T,X>Iterable<X> each(Iterable<T> i, Function<T,X> apply, Predicate<T> test) {
+    List<X> list = new ArrayList<X>();
+    for (T t : i) {
+      try {
+        if (test.apply(t))
+          list.add(apply.apply(t));
+      } catch (Throwable e) {
+        throw ExceptionHelper.propogate(e);
+      }
+    }
+    return Iterables.<X>unmodifiableIterable(list);
+  }
+  
+  public static <T,X>X[] each(T[] i, Function<T,X> apply, Class<X> _class) {
+    Iterable<X> x = Functions.<T,X>each(Arrays.<T>asList(i),apply);
+    return Iterables.<X>toArray(x, _class);
+  }
+  
+  public static <T,X>X[] each(T[] i, Function<T,X> apply,Predicate<T> pred, Class<X> _class) {
+    Iterable<X> x = Functions.<T,X>each(Arrays.<T>asList(i),apply,pred);
+    return Iterables.<X>toArray(x, _class);
+  }
+}

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

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=1187599&r1=1187598&r2=1187599&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 Fri Oct 21 23:47:50 2011
@@ -17,105 +17,128 @@
  */
 package org.apache.abdera2.common.protocol;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.abdera2.common.text.UrlEncoding;
 import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.common.misc.ExceptionHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.joda.time.DateTime;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+
 /**
  * Base CollectionAdapter implementation that provides a number of helper 
  * utility methods for adapter implementations.
  */
-@SuppressWarnings("unchecked")
 public abstract class AbstractCollectionAdapter 
   implements CollectionAdapter, 
-             MediaCollectionAdapter, 
-             Transactional,
              CollectionInfo {
 
     private final static Log log = 
       LogFactory.getLog(AbstractCollectionAdapter.class);
 
     private String href;
-    private Map<String, Object> hrefParams = 
+    private final Map<String, Object> hrefParams = 
       new HashMap<String, Object>();
-
-    public AbstractCollectionAdapter() {
+    
+    private final Map<HandlerKey,Function<RequestContext,ResponseContext>> handlers = 
+      new HashMap<HandlerKey,Function<RequestContext,ResponseContext>>();
+
+    private static class HandlerKey implements Serializable {
+      private static final long serialVersionUID = -580349554867112812L;
+      private final TargetType type;
+      private final String method;
+      HandlerKey(TargetType type, String method) {
+        this.type = type;
+        this.method = method.toUpperCase();
+      }
+      public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((method == null) ? 0 : method.hashCode());
+        result = prime * result + ((type == null) ? 0 : type.hashCode());
+        return result;
+      }
+      public boolean equals(Object obj) {
+        if (this == obj)
+          return true;
+        if (obj == null)
+          return false;
+        if (getClass() != obj.getClass())
+          return false;
+        HandlerKey other = (HandlerKey) obj;
+        if (method == null) {
+          if (other.method != null)
+            return false;
+        } else if (!method.equals(other.method))
+          return false;
+        if (type == null) {
+          if (other.type != null)
+            return false;
+        } else if (!type.equals(other.type))
+          return false;
+        return true;
+      }
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected synchronized <X extends AbstractCollectionAdapter>X putHandler(
+      TargetType targetType,
+      String method,
+      Function<RequestContext,ResponseContext> handler) {
+        HandlerKey key = new HandlerKey(targetType,method);
+        handlers.put(key, handler);
+        return (X)this;
+    }
+    
+    public AbstractCollectionAdapter(String href) {
         super();
+        putHandler(TargetType.TYPE_CATEGORIES, "GET", NOT_FOUND);
+        putHandler(TargetType.TYPE_CATEGORIES, "HEAD", NOT_FOUND);
+        setHref(href);
     }
 
     public String getHref() {
         return href;
     }
 
-    public void setHref(String href) {
+    private void setHref(String href) {
         this.href = href;
-        hrefParams.put("collection", href);
+        if (href != null)
+          hrefParams.put("collection", href);
     }
 
     public String getHref(RequestContext request) {
         return request.urlFor("feed", hrefParams);
     }
 
-    public void compensate(RequestContext request, Throwable t) {
-    }
+    public abstract String getAuthor(
+      RequestContext request) 
+        throws ResponseContextException;
 
-    public void end(RequestContext request, ResponseContext response) {
-    }
-
-    public void start(RequestContext request) {
-    }
-
-    public <S extends ResponseContext>S deleteMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S getMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S headMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S optionsMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S putMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S postMedia(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S headItem(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public <S extends ResponseContext>S optionsItem(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request);
-    }
-
-    public abstract String getAuthor(RequestContext request) throws ResponseContextException;
-
-    public abstract String getId(RequestContext request);
+    public abstract String getId(
+      RequestContext request);
 
     /**
      * 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, DateTime updated)
+    protected ResponseContext buildHeadEntryResponse(
+      RequestContext request, 
+      String id, 
+      DateTime updated)
         throws ResponseContextException {
-        EmptyResponseContext rc = new EmptyResponseContext(200);
-        rc.setEntityTag(EntityTag.generate(id, DateTimes.format(updated)));
-        return (S)rc;
+        return new EmptyResponseContext(200)
+          .setEntityTag(
+            EntityTag.generate(
+              id, 
+              DateTimes.format(updated)));
     }
 
     /**
@@ -124,15 +147,10 @@ public abstract class AbstractCollection
      * @param e
      * @return
      */
-    protected <S extends ResponseContext>S createErrorResponse(ResponseContextException e) {
-        if (log.isDebugEnabled()) {
-            log.debug("A ResponseException was thrown.", e);
-        } else if (e.getResponseContext() instanceof EmptyResponseContext && ((EmptyResponseContext)e
-            .getResponseContext()).getStatus() >= 500) {
-            log.warn("A ResponseException was thrown.", e);
-        }
-
-        return (S)e.getResponseContext();
+    protected ResponseContext createErrorResponse(
+      ResponseContextException e) {
+        ExceptionHelper.responseLog(log,e);
+        return e.getResponseContext();
     }
 
     /**
@@ -149,12 +167,48 @@ public abstract class AbstractCollection
         return UrlEncoding.decode(id);
     }
 
-    public <S extends ResponseContext>S extensionRequest(RequestContext request) {
-        return (S)ProviderHelper.notallowed(request, getMethods(request));
-    }
-
-    private String[] getMethods(RequestContext request) {
+    protected String[] getMethods(RequestContext request) {
         return ProviderHelper.getDefaultMethods(request);
     }
 
+    private static final Predicate<HandlerKey> COLLECTION_POST_CHECK = 
+      new Predicate<HandlerKey>() {
+        public boolean apply(HandlerKey input) {
+          return input.method.equalsIgnoreCase("POST") && 
+                 input.type == TargetType.TYPE_COLLECTION;
+        }
+    };
+    
+    public Function<RequestContext,ResponseContext> handlerFor(
+      Target target, 
+      String method) {
+        HandlerKey key = new HandlerKey(target.getType(),method);
+        Function<RequestContext,ResponseContext> handler = handlers.get(key);
+        return handler != null ?
+          handler :
+          COLLECTION_POST_CHECK.apply(key) ? // if this is a post to a collection, and the handler is null
+            UNSUPPORTED_TYPE :               // return an unsupported_type reponse since POST is always 
+            NOT_ALLOWED;                     // allowed on the collection
+    }
+    
+    protected final Function<RequestContext,ResponseContext> UNSUPPORTED_TYPE = 
+      new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return ProviderHelper.notsupported(input);
+        }
+    };
+    
+    protected final Function<RequestContext,ResponseContext> NOT_ALLOWED =
+      new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return ProviderHelper.notallowed(input,getMethods(input));
+        }
+    };
+    
+    protected final Function<RequestContext,ResponseContext> NOT_FOUND = 
+      new Function<RequestContext,ResponseContext>() {
+        public ResponseContext apply(RequestContext input) {
+          return ProviderHelper.notfound(input);
+        }
+    };
 }

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractRequest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractRequest.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractRequest.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractRequest.java Fri Oct 21 23:47:50 2011
@@ -17,10 +17,9 @@
  */
 package org.apache.abdera2.common.protocol;
 
-import java.util.Date;
-
 import org.apache.abdera2.common.http.Authentication;
 import org.apache.abdera2.common.http.EntityTag;
+import org.joda.time.DateTime;
 
 public abstract class AbstractRequest extends AbstractMessage implements Request {
 
@@ -49,7 +48,7 @@ public abstract class AbstractRequest ex
         return EntityTag.parseTags(getHeader("If-Match"));
     }
 
-    public Date getIfModifiedSince() {
+    public DateTime getIfModifiedSince() {
         return getDateHeader("If-Modified-Since");
     }
 
@@ -57,7 +56,7 @@ public abstract class AbstractRequest ex
         return EntityTag.parseTags(getHeader("If-None-Match"));
     }
 
-    public Date getIfUnmodifiedSince() {
+    public DateTime getIfUnmodifiedSince() {
         return getDateHeader("If-Unmodified-Since");
     }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponse.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponse.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponse.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponse.java Fri Oct 21 23:47:50 2011
@@ -17,12 +17,11 @@
  */
 package org.apache.abdera2.common.protocol;
 
-import java.util.Date;
-
 import org.apache.abdera2.common.iri.IRI;
 import org.apache.abdera2.common.http.Authentication;
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.http.ResponseType;
+import org.joda.time.DateTime;
 
 public abstract class AbstractResponse extends AbstractMessage implements Response {
 
@@ -53,11 +52,11 @@ public abstract class AbstractResponse e
         return (etag != null) ? EntityTag.parse(getHeader("ETag")) : null;
     }
 
-    public Date getExpires() {
+    public DateTime getExpires() {
         return getDateHeader("Expires");
     }
 
-    public Date getLastModified() {
+    public DateTime getLastModified() {
         return getDateHeader("Last-Modified");
     }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractResponseContext.java Fri Oct 21 23:47:50 2011
@@ -17,6 +17,8 @@
  */
 package org.apache.abdera2.common.protocol;
 
+import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -34,6 +36,11 @@ import org.apache.abdera2.common.http.Ca
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.http.Preference;
 import org.apache.abdera2.common.http.WebLink;
+import org.apache.abdera2.common.mediatype.MimeTypeHelper;
+import org.apache.abdera2.common.misc.Functions;
+import org.joda.time.DateTime;
+
+import com.google.common.collect.Iterables;
 
 @SuppressWarnings("unchecked")
 public abstract class AbstractResponseContext extends AbstractResponse implements ResponseContext {
@@ -73,11 +80,10 @@ public abstract class AbstractResponseCo
     }
 
     public <T extends ResponseContext>T setEncodedHeader(String name, String charset, String... vals) {
-        Object[] evals = new Object[vals.length];
-        for (int n = 0; n < vals.length; n++) {
-            evals[n] = Codec.encode(vals[n], charset);
-        }
-        return (T)setHeader(name, evals);
+        String[] evals = 
+          Functions.<String,String>each(
+            vals, Codec.encodeStar(charset), String.class);
+        return (T)setHeader(name, (Object[])evals);
     }
 
     public <T extends ResponseContext>T setEscapedHeader(String name, Profile profile, String value) {
@@ -91,8 +97,7 @@ public abstract class AbstractResponseCo
     public <T extends ResponseContext>T setHeader(String name, Object... vals) {
         Map<String, Iterable<Object>> headers = getHeaders();
         Set<Object> values = new HashSet<Object>();
-        for (Object value : vals)
-            values.add(value);
+        values.addAll(Arrays.asList(vals));
         headers.put(name, values);
         return (T)this;
     }
@@ -102,10 +107,9 @@ public abstract class AbstractResponseCo
     }
 
     public <T extends ResponseContext>T addEncodedHeaders(String name, String charset, String... vals) {
-        for (String value : vals) {
-            addHeader(name, Codec.encode(value, charset));
-        }
-        return (T)this;
+      String[] evals = Functions.<String,String>each(vals, Codec.encodeStar(charset),String.class);
+      addHeaders(name,(Object[])evals);
+      return (T)this;
     }
 
     public <T extends ResponseContext>T addHeader(String name, Object value) {
@@ -115,14 +119,11 @@ public abstract class AbstractResponseCo
     public <T extends ResponseContext>T addHeaders(String name, Object... vals) {
         Map<String, Iterable<Object>> headers = getHeaders();
         Iterable<Object> values = headers.get(name);
-        Set<Object> l = null;
-        if (values == null)
-            l = new HashSet<Object>();
-        else
-            l = (Set<Object>)values;
-        for (Object value : vals) {
-            l.add(value);
-        }
+        Set<Object> l = 
+          values == null ? 
+            new HashSet<Object>() :
+            (Set<Object>)values;
+        l.addAll(Arrays.asList(vals));
         headers.put(name, l);
         return (T)this;
     }
@@ -133,25 +134,27 @@ public abstract class AbstractResponseCo
         return headers;
     }
 
-    public Date getDateHeader(String name) {
+    public DateTime getDateHeader(String name) {
         Map<String, Iterable<Object>> headers = getHeaders();
         Iterable<Object> values = headers.get(name);
         if (values != null) {
             for (Object value : values) {
                 if (value instanceof Date)
-                    return (Date)value;
+                    return new DateTime(value);
+                else if (value instanceof DateTime)
+                    return (DateTime)value;
+                else if (value instanceof Calendar)
+                    return new DateTime(value);
             }
         }
         return null;
     }
 
     public String getHeader(String name) {
-        Map<String, Iterable<Object>> headers = getHeaders();
-        Iterable<Object> values = headers.get(name);
-        if (values != null)
-          for (Object val : values)
-            return val.toString();
-        return null;
+      Map<String, Iterable<Object>> headers = getHeaders();
+      Iterable<Object> values = headers.get(name);
+      Object obj = Iterables.getFirst(values,null);
+      return obj != null ? obj.toString() : null;
     }
 
     public Iterable<Object> getHeaders(String name) {
@@ -181,12 +184,15 @@ public abstract class AbstractResponseCo
     }
 
     public <T extends ResponseContext>T setSlug(String slug) {
-        if (slug == null) {
+        if (slug == null)
             return (T)removeHeader("Slug");
-        }
-        if (slug.indexOf((char)10) > -1 || slug.indexOf((char)13) > -1)
-            throw new IllegalArgumentException(Localizer.get("SLUG.BAD.CHARACTERS"));
-        return (T)setEscapedHeader("Slug", Profile.PATHNODELIMS, slug);
+        if (slug.indexOf((char)10) > -1 || 
+            slug.indexOf((char)13) > -1)
+          throw new IllegalArgumentException(
+            Localizer.get("SLUG.BAD.CHARACTERS"));
+        return (T)setEscapedHeader(
+          "Slug", 
+          Profile.PATHNODELIMS, slug);
     }
 
     public <T extends ResponseContext>T setContentType(String type) {
@@ -194,17 +200,12 @@ public abstract class AbstractResponseCo
     }
 
     public <T extends ResponseContext>T setContentType(String type, String charset) {
-        if (type == null) {
+        if (type == null)
             return (T)removeHeader("Content-Type");
-        }
-        try {
-            MimeType mimeType = new MimeType(type);
-            if (charset != null)
-                mimeType.setParameter("charset", charset);
-            return (T)setHeader("Content-Type", mimeType.toString());
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+        MimeType mimeType = MimeTypeHelper.create(type);
+        if (charset != null)
+            mimeType.setParameter("charset", charset);
+        return (T)setHeader("Content-Type", mimeType.toString());
     }
 
     public <T extends ResponseContext>T setEntityTag(String etag) {
@@ -215,11 +216,11 @@ public abstract class AbstractResponseCo
         return (T)(etag == null ? removeHeader("ETag") : setHeader("ETag", etag.toString()));
     }
 
-    public <T extends ResponseContext>T setExpires(Date date) {
+    public <T extends ResponseContext>T setExpires(DateTime date) {
         return (T)(date == null ? removeHeader("Expires") : setHeader("Expires", date));
     }
 
-    public <T extends ResponseContext>T setLastModified(Date date) {
+    public <T extends ResponseContext>T setLastModified(DateTime date) {
         return (T)(date == null ? removeHeader("Last-Modified") : setHeader("Last-Modified", date));
     }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceManager.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceManager.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceManager.java Fri Oct 21 23:47:50 2011
@@ -18,10 +18,12 @@
 package org.apache.abdera2.common.protocol;
 
 import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
+import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
+import org.joda.time.DateTime;
 
 /**
  * Base implementation for WorkspaceManager implementations
@@ -29,26 +31,25 @@ import org.apache.abdera2.common.http.En
 public abstract class AbstractWorkspaceManager 
   implements WorkspaceManager {
 
-    protected Collection<WorkspaceInfo> workspaces;
+    protected final Set<WorkspaceInfo> workspaces = 
+      new LinkedHashSet<WorkspaceInfo>();
     public static final String COLLECTION_ADAPTER_ATTRIBUTE = "collectionProvider";
 
     public Collection<WorkspaceInfo> getWorkspaces(RequestContext request) {
         return workspaces;
     }
 
-    public void setWorkspaces(Collection<WorkspaceInfo> workspaces) {
-        this.workspaces = workspaces;
+    public synchronized void setWorkspaces(Collection<WorkspaceInfo> workspaces) {
+        this.workspaces.clear();
+        this.workspaces.addAll(workspaces);
     }
 
-    public void addWorkspace(WorkspaceInfo workspace) {
-        if (workspaces == null) {
-            workspaces = new HashSet<WorkspaceInfo>();
-        }
+    public synchronized void addWorkspace(WorkspaceInfo workspace) {
         workspaces.add(workspace);
     }
     
-    public Date getLastModified() {
-      return new Date();
+    public DateTime getLastModified() {
+      return DateTimes.utcNow();
     }
     
     public EntityTag getEntityTag() { 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceProvider.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceProvider.java?rev=1187599&r1=1187598&r2=1187599&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceProvider.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/protocol/AbstractWorkspaceProvider.java Fri Oct 21 23:47:50 2011
@@ -18,11 +18,13 @@
 package org.apache.abdera2.common.protocol;
 
 import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
+import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.misc.Resolver;
+import org.joda.time.DateTime;
 
 /**
  * An abstract base Provider implementation that implements the WorkspaceManager interface. This is intended to be used
@@ -34,9 +36,10 @@ public abstract class AbstractWorkspaceP
 
     protected Resolver<Target,RequestContext> targetResolver;
     protected TargetBuilder<?> targetBuilder;
-    protected Collection<WorkspaceInfo> workspaces;
+    protected final Set<WorkspaceInfo> workspaces = 
+      new LinkedHashSet<WorkspaceInfo>();
 
-    protected WorkspaceManager getWorkspaceManager(RequestContext request) {
+    protected WorkspaceManager getWorkspaceManager() {
       return this;
     }
 
@@ -61,10 +64,12 @@ public abstract class AbstractWorkspaceP
         return workspaces;
     }
 
-    public void addWorkspace(WorkspaceInfo workspace) {
-        if (workspaces == null) {
-            workspaces = new HashSet<WorkspaceInfo>();
-        }
+    public synchronized void setWorkspaces(Collection<WorkspaceInfo> workspaces) {
+      workspaces.clear();
+      workspaces.addAll(workspaces);
+    }
+    
+    public synchronized void addWorkspace(WorkspaceInfo workspace) {
         workspaces.add(workspace);
     }
 
@@ -74,7 +79,7 @@ public abstract class AbstractWorkspaceP
     }
     
     // JIRA: https://issues.apache.org/jira/browse/ABDERA-255
-    public Date getLastModified() {
-      return new Date();
+    public DateTime getLastModified() {
+      return DateTimes.utcNow();
     }
 }



Mime
View raw message