abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1200583 [5/5] - in /abdera/abdera2: activities/src/main/java/org/apache/abdera2/activities/client/ activities/src/main/java/org/apache/abdera2/activities/extra/ activities/src/main/java/org/apache/abdera2/activities/io/gson/ activities/src...
Date Thu, 10 Nov 2011 21:48:48 GMT
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/VideoObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/VideoObject.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/VideoObject.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/VideoObject.java Thu Nov 10 21:48:45 2011
@@ -17,58 +17,71 @@
  */
 package org.apache.abdera2.activities.model.objects;
 
+import java.util.Map;
+
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.activities.model.MediaLink;
 import org.apache.abdera2.common.anno.Name;
-@Name("video")
+
 public class VideoObject 
   extends ASObject {
-
-  private static final long serialVersionUID = 5394642824444623984L;
+ 
   public static final String EMBEDCODE = "embedCode";
   public static final String STREAM = "stream";
-  
-  public VideoObject() {}
-  
-  public VideoObject(String displayName) {
-    setDisplayName(displayName);
+
+  public static VideoBuilder makeVideo() {
+    return new VideoBuilder("video");
   }
   
-  public String getEmbedCode() {
-    return getProperty(EMBEDCODE);
+  @Name("video")
+  public static final class VideoBuilder extends Builder<VideoObject,VideoBuilder> {
+    public VideoBuilder() {
+      super(VideoObject.class,VideoBuilder.class);
+    }
+    public VideoBuilder(Map<String, Object> map) {
+      super(map, VideoObject.class,VideoBuilder.class);
+    }
+    public VideoBuilder(String objectType) {
+      super(objectType,VideoObject.class,VideoBuilder.class);
+    }
   }
   
-  public void setEmbedCode(String embedCode) {
-    setProperty(EMBEDCODE, embedCode);
+  @SuppressWarnings("unchecked")
+  public static abstract class Builder<X extends VideoObject,M extends Builder<X,M>>
+    extends ASObject.Builder<X,M> {
+    protected Builder(Class<X> _class,Class<M> _builder) { 
+      super(_class,_builder);
+    }
+    protected Builder(String objectType,Class<X> _class,Class<M> _builder) {
+      super(objectType,_class,_builder);
+    }
+    protected Builder(Map<String,Object> map,Class<X> _class,Class<M> _builder) {
+      super(map,_class,_builder);
+    }
+    public M embedCode(String code) {
+      set(EMBEDCODE,code);
+      return (M)this;
+    }
+    public M stream(MediaLink stream) {
+      set(STREAM,stream);
+      return (M)this;
+    }
   }
   
-  public MediaLink getStream() {
-    return getProperty(STREAM);
+  public VideoObject(Map<String,Object> map) {
+    super(map,VideoBuilder.class,VideoObject.class);
   }
   
-  public void setStream(MediaLink stream) {
-    setProperty(STREAM, stream);
+  public <X extends VideoObject, M extends Builder<X,M>>VideoObject(Map<String,Object> map, Class<M> _class, Class<X>_obj) {
+    super(map,_class,_obj);
   }
   
-  public static <T extends VideoObject>VideoObjectGenerator<T> makeVideo() {
-    return new VideoObjectGenerator<T>();
+  public String getEmbedCode() {
+    return getProperty(EMBEDCODE);
   }
   
-  @SuppressWarnings("unchecked")
-  public static class VideoObjectGenerator<T extends VideoObject> extends ASObjectGenerator<T> {
-    public VideoObjectGenerator() {
-      super((Class<? extends T>) VideoObject.class);
-    }
-    public VideoObjectGenerator(Class<T> _class) {
-      super(_class);
-    }
-    public <X extends VideoObjectGenerator<T>>X embedCode(String code) {
-      item.setEmbedCode(code);
-      return (X)this;
-    }
-    public <X extends VideoObjectGenerator<T>>X stream(MediaLink stream) {
-      item.setStream(stream);
-      return (X)this;
-    }
+  public MediaLink getStream() {
+    return getProperty(STREAM);
   }
+  
 }

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=1200583&r1=1200582&r2=1200583&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 Thu Nov 10 21:48:45 2011
@@ -23,6 +23,7 @@ import java.util.Arrays;
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.model.objects.PersonObject;
 import org.apache.abdera2.activities.model.objects.ServiceObject;
 import org.apache.abdera2.common.misc.ExceptionHelper;
@@ -51,32 +52,32 @@ public abstract class AbstractActivities
     return Arrays.asList("application/json");
   }
   
-  protected ResponseContext buildCreateEntryResponse(
+  protected <T extends ASBase>ResponseContext buildCreateEntryResponse(
     String link, 
-    ASBase base) {
+    ASBase.Builder<T,?> builder) {
     return
-      new ActivitiesResponseContext<ASBase>(base)
+      new ActivitiesResponseContext<T>(builder)
         .setLocation(link)
         .setContentLocation(link)
-        .setEntityTag(calculateEntityTag(base))
+        .setEntityTag(calculateEntityTag(builder.get()))
         .setStatus(201);
   }
 
-  protected ResponseContext buildGetEntryResponse(
+  protected <T extends ASObject>ResponseContext buildGetEntryResponse(
     RequestContext request, 
-    ASObject base)
+    ASObject.Builder<T,?> builder)
       throws ResponseContextException {
-      base.setSource(createSourceObject(request));
+      builder.source(createSourceObject(request));
       return 
-        new ActivitiesResponseContext<ASObject>(base)
-         .setEntityTag(calculateEntityTag(base));
+        new ActivitiesResponseContext<T>(builder)
+         .setEntityTag(calculateEntityTag(builder.get()));
   }
 
-  protected ResponseContext buildGetFeedResponse(
-    Collection<ASObject> collection) {
+  protected <T extends ASObject>ResponseContext buildGetFeedResponse(
+    CollectionBuilder<T> builder) {
       return 
-        new ActivitiesResponseContext<Collection<ASObject>>(collection)
-          .setEntityTag(calculateEntityTag(collection));
+        new ActivitiesResponseContext<Collection<T>>(builder)
+          .setEntityTag(calculateEntityTag(builder.get()));
   }
 
   protected ServiceObject createSourceObject(

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=1200583&r1=1200582&r2=1200583&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 Thu Nov 10 21:48:45 2011
@@ -25,11 +25,13 @@ import java.util.Set;
 import javax.activation.MimeType;
 
 import org.apache.abdera2.activities.model.ASBase;
+import org.apache.abdera2.activities.model.ASDocument;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.activities.model.Activity;
 import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.activities.model.IO;
 import org.apache.abdera2.activities.model.TypeAdapter;
+import org.apache.abdera2.activities.model.objects.ErrorObject;
 import org.apache.abdera2.common.date.DateTimes;
 import org.apache.abdera2.common.http.EntityTag;
 import org.apache.abdera2.common.misc.ExceptionHelper;
@@ -87,8 +89,7 @@ public abstract class AbstractActivities
             ErrorObject
             .makeError()
             .code(code)
-            .displayName(message)
-            .get())
+            .displayName(message))
         .setStatus(code)
         .setStatusText(message);
   }
@@ -154,28 +155,29 @@ public abstract class AbstractActivities
       } catch (Throwable t) {
         throw ExceptionHelper.propogate(t);
       }
-    if (entity != null) {
-      setDocProperties(entity, context);
-      context.setAttribute(ASBase.class.getName(), entity);
-    }
+    if (entity != null)
+      context.setAttribute(ASBase.class.getName(), getDoc(entity,context));
     return (T)entity;
   }
   
-  private static void setDocProperties(ASBase base, RequestContext context) {
+  private static <T extends ASBase>ASDocument<T> getDoc(T base, RequestContext context) {
+    ASDocument.Builder<T> builder = 
+      ASDocument.make(base);
     String etag = context.getHeader("ETag");
     if (etag != null)
-        base.setEntityTag(etag);
+        builder.entityTag(etag);
     DateTime lm = context.getDateHeader("Last-Modified");
     if (lm != null)
-        base.setLastModified(lm);
+        builder.lastModified(lm);
     MimeType mt = context.getContentType();
     if (mt != null)
-        base.setContentType(mt.toString());
+        builder.contentType(mt.toString());
     String language = context.getContentLanguage();
     if (language != null)
-        base.setLanguage(language);
+        builder.language(language);
     String slug = context.getSlug();
     if (slug != null)
-        base.setSlug(slug);
+        builder.slug(slug);
+    return builder.get();
   }
 }

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=1200583&r1=1200582&r2=1200583&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 Thu Nov 10 21:48:45 2011
@@ -23,6 +23,7 @@ import java.util.Set;
 import javax.activation.MimeType;
 
 import org.apache.abdera2.activities.model.TypeAdapter;
+import org.apache.abdera2.activities.model.objects.ErrorObject;
 import org.apache.abdera2.common.mediatype.MimeTypeHelper;
 import org.apache.abdera2.common.protocol.AbstractWorkspaceProvider;
 import org.apache.abdera2.common.protocol.CollectionRequestProcessor;
@@ -87,8 +88,7 @@ public abstract class AbstractActivities
           ErrorObject
             .makeError()
             .code(code)
-            .displayName(message)
-            .get())
+            .displayName(message))
         .setStatus(code)
         .setStatusText(message);
   }

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ActivitiesResponseContext.java Thu Nov 10 21:48:45 2011
@@ -34,17 +34,15 @@ public class ActivitiesResponseContext<T
   
   private final static Log log = LogFactory.getLog(ActivitiesResponseContext.class);
   
-  private final T base;
+  private final ASBase.Builder<T,?> builder;
   private final boolean chunked;
   
-  public ActivitiesResponseContext(T base) {
-    this(base, true);
+  public ActivitiesResponseContext(ASBase.Builder<T,?> builder) {
+    this(builder, true);
   }
   
-  public ActivitiesResponseContext(T base, boolean chunked) {
-    log.debug(String.format("Entity: %s", base.toString()));
-    log.debug(String.format("Chunked? %s", chunked));
-    this.base = base;
+  public ActivitiesResponseContext(ASBase.Builder<T,?> builder, boolean chunked) {
+    this.builder = builder;
     setStatus(200);
     setStatusText("OK");
     this.chunked = chunked;
@@ -59,24 +57,29 @@ public class ActivitiesResponseContext<T
     log.debug(String.format("Content-Type: %s", getContentType()));
   }
    
+  @SuppressWarnings("unchecked")
+  public <X extends ASBase.Builder<T,?>>X getBuilder() {
+    return (X)builder;
+  }
+  
   public T getEntity() {
-    return base;
+    return builder.get();
   }
 
   public boolean hasEntity() {
-    return (base != null);
+    return (builder != null);
   }
 
   public void writeTo(java.io.Writer javaWriter) throws IOException {
     log.debug("Writing...");
     if (hasEntity())
-      base.writeTo(javaWriter);
+      getEntity().writeTo(javaWriter);
   }
 
   public void writeTo(OutputStream out) throws IOException {
     log.debug("Writing...");
     if (hasEntity())
-      base.writeTo(out);
+      getEntity().writeTo(out);
   }
 
   public MimeType getContentType() {
@@ -88,7 +91,7 @@ public class ActivitiesResponseContext<T
     if (hasEntity() && len == -1 && !chunked) {
         try {
             ByteArrayOutputStream out = new ByteArrayOutputStream();
-            base.writeTo(out);
+            getEntity().writeTo(out);
             len = out.size();
             super.setContentLength(len);
         } catch (Exception e) {

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/protocol/ProtocolException.java Thu Nov 10 21:48:45 2011
@@ -17,6 +17,7 @@
  */
 package org.apache.abdera2.activities.protocol;
 
+import org.apache.abdera2.activities.model.objects.ErrorObject;
 import org.apache.abdera2.common.misc.MoreFunctions;
 
 public class ProtocolException extends RuntimeException {
@@ -31,9 +32,11 @@ public class ProtocolException extends R
 
     public ProtocolException(int code, String message) {
         super(String.format("%d::%s",code,message));
-        this.error = new ErrorObject();
-        error.setDisplayName(message);
-        error.setCode(code);
+        this.error = ErrorObject
+          .makeError()
+            .code(code)
+            .displayName(message)
+          .get();
     }
 
     public ErrorObject getError() {

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=1200583&r1=1200582&r2=1200583&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 Thu Nov 10 21:48:45 2011
@@ -17,7 +17,6 @@
  */
 package org.apache.abdera2.activities.protocol.basic;
 
-import java.util.LinkedHashSet;
 import java.util.UUID;
 import java.util.logging.Logger;
 
@@ -26,10 +25,10 @@ import javax.activation.MimeType;
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
+import org.apache.abdera2.activities.model.objects.ErrorObject;
 import org.apache.abdera2.activities.model.objects.PersonObject;
-import org.apache.abdera2.activities.protocol.AbstractActivitiesProvider;
 import org.apache.abdera2.activities.protocol.ActivitiesResponseContext;
-import org.apache.abdera2.activities.protocol.ErrorObject;
 import org.apache.abdera2.activities.protocol.managed.FeedConfiguration;
 import org.apache.abdera2.activities.protocol.managed.ManagedCollectionAdapter;
 import org.apache.abdera2.common.mediatype.MimeTypeHelper;
@@ -80,10 +79,10 @@ public abstract class BasicAdapter exten
         return (String)val;
     }
 
-    protected Collection<ASObject> createCollection() {
-      Collection<ASObject> col = 
+    protected <T extends ASObject>CollectionBuilder<T> createCollection() {
+      return
         Collection
-          .makeCollection()
+          .<T>makeCollection()
           .id(config.getFeedUri())
           .set("title", config.getFeedTitle())
           .set("updated", DateTime.now())
@@ -91,31 +90,27 @@ public abstract class BasicAdapter exten
             PersonObject
               .makePerson()
               .displayName(config.getFeedAuthor())
-              .get())
-          .get();
-      col.setItems(new LinkedHashSet<ASObject>());
-      return col;
+              .get());
     }
     
-    protected void addEditLinkToObject(ASObject object) throws Exception {
-      if (AbstractActivitiesProvider.getEditUriFromEntry(object) == null)
-        object.setProperty("editLink", object.getId());
+    protected <T extends ASObject>void addEditLinkToObject(
+      ASObject.Builder<T,?> builder, 
+      String id) throws Exception {
+        builder.set("editLink", id);
     }
 
-    protected void setObjectIdIfNull(ASObject object) throws Exception {
-      if (object.getId() != null)
-        return;
+    protected <T extends ASObject>void setObjectId(ASObject.Builder<T,?> builder) throws Exception {
       String uuidUri = UUID.randomUUID().toString();
       String[] segments = uuidUri.split(":");
       String entryId = segments[segments.length - 1];
-      object.setId(createEntryIdUri(entryId));
+      builder.id(createEntryIdUri(entryId));
     }
 
     protected String createEntryIdUri(String entryId) throws Exception {
         return config.getFeedUri() + "/" + entryId;
     }
 
-    private void push(RequestContext context, String channel, ASObject object) {
+    private <T extends ASObject>void push(RequestContext context, String channel, ASObject.Builder<T,?> builder) {
       if (context.getAttribute(Scope.CONTAINER, "AbderaChannelManager") != null) {
         ChannelManager cm = (ChannelManager) context.getAttribute(
           Scope.CONTAINER, "AbderaChannelManager");
@@ -123,12 +118,12 @@ public abstract class BasicAdapter exten
           Pusher<ASObject> pusher = 
             cm.getPusher(channel);
           if (pusher != null)
-            pusher.push(object);
+            pusher.push(builder.get());
         }
       }
     }
     
-    private ResponseContext createOrUpdateObject(RequestContext request, boolean createFlag) {
+    ResponseContext createOrUpdateObject(RequestContext request, boolean createFlag) {
       try {
         MimeType mimeType = request.getContentType();
         String contentType = mimeType == null ? null : mimeType.toString();
@@ -143,18 +138,20 @@ public abstract class BasicAdapter exten
             target.getType() == TargetType.TYPE_COLLECTION) {
             // only allow multiposts on collections.. these always create, never update
             Collection<ASObject> coll = (Collection<ASObject>) base;
-            Collection<ASObject> retl = new Collection<ASObject>();
+            CollectionBuilder<ASObject> retl = Collection.makeCollection();
             int c = 0;
             for (ASObject inputEntry : coll.getItems()) {
-              ASObject newEntry = createItem(inputEntry,c++);
+              ASObject.Builder<?,?> newEntry = createItem(inputEntry,c++);
               if (newEntry != null) {
                 push(request,target.getParameter(BasicProvider.PARAM_FEED),newEntry);
-                retl.addItem(newEntry);
+                retl.item(newEntry.get());
               } else {
-                ErrorObject err = new ErrorObject();
-                err.setCode(-100);
-                err.setDisplayName("Error adding object");
-                retl.addItem(err);
+                retl.item(
+                  ErrorObject
+                    .makeError()
+                      .code(-100)
+                      .displayName("Error adding object")
+                    .get());
               }
             }
             return
@@ -165,12 +162,12 @@ public abstract class BasicAdapter exten
             target.getParameter(BasicProvider.PARAM_ENTRY) : 
               null;
           ASObject inputEntry = (ASObject) base;
-          ASObject newEntry = createFlag ? 
+          ASObject.Builder<ASObject,?> newEntry = createFlag ? 
             createItem(inputEntry) : 
             updateItem(entryId, inputEntry);
           if (newEntry != null) {
             push(request,target.getParameter(BasicProvider.PARAM_FEED),newEntry);
-            String loc = newEntry.getProperty("editLink");
+            String loc = newEntry.get().getProperty("editLink");
             return 
               new ActivitiesResponseContext<ASObject>(newEntry)
                 .setStatus(createFlag?201:200)
@@ -223,7 +220,7 @@ public abstract class BasicAdapter exten
           Target target = input.getTarget();
           String entryId = target.getParameter(BasicProvider.PARAM_ENTRY);
           try {
-              ASObject object = getItem(entryId);
+              ASObject.Builder<ASObject,?> object = getItem(entryId);
               if (object != null) {
                 return 
                   new ActivitiesResponseContext<ASObject>(object)
@@ -240,9 +237,8 @@ public abstract class BasicAdapter exten
       return new Function<RequestContext,ResponseContext>() {
         public ResponseContext apply(RequestContext input) {
           try {
-            Collection<ASObject> collection = 
+            CollectionBuilder<ASObject> collection = 
               getCollection();
-
             if (collection != null) { 
               return 
                 new ActivitiesResponseContext<Collection<ASObject>>(collection)
@@ -255,15 +251,15 @@ public abstract class BasicAdapter exten
       };
     }
 
-    public abstract Collection<ASObject> getCollection() throws Exception;
+    public abstract <T extends ASObject>CollectionBuilder<T> getCollection() throws Exception;
 
-    public abstract ASObject getItem(Object objectId) throws Exception;
+    public abstract <T extends ASObject>ASObject.Builder<T,?> getItem(Object objectId) throws Exception;
 
-    public abstract ASObject createItem(ASObject object) throws Exception;
+    public abstract <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object) throws Exception;
 
-    public abstract ASObject createItem(ASObject object, int c) throws Exception;
+    public abstract <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object, int c) throws Exception;
     
-    public abstract ASObject updateItem(Object objectId, ASObject object) throws Exception;
+    public abstract <T extends ASObject>ASObject.Builder<T,?> updateItem(Object objectId, ASObject object) throws Exception;
 
     public abstract boolean deleteItem(Object objectId) throws Exception;
 

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=1200583&r1=1200582&r2=1200583&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 Thu Nov 10 21:48:45 2011
@@ -18,7 +18,6 @@
 package org.apache.abdera2.activities.protocol.managed;
 
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -26,6 +25,7 @@ import org.apache.abdera2.common.protoco
 import org.apache.abdera2.common.protocol.RequestContext;
 
 import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableMap;
 
 public class FeedConfiguration extends Configuration implements CollectionInfo {
     public static final String PROP_NAME_ADAPTER_CLASS = "adapterClassName";
@@ -45,16 +45,16 @@ public class FeedConfiguration extends C
 
     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;      
+      String feedId;
+      String subUri;
+      String adapterClassName;
+      String feedConfigLocation;
+      ServerConfiguration serverConfiguration;
+      String feedTitle = "unknown";
+      String feedAuthor = "unknown";
+      final ImmutableMap.Builder<Object,Object> optionalProperties =
+        ImmutableMap.builder();
+      CollectionAdapterConfiguration adapterConfiguration;      
       
       public Generator id(String id) {
         this.feedId = id;
@@ -123,8 +123,7 @@ public class FeedConfiguration extends C
     private final ServerConfiguration serverConfiguration;
     private final String feedTitle;
     private final String feedAuthor;
-    private final Map<Object, Object> optionalProperties = 
-      new HashMap<Object,Object>();
+    private final ImmutableMap<Object, Object> optionalProperties;
     private final CollectionAdapterConfiguration adapterConfiguration;
 
     protected FeedConfiguration(Generator gen) {
@@ -135,7 +134,7 @@ public class FeedConfiguration extends C
       this.serverConfiguration = gen.serverConfiguration;
       this.feedTitle = gen.feedTitle;
       this.feedAuthor = gen.feedAuthor;
-      this.optionalProperties.putAll(gen.optionalProperties);
+      this.optionalProperties = gen.optionalProperties.build();
       this.adapterConfiguration = gen.adapterConfiguration;
     }
 
@@ -210,7 +209,7 @@ public class FeedConfiguration extends C
         String[] arr = null;
         if (accepts == null || !(accepts instanceof String))
             arr = new String[] {"application/json"};
-        arr = ((String)accepts).split("\\s*,\\s*");
+        else arr = ((String)accepts).split("\\s*,\\s*");
         return Arrays.<String>asList(arr);
     }
 

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java Thu Nov 10 21:48:45 2011
@@ -31,6 +31,10 @@ public final class IsoPosition 
     return new IsoPosition(coordinate.getLatitude(),coordinate.getLongitude());
   }
   
+  public static IsoPosition at(double latitude, double longitude) {
+    return new IsoPosition(latitude,longitude);
+  }
+  
   public static IsoPosition at(Point point) {
     return new IsoPosition(
       point.getCoordinate().getLatitude(),

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java (original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/misc/MoreFunctions.java Thu Nov 10 21:48:45 2011
@@ -1,5 +1,6 @@
 package org.apache.abdera2.common.misc;
 
+import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.LinkedHashSet;
@@ -111,7 +112,9 @@ public class MoreFunctions {
       public T apply(Object[] input) {
         try {
           if (input != null) {
-            return _class.getConstructor(args).newInstance(input);
+            Constructor<T> c = _class.getConstructor(args);
+            c.setAccessible(true);
+            return c.newInstance(input);
           } else {
             return _class.newInstance();
           }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/Activities.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/Activities.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/Activities.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/Activities.java Thu Nov 10 21:48:45 2011
@@ -26,6 +26,9 @@ public class Activities {
     // coming from.
     //
     // this activity basically says: "James is following John"
+    //
+    // All Activity objects are immutable and thread-safe
+    // once created
     Activity activity = 
       makeActivity()
         .actor(

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtendingBaseObjectExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtendingBaseObjectExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtendingBaseObjectExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtendingBaseObjectExample.java Thu Nov 10 21:48:45 2011
@@ -1,8 +1,10 @@
 package org.apache.abdera2.examples.activities;
 
+import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.activities.model.IO;
 import org.apache.abdera2.activities.model.objects.EventObject;
 import org.apache.abdera2.activities.model.objects.AdditionalEventProperties;
+import org.apache.abdera2.activities.model.objects.EventObject.EventBuilder;
 import org.apache.abdera2.activities.model.objects.PersonObject;
 
 /**
@@ -16,17 +18,23 @@ public class ExtendingBaseObjectExample 
 
   public static void main(String... args) throws Exception {
     IO io = IO.get();
-    EventObject event = new EventObject();
-    event.setObjectType("hangout");
+    EventBuilder builder = 
+      EventObject.makeEvent("hangout");
     // the extend method dynamically attaches a new interface
     // to the object that can be used to specify extension
     // properties in a typesafe manner
-    AdditionalEventProperties ext = 
-      event.extend(
-        AdditionalEventProperties.class);
-    ext.setHost(new PersonObject("james"));
-    event.getAttending(true).addItem(new PersonObject("joe"));
-    io.write(event,System.out,"UTF-8");
+    builder.extend(
+      AdditionalEventProperties.Builder.class)
+       .host(PersonObject.makePerson().displayName("James").get());
+    builder.attending(
+      Collection.makeCollection()
+        .item(
+           PersonObject
+             .makePerson()
+               .displayName("Joe")
+                 .get())
+                   .get());
+    io.write(builder.get(),System.out,"UTF-8");
   }
   
 }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtensionExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtensionExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtensionExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtensionExample.java Thu Nov 10 21:48:45 2011
@@ -16,14 +16,14 @@ public class ExtensionExample {
   public static void main(String... args) throws Exception {
     
     // create the io with our custom type adapter
-    IO io = IO.get(new BarAdapter());
-    
-    // tell the serializer how to handle specific property names
-    io.addPropertyMapping("bar", Bar.class);
-    io.addPropertyMapping("etag", EntityTag.class);
+    IO io = IO.make()
+      .adapter(new BarAdapter())
+      .property("bar", Bar.class)
+      .property("etag", EntityTag.class)
+      .get();
     
     // create a new object with "objectType":"foo"
-    ASObject as = new ASObject("foo");
+    ASObject.Builder<ASObject,?> as = ASObject.makeObject("foo");
     
     // attach the Foo.class interface to the object to set
     // extension properties
@@ -34,18 +34,19 @@ public class ExtensionExample {
     Map<Bar,String> map = new HashMap<Bar,String>();
     map.put(new Bar("z"),"a");
     map.put(new Bar("y"), "b");
-    as.setProperty("map",map);
+    as.set("map",map);
     
     // outputs: foo
-    System.out.println(as.getObjectType());
+    ASObject obj = as.get();
+    System.out.println(obj.getObjectType());
     
     // outputs: {"etag":"W/\"test\"","map":{"y":"b","z":"a"},"bar":"foobarbaz","objectType":"foo"}
-    as.writeTo(io,System.out);
+    obj.writeTo(io,System.out);
     
     // now try reading it
-    StringReader sr = new StringReader(io.write(as));
-    as = io.readObject(sr);
-    foo = as.extend(Foo.class);
+    StringReader sr = new StringReader(io.write(obj));
+    obj = io.readObject(sr);
+    foo = obj.extend(Foo.class);
 
     System.out.println();
     
@@ -55,7 +56,7 @@ public class ExtensionExample {
     System.out.println(foo.getBar().getClass());
     
     // map will deserialize as an asobject...
-    System.out.println(as.getProperty("map").getClass());
+    System.out.println(obj.getProperty("map").getClass());
     
   }
   

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GeneratorStreamingExample.java Thu Nov 10 21:48:45 2011
@@ -5,9 +5,9 @@ import java.io.ByteArrayOutputStream;
 
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
 import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.activities.model.CollectionWriter;
-import org.apache.abdera2.activities.model.Generator;
 import org.apache.abdera2.activities.model.IO;
 import org.apache.abdera2.activities.model.Verb;
 
@@ -33,13 +33,14 @@ public class GeneratorStreamingExample {
       io.getCollectionWriter(out, "UTF-8");
     
     // Output the collection header
-    ASBase header = new ASBase();
-    header.setProperty("title", "My Items");
-    header.setProperty("totalItems", 10);
-    writer.writeHeader(header);
+    writer.writeHeader(
+      ASBase.make()
+        .set("title", "My Items")
+        .set("totalItems", 10)
+        .get());
     
     // Prepare the Activity template
-    Generator<Activity> gen = 
+    ActivityBuilder gen = 
       makeActivity()
       .actor(makePerson().get())
       .verb(Verb.POST)
@@ -47,9 +48,7 @@ public class GeneratorStreamingExample {
         makeService()
           .displayName("My Application")
           .get())
-      .displayName("joe")
-      .get()
-      .newGenerator();
+      .displayName("joe");
     
     // we can now use the Generator to produce 
     // new Activities using the one we just 
@@ -64,9 +63,9 @@ public class GeneratorStreamingExample {
     // modified list
     for (int n = 0; n < 10; n++)
       writer.writeObject(  // write out each object as we create it
-        gen.startNew()
+        gen.template()
           .set("title", "A" + n)
-          .complete());
+          .get());
     
     // complete the writer.. very important.. always do this
     // or the json generated by the writer will be malformed

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GooglePlusExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GooglePlusExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GooglePlusExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/GooglePlusExample.java Thu Nov 10 21:48:45 2011
@@ -5,6 +5,7 @@ import org.apache.abdera2.common.anno.Pa
 import org.apache.abdera2.common.anno.URITemplate;
 
 import org.apache.abdera2.activities.client.ActivitiesClient;
+import org.apache.abdera2.activities.model.ASDocument;
 import org.apache.abdera2.activities.model.Activity;
 import org.apache.abdera2.activities.model.Collection;
 import static org.apache.abdera2.common.templates.Template.expandAnnotated;
@@ -24,10 +25,11 @@ public class GooglePlusExample   {
     ActivitiesClient cl = 
       new ActivitiesClient();
     try {
-      Collection<Activity> c = 
+      ASDocument<Collection<Activity>> doc = 
         cl.getCollection(
           expandAnnotated(
             new GooglePlusExample()));
+      Collection<Activity> c = doc.getRoot();
       out.println(c.getProperty("title"));
       int n = 1;
       for (Activity a : c.getItems())

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MiscellaneousExamples.java Thu Nov 10 21:48:45 2011
@@ -3,6 +3,7 @@ package org.apache.abdera2.examples.acti
 import org.apache.abdera2.activities.extra.ASContext;
 import org.apache.abdera2.activities.extra.Extra;
 import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
 import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.common.templates.Template;
 
@@ -36,18 +37,41 @@ public class MiscellaneousExamples {
     // do not know about each other directly, we can related the two
     // and detect that they are likely duplicates of one another
     
-    Activity a1 = new Activity();
-    a1.setId("foo");
-    a1.addDownstreamDuplicate("baz");
-    
-    Activity a2 = new Activity();
-    a2.setId("bar");
-    a2.addUpstreamDuplicate("baz");
+    Activity a1 = 
+      Activity.makeActivity()
+        .id("foo")
+        .downstreamDuplicate("baz")
+        .get();
+    
+    Activity a2 = 
+      Activity.makeActivity()
+       .id("bar")
+       .upstreamDuplicate("baz")
+       .get();
     
     System.out.println(Extra.IDENTITY_EQUIVALENCE.equivalent(a1, a2)); // false
     System.out.println(Extra.IDENTITY_WITH_DUPLICATES_EQUIVALENCE.equivalent(a1, a2)); // true
     
     
+    // All of the Activity objects are immutable thread-safe instances,
+    // which means editing the data in an object is a bit more difficult 
+    // that just calling a setter...
+    // support we want to add a property to one of the activities
+    // we created above... we can do so by using the activity as a template
+    // for creating a new Activity object
+    
+    Activity a3 = a1.<Activity,ActivityBuilder>template().set("foo", "bar").get();
+    a3.writeTo(System.out);
+    
+    // it's also possible to merge two objects into a forth of the 
+    // same or different type... when merging, properties contained
+    // in the passed in object will replace those contained in the 
+    // original source object. The merge is not deep...
+    
+    Activity a4 = a1.as(Activity.class, a3);
+    a4.writeTo(System.out);
+    
+    
     
     // Working with URI Templates.. the ASContext class
     // provides a URI Template Context implementation
@@ -62,8 +86,9 @@ public class MiscellaneousExamples {
     // the url for the next page.
     
     Collection<Activity> collection = 
-      new Collection<Activity>();
-    collection.setProperty("nextPageToken", "foo");
+      Collection.<Activity>makeCollection()
+        .set("nextPageToken", "foo")
+        .get();
     
     Template template = 
       new Template("http://example.org/stuff{?nextPageToken}");

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MyActivitiesAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MyActivitiesAdapter.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MyActivitiesAdapter.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/MyActivitiesAdapter.java Thu Nov 10 21:48:45 2011
@@ -21,13 +21,15 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Logger;
 
+import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
-import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.protocol.basic.BasicAdapter;
 import org.apache.abdera2.activities.protocol.managed.FeedConfiguration;
 import org.apache.abdera2.common.protocol.RequestContext;
 import org.apache.abdera2.common.protocol.ResponseContextException;
 
+
 public class MyActivitiesAdapter extends BasicAdapter {
 
     private static final String ERROR_INVALID_ENTRY = "No Such Entry in the Feed";
@@ -58,57 +60,58 @@ public class MyActivitiesAdapter extends
     }
 
     @Override
-    public Collection<ASObject> getCollection() throws Exception {
-        Collection<ASObject> col = createCollection();
-        
+    public CollectionBuilder<ASObject> getCollection() throws Exception {
+        CollectionBuilder<ASObject> col = createCollection();
         for (Item item : entries)
-          col.addItem(item.getValue());
+          col.item(item.getValue());
         return col;
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject getItem(Object entryId) throws Exception {
+    public ASObject.Builder<ASObject,?> getItem(Object entryId) throws Exception {
       ASObject ret = null;
       for (Item item : entries)
         if (item.getKey().equals(entryId.toString())) {
           ret = item.getValue();
           break;
         }
-      return ret;
+      if (ret == null) return null;
+      return ret.<ASObject,ASObject.Builder>template();
     }
 
     @Override
-    public ASObject createItem(ASObject object) throws Exception {
+    public <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object) throws Exception {
         return createItem(object,-1);
     }
     
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject createItem(ASObject object, int c) throws Exception {
-        setObjectIdIfNull(object);
-        logger.info("assigning id to Object: " + object.getId().toString());
-        String entryId = getObjectIdFromUri(object.getId().toString());
-        if (c != -1) entryId += c;
-        if (object.getUpdated() == null) {
-            object.setUpdatedNow();
-        }
-        addEditLinkToObject(object);
-        storeObject(entryId, object);
-        logger.finest("returning this object from sampleadapter.createItem: " + object.toString());
-        return object;
+    public <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object, int c) throws Exception {
+      ASObject.Builder<T, ?> builder = object.<ASObject,ASObject.Builder>template(ASBase.withoutFields("editLink","updated"));
+      if (!object.has("id"))
+        setObjectId(builder);
+      logger.info("assigning id to Object: " + object.getId().toString());
+      String entryId = getObjectIdFromUri(object.getId().toString());
+      if (c != -1) entryId += c;
+      builder.updatedNow();
+      addEditLinkToObject(builder,object.getId());
+      storeObject(entryId, object);
+      logger.finest("returning this object from sampleadapter.createItem: " + object.toString());
+      return builder;
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject updateItem(Object entryId, ASObject object) throws Exception {
+    public <T extends ASObject>ASObject.Builder<T,?> updateItem(Object entryId, ASObject object) throws Exception {
         if (!deleteItem(entryId))
             throw new Exception(ERROR_INVALID_ENTRY);
-        
-        if (object.getUpdated() == null) {
-            object.setUpdatedNow();
-        }
-        addEditLinkToObject(object);
-        storeObject((String)entryId, object);
+        ASObject.Builder<T, ?> builder = object.<ASObject,ASObject.Builder>template(ASBase.withoutFields("editLink","updated"));
+        builder.updatedNow();
+        addEditLinkToObject(builder,object.getId());
+        storeObject((String)entryId, builder.get());
         logger.finest("returning this entry from sampleadapter.updateEntry: " + object.toString());
-        return object;
+        return builder;
     }
 
     @Override

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/PusherExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/PusherExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/PusherExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/PusherExample.java Thu Nov 10 21:48:45 2011
@@ -10,7 +10,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadPoolExecutor;
 
 import org.apache.abdera2.activities.model.Activity;
-import org.apache.abdera2.activities.model.Generator;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
 import org.apache.abdera2.activities.model.Verb;
 import org.apache.abdera2.common.pusher.ChannelManager;
 import org.apache.abdera2.common.pusher.Pusher;
@@ -20,12 +20,10 @@ import org.apache.abdera2.common.pusher.
 
 public class PusherExample {
 
-  private static final Generator<Activity> gen = 
+  private static final ActivityBuilder gen = 
     makeActivity()
     .actor(makePerson().displayName("joe").get())
-    .verb(Verb.POST)
-    .get()
-    .newGenerator();
+    .verb(Verb.POST);
   
   public static void main(String... args) throws Exception {
     
@@ -51,12 +49,12 @@ public class PusherExample {
     Pusher<Activity> pusher = cm.getPusher("foo");
     for (int n = 0; n < 3; n++) 
       pusher.push(
-        gen.startNew()
+        gen.template()
           .set("object",
             makeNote()
               .displayName(format("My note #%d",n+1))
               .get())
-          .complete()
+          .get()
         );
     
     latch.await();

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ReadingListExample.java Thu Nov 10 21:48:45 2011
@@ -1,8 +1,8 @@
 package org.apache.abdera2.examples.activities;
 
 import org.apache.abdera2.activities.model.Activity;
-import org.apache.abdera2.activities.model.Collection;
-import org.apache.abdera2.activities.model.Generator;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.model.IO;
 
 import static org.apache.abdera2.activities.model.Verb.SAVE;
@@ -28,31 +28,30 @@ public class ReadingListExample {
     // Building an activity stream for a reading list
     IO io = IO.get();
     
-    Generator<Activity> gen = 
+    ActivityBuilder gen = 
       makeActivity()
         .actor(
           makePerson()
             .displayName("James")
-            .get())
-        .get().newGenerator();
+            .get());
 
-    Collection.CollectionGenerator<Activity> builder = 
+    CollectionBuilder<Activity> builder = 
       makeCollection();
     
     // Add a book we want to read
     builder.item(
-      gen.startNew()
+      gen.template()
          .set("verb", SAVE)
          .set("object", 
            makeBook()
              .displayName("The Cat in the Hat")
              .get())
          .set("format", EBOOK())
-         .complete());
+         .get());
     
     // Add a book we just finished
     builder.item(
-      gen.startNew()
+      gen.template()
          .set("verb", CONSUME)
          .set("object", 
            makeBook()
@@ -63,7 +62,7 @@ public class ReadingListExample {
                  .get())
              .get())
          .set("format", HARDCOVER())
-         .complete());
+         .get());
     
     builder.get().writeTo(io,System.out);
     

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/RepliesAndTargetingExample.java Thu Nov 10 21:48:45 2011
@@ -1,8 +1,8 @@
 package org.apache.abdera2.examples.activities;
 
 import org.apache.abdera2.activities.model.Activity;
-import org.apache.abdera2.activities.model.objects.NoteObject;
-import org.apache.abdera2.activities.model.objects.PersonObject;
+import static org.apache.abdera2.activities.model.objects.NoteObject.makeNote;
+import static org.apache.abdera2.activities.model.objects.PersonObject.makePerson;
 import static org.apache.abdera2.activities.model.objects.Objects.FRIENDS;
 import static org.apache.abdera2.activities.model.objects.Objects.NETWORK;
 
@@ -12,13 +12,12 @@ public class RepliesAndTargetingExample 
     
     Activity activity = 
       Activity.makeActivity()
-        .to(new PersonObject("bob"))
-        .cc(FRIENDS("Colleagues"))
-        .bto(new PersonObject("sally"))
-        .bcc(NETWORK())
+        .to(makePerson().displayName("bob").get())
+        .cc(FRIENDS("Colleagues").get())
+        .bto(makePerson().displayName("sally").get())
+        .bcc(NETWORK)
         .inReplyTo(
-          NoteObject
-            .makeNote()
+          makeNote()
             .id("urn:foo:note:1")
           .get())
         .get();

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/VersionControlExample.java Thu Nov 10 21:48:45 2011
@@ -1,8 +1,8 @@
 package org.apache.abdera2.examples.activities;
 
 import org.apache.abdera2.activities.model.Activity;
-import org.apache.abdera2.activities.model.Collection;
-import org.apache.abdera2.activities.model.Generator;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.model.objects.FileObject;
 import org.apache.abdera2.activities.model.objects.VersionObject;
 
@@ -19,16 +19,21 @@ public class VersionControlExample {
 
   public static void main(String... args) throws Exception {
         
-    Generator<Activity> gen = 
+    ActivityBuilder me = 
       makeActivity()
       .actor(
         makePerson()
           .displayName("James")
-          .get())
-      .get()
-      .newGenerator();
+          .get());
     
-    Collection.CollectionGenerator<Activity> builder = 
+    ActivityBuilder boss = 
+      makeActivity()
+      .actor(
+        makePerson()
+          .displayName("The Boss")
+          .get());
+    
+    CollectionBuilder<Activity> builder = 
       makeCollection();
     
     // first, indicate that we created a document
@@ -39,54 +44,52 @@ public class VersionControlExample {
         .get();
     
     builder.item(
-      gen.startNew()
+      me.template()
         .set("object", file)
         .set("verb", POST)
-        .complete());
+        .get());
     
     // second, indicate that a new version was created
     VersionObject version = 
       makeVersion()
         .of(file)
-        .major("2")
+        .major(2)
         .get();
     
     builder.item(
-      gen.startNew() 
+      me.template() 
          .set("object", version)
          .set("verb", POST)
-         .complete());
+         .get());
     
     // whoops, the boss rejected the new version
     builder.item(
-      gen.startNew()
+      boss.template()
          .set("object", version)
          .set("verb", REJECT)
-         .set("actor", makePerson().displayName("The Boss").get())
          .set("summary", "This version is missing something")
-         .complete());
+         .get());
     
     // create a new version to deal with the bosses concerns
     VersionObject old = version;
     version = makeVersion()
       .of(file)
-      .major("3")
+      .major(3)
       .previous(old)
       .get();
     
     builder.item(
-        gen.startNew() 
-           .set("object", version)
-           .set("verb", POST)
-           .complete());
+      me.template() 
+         .set("object", version)
+         .set("verb", POST)
+         .get());
     
     // the boss approves the new version
     builder.item(
-      gen.startNew()
-         .set("object", version)
-         .set("verb", APPROVE)
-         .set("actor", makePerson().displayName("The Boss").get())
-         .complete());
+      boss.template()
+       .set("object", version)
+       .set("verb", APPROVE)
+       .get());
     
     builder.get().writeTo(System.out);
   }

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java (original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/JwtExample.java Thu Nov 10 21:48:45 2011
@@ -22,8 +22,11 @@ public class JwtExample {
     
     KeyPair pair = KeyHelper.generateKeyPair("RSA", 1024);
 
-    Activity activity = new Activity();
-    activity.setVerb(Verb.POST);
+    Activity activity = 
+      Activity
+        .makeActivity()
+          .verb(Verb.POST)
+            .get();
 
     String jwt = Jwt.generate(pair.getPrivate(), activity);
     

Modified: abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java (original)
+++ abdera/abdera2/ext/src/main/java/org/apache/abdera2/ext/activities/FeedToActivityConverter.java Thu Nov 10 21:48:45 2011
@@ -1,15 +1,16 @@
 package org.apache.abdera2.ext.activities;
 
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import javax.xml.namespace.QName;
 
 import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
+import org.apache.abdera2.activities.model.ASObject.ASObjectBuilder;
 import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
 import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.model.CollectionWriter;
 import org.apache.abdera2.activities.model.MediaLink;
 import org.apache.abdera2.activities.model.Verb;
@@ -72,24 +73,24 @@ public class FeedToActivityConverter {
   }
 
   protected ASBase header(Feed feed) {
-    Collection<Activity> col = 
-      new Collection<Activity>();
-    col.setId(feed.getId().toString());
-    col.setAuthor(authors(feed.getAuthors()));
-    col.setProperty("contributors", authors(feed.getContributors()));
-    categories(feed.getCategories(), col);
-    col.setProperty("generator", generator(feed.getGenerator()));
-    col.setImage(image(feed.getIcon()));
-    col.setUrl(feed.getAlternateLinkResolvedHref());
-    col.setDisplayName(feed.getTitle());
-    col.setSummary(feed.getSubtitle());
-    col.setUpdated(feed.getUpdated());
-    col.setProperty("nextLink", FeedPagingHelper.getNext(feed));
-    col.setProperty("previousLink", FeedPagingHelper.getPrevious(feed));
-    col.setProperty("firstLink", FeedPagingHelper.getFirst(feed));
-    col.setProperty("lastLink", FeedPagingHelper.getLast(feed));
-    col.setProperty("selfLink", feed.getSelfLinkResolvedHref());
-    return col;
+    CollectionBuilder<Activity> builder = 
+      Collection.<Activity>makeCollection()
+        .id(feed.getId().toString())
+        .author(authors(feed.getAuthors()))
+        .set("contributors", authors(feed.getContributors()));
+    categories(feed.getCategories(), builder);
+    builder.set("generator", generator(feed.getGenerator()))
+      .image(image(feed.getIcon()))
+      .url(feed.getAlternateLinkResolvedHref())
+      .displayName(feed.getTitle())
+      .summary(feed.getSubtitle())
+      .updated(feed.getUpdated())
+      .set("nextLink", FeedPagingHelper.getNext(feed))
+      .set("previousLink", FeedPagingHelper.getPrevious(feed))
+      .set("firstLink", FeedPagingHelper.getFirst(feed))
+      .set("lastLink", FeedPagingHelper.getLast(feed))
+      .set("selfLink", feed.getSelfLinkResolvedHref());
+    return builder.get();
   }
   
   protected Verb verb(Entry entry) {
@@ -105,30 +106,29 @@ public class FeedToActivityConverter {
   }
   
   protected Activity item(Entry entry) {
-    Activity activity = new Activity();
+    ActivityBuilder builder = Activity.makeActivity();
     if (entry.getId() != null)
-      activity.setId(entry.getId().toString());
+      builder.id(entry.getId().toString());
     if (entry.getUpdated() != null)
-      activity.setUpdated(entry.getUpdated());
+      builder.updated(entry.getUpdated());
     if (entry.getPublished() != null)
-      activity.setPublished(entry.getPublished());
-    activity.setUrl(entry.getAlternateLinkResolvedHref());
-    activity.setTitle(entry.getTitle());
-    activity.setSummary(entry.getSummary());
-    categories(entry.getCategories(), activity);
-    activity.setLang(entry.getLanguageTag());
-    activity.setVerb(verb(entry));
+      builder.published(entry.getPublished());
+    builder.url(entry.getAlternateLinkResolvedHref())
+      .title(entry.getTitle())
+      .summary(entry.getSummary());
+    categories(entry.getCategories(), builder);
+    builder.lang(entry.getLanguageTag())
+      .verb(verb(entry));
     List<Person> authors = entry.getAuthorsInherited();
-    activity.setActor(authors(authors));
-    activity.setProperty("contributors", authors(entry.getContributors()));
-    activity.setObject(object(entry));
-    activity.setTarget(target(entry));
+    builder.actor(authors(authors))
+      .set("contributors", authors(entry.getContributors()))
+      .object(object(entry))
+      .target(target(entry));
     List<Link> enclosures = entry.getLinks("enclosure");
-    for (Link link : enclosures) {
-      activity.addAttachment(
+    for (Link link : enclosures)
+      builder.attachment(
         attachment(link));
-    }
-    return activity;
+    return builder.get();
   }
   
   protected String objectType(ExtensibleElement ext) {
@@ -143,29 +143,28 @@ public class FeedToActivityConverter {
   }
   
   protected ASObject object(ExtensibleElement ext) {
-    ASObject obj = new ASObject();
+    ASObjectBuilder builder = ASObject.makeObject(objectType(ext));
     if (ext.has(Constants.ID))
-      obj.setId(ext.getSimpleExtension(Constants.ID));
+      builder.id(ext.getSimpleExtension(Constants.ID));
     if (ext.has(Constants.TITLE)) {
       Text text = ext.getExtension(Constants.TITLE);
-      obj.setDisplayName(text.getValue());
+      builder.displayName(text.getValue());
     }
     if (ext.has(Constants.SUMMARY)) {
       Text text = ext.getExtension(Constants.SUMMARY);
-      obj.setSummary(text.getValue());
+      builder.summary(text.getValue());
     }
-    obj.setObjectType(objectType(ext));
     List<Link> links = ext.getExtensions(
       Constants.LINK, withRel("preview"));
     for (Link link : links) {
       String rel = link.getCanonicalRel();
       if (Link.REL_ALTERNATE.equalsIgnoreCase(rel)) {
-        obj.setUrl(link.getResolvedHref());
+        builder.url(link.getResolvedHref());
       } else if ("preview".equalsIgnoreCase(rel)) {
-        obj.setImage(image(link.getResolvedBaseUri()));
+        builder.image(image(link.getResolvedBaseUri()));
       }
     }
-    return obj;
+    return builder.get();
   }
   
   protected ASObject target(Entry entry) {
@@ -181,73 +180,61 @@ public class FeedToActivityConverter {
   }
   
   protected ASObject attachment(Link link) {
-    ASObject obj = new ASObject();
-    obj.setUrl(link.getResolvedHref());
-    obj.setProperty("mimeType", link.getMimeType());
-    obj.setDisplayName(link.getTitle());
-    obj.setProperty("hreflang", link.getHrefLang());
-    obj.setObjectType("link");
-    return obj;
+    return ASObject.makeObject("link")
+      .url(link.getResolvedHref())
+      .set("mimeType", link.getMimeType())
+      .displayName(link.getTitle())
+      .set("hreflang", link.getHrefLang())
+      .get();
   }
   
   protected MediaLink image(IRI iri) {
-    MediaLink link = null;
-    if (iri != null) {
-      link = new MediaLink();
-      link.setUrl(iri);
-    }
-    return link;
+    return iri == null ? null :
+      MediaLink.makeMediaLink()
+        .url(iri).get();
   }
   
   protected ASObject generator(Generator generator) {
-    ASObject _generator = null;
-    if (generator != null) {
-      _generator = new ServiceObject();
-      _generator.setDisplayName(generator.getText());
-      _generator.setProperty("version", generator.getVersion());
-      _generator.setUrl(generator.getUri());
-    }
-    return _generator;
+    return generator == null ? null :
+      ServiceObject
+        .makeService()
+        .displayName(generator.getText())
+        .set("version",generator.getVersion())
+        .url(generator.getUri())
+        .get();
   }
   
-  protected void categories(List<Category> categories, ASObject obj) {
+  protected void categories(List<Category> categories, ASObject.Builder<?,?> builder) {
     for (Category category : categories)
-      obj.addTag(category(category));
+      builder.tag(category(category));
   }
   
   protected ASObject category(Category category) {
-    ASObject _category = new ASObject("category");
-    _category.setDisplayName(category.getTerm());
-    if (category.getScheme() != null)
-      _category.setProperty("scheme", category.getScheme());
-    return _category;
+    return ASObject.makeObject("category")
+      .displayName(category.getTerm())
+      .set("scheme",category.getScheme()).get();
   }
   
   protected ASObject authors(List<Person> authors) {
     if (authors.size() == 1) {
       return person(authors.get(0));
     } else if (authors.size() > 1) {
-      Collection<PersonObject> _authors = 
-        new Collection<PersonObject>();
+      CollectionBuilder<PersonObject> _authors = 
+        Collection.<PersonObject>makeCollection();
       for (Person person : authors) {
         PersonObject _person = person(person);
         if (_person != null) 
-          _authors.addItem(_person);
+          _authors.item(_person);
       }
-      return _authors;
+      return _authors.get();
     } else return null;
   }
   
   protected PersonObject person(Person person) {
-    PersonObject _person = new PersonObject();
-    _person.setDisplayName(person.getName());
-    if (person.getUri() != null)
-      _person.setUrl(person.getUri());
-    if (person.getEmail() != null) {
-      Set<String> emails = new HashSet<String>();
-      emails.add(person.getEmail());
-      _person.setEmails(emails);
-    }
-    return _person;
+    return 
+      PersonObject.makePerson()
+       .displayName(person.getName())
+       .url(person.getUri())
+       .email(person.getEmail()).get();
   }
 }

Modified: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/AsyncBasicTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/AsyncBasicTest.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/AsyncBasicTest.java (original)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/AsyncBasicTest.java Thu Nov 10 21:48:45 2011
@@ -87,17 +87,15 @@ public class AsyncBasicTest {
           Thread.sleep(20 * 1000);
         } catch (Throwable t) {}
       
-        Activity activity = new Activity();
-        activity.setId("http://localhost:9002/sample/foo");
-        activity.setTitle("test entry");
-        activity.setVerb(Verb.POST);
-        activity.setPublishedNow();
-        PersonObject person = new PersonObject();
-        person.setDisplayName("James");
-        activity.setActor(person);
-        NoteObject note = new NoteObject();
-        note.setContent("Test Content");
-        activity.setObject(note);
+        Activity activity = 
+          Activity.makeActivity()
+           .id("http://localhost:9002/sample/foo")
+           .title("test entry")
+           .verb(Verb.POST)
+           .publishedNow()
+           .actor(PersonObject.makePerson().displayName("James").get())
+           .object(NoteObject.makeNote().content("Test Content").get())
+           .get();
         Session session = client.newSession();
         ActivityEntity ae = new ActivityEntity(activity);
         ClientResponse resp = session.post("http://localhost:9002/sample", ae);

Modified: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/BasicTest.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/BasicTest.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/BasicTest.java (original)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/BasicTest.java Thu Nov 10 21:48:45 2011
@@ -27,6 +27,10 @@ import java.io.IOException;
 import org.apache.abdera2.activities.client.ActivityEntity;
 import org.apache.abdera2.activities.model.ASObject;
 import org.apache.abdera2.activities.model.Activity;
+import org.apache.abdera2.activities.model.Activity.ActivityBuilder;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
+
+import static org.apache.abdera2.activities.model.ASBase.withoutFields;
 import org.apache.abdera2.activities.model.Collection;
 import org.apache.abdera2.activities.model.IO;
 import org.apache.abdera2.activities.model.Verb;
@@ -79,17 +83,15 @@ public class BasicTest {
 
     @Test
     public void testPostEntry() throws IOException {
-        Activity activity = new Activity();
-        activity.setId("http://localhost:9002/sample/foo");
-        activity.setTitle("test entry");
-        activity.setVerb(Verb.POST);
-        activity.setPublishedNow();
-        PersonObject person = new PersonObject();
-        person.setDisplayName("James");
-        activity.setActor(person);
-        NoteObject note = new NoteObject();
-        note.setContent("Test Content");
-        activity.setObject(note);
+      Activity activity = 
+        Activity.makeActivity()
+         .id("http://localhost:9002/sample/foo")
+         .title("test entry")
+         .verb(Verb.POST)
+         .publishedNow()
+         .actor(PersonObject.makePerson().displayName("James").get())
+         .object(NoteObject.makeNote().content("Test Content").get())
+         .get();
         Session session = client.newSession();
         ActivityEntity ae = new ActivityEntity(activity);
         ClientResponse resp = session.post("http://localhost:9002/sample", ae);
@@ -122,7 +124,7 @@ public class BasicTest {
         resp.release();
         assertTrue(object instanceof Activity);
         Activity activity = (Activity) object;
-        activity.setTitle("This is the modified title");
+        activity = activity.<Activity,ActivityBuilder>template(withoutFields("title")).get();
         ActivityEntity ae = new ActivityEntity(activity);
         resp = session.put("http://localhost:9002/sample/foo", ae);
         assertEquals(ResponseType.SUCCESSFUL, resp.getType());
@@ -163,23 +165,19 @@ public class BasicTest {
     @SuppressWarnings("unused")
     @Test
     public void testMultiPostEntry() throws IOException {
-        Collection<Activity> collection = new Collection<Activity>();
-        for (int n = 0; n < 10; n++) {
-          Activity activity = new Activity();
-          activity.setId("http://localhost:9002/sample/foo" + n);
-          activity.setTitle("test entry " + n);
-          activity.setVerb(Verb.POST);
-          activity.setPublishedNow();
-          PersonObject person = new PersonObject();
-          person.setDisplayName("James");
-          activity.setActor(person);
-          NoteObject note = new NoteObject();
-          note.setContent("Test Content " + n);
-          activity.setObject(note);
-          collection.addItem(activity);
-        }
+        CollectionBuilder<Activity> builder = Collection.makeCollection();
+        for (int n = 0; n < 10; n++)
+          builder.item(
+            Activity.makeActivity()
+             .id("http://localhost:9002/sample/foo" + n)
+             .title("test entry "+n)
+             .verb(Verb.POST)
+             .publishedNow()
+             .actor(PersonObject.makePerson().displayName("James").get())
+             .object(NoteObject.makeNote().content("Test Content "+n).get())
+             .get());
         Session session = client.newSession();
-        ActivityEntity ae = new ActivityEntity(collection);
+        ActivityEntity ae = new ActivityEntity(builder.get());
         ClientResponse resp = session.post("http://localhost:9002/sample", ae);
         assertNotNull(resp);
         assertEquals(ResponseType.SUCCESSFUL, resp.getType());

Modified: abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/SampleBasicAdapter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/SampleBasicAdapter.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/SampleBasicAdapter.java (original)
+++ abdera/abdera2/test/src/main/java/org/apache/abdera2/test/activities/server/SampleBasicAdapter.java Thu Nov 10 21:48:45 2011
@@ -21,8 +21,9 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.logging.Logger;
 
+import org.apache.abdera2.activities.model.ASBase;
 import org.apache.abdera2.activities.model.ASObject;
-import org.apache.abdera2.activities.model.Collection;
+import org.apache.abdera2.activities.model.Collection.CollectionBuilder;
 import org.apache.abdera2.activities.protocol.basic.BasicAdapter;
 import org.apache.abdera2.activities.protocol.managed.FeedConfiguration;
 import org.apache.abdera2.common.protocol.RequestContext;
@@ -58,57 +59,58 @@ public class SampleBasicAdapter extends 
     }
 
     @Override
-    public Collection<ASObject> getCollection() throws Exception {
-        Collection<ASObject> col = createCollection();
-        
+    public CollectionBuilder<ASObject> getCollection() throws Exception {
+        CollectionBuilder<ASObject> col = createCollection();
         for (Item item : entries)
-          col.addItem(item.getValue());
+          col.item(item.getValue());
         return col;
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject getItem(Object entryId) throws Exception {
+    public ASObject.Builder<ASObject,?> getItem(Object entryId) throws Exception {
       ASObject ret = null;
       for (Item item : entries)
         if (item.getKey().equals(entryId.toString())) {
           ret = item.getValue();
           break;
         }
-      return ret;
+      if (ret == null) return null;
+      return ret.<ASObject,ASObject.Builder>template();
     }
 
     @Override
-    public ASObject createItem(ASObject object) throws Exception {
+    public <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object) throws Exception {
         return createItem(object,-1);
     }
     
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject createItem(ASObject object, int c) throws Exception {
-        setObjectIdIfNull(object);
-        logger.info("assigning id to Object: " + object.getId().toString());
-        String entryId = getObjectIdFromUri(object.getId().toString());
-        if (c != -1) entryId += c;
-        if (object.getUpdated() == null) {
-            object.setUpdatedNow();
-        }
-        addEditLinkToObject(object);
-        storeObject(entryId, object);
-        logger.finest("returning this object from sampleadapter.createItem: " + object.toString());
-        return object;
+    public <T extends ASObject>ASObject.Builder<T,?> createItem(ASObject object, int c) throws Exception {
+      ASObject.Builder<T, ?> builder = object.<ASObject,ASObject.Builder>template(ASBase.withoutFields("editLink","updated"));
+      if (!object.has("id"))
+        setObjectId(builder);
+      logger.info("assigning id to Object: " + object.getId().toString());
+      String entryId = getObjectIdFromUri(object.getId().toString());
+      if (c != -1) entryId += c;
+      builder.updatedNow();
+      addEditLinkToObject(builder,object.getId());
+      storeObject(entryId, object);
+      logger.finest("returning this object from sampleadapter.createItem: " + object.toString());
+      return builder;
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Override
-    public ASObject updateItem(Object entryId, ASObject object) throws Exception {
+    public <T extends ASObject>ASObject.Builder<T,?> updateItem(Object entryId, ASObject object) throws Exception {
         if (!deleteItem(entryId))
             throw new Exception(ERROR_INVALID_ENTRY);
-        
-        if (object.getUpdated() == null) {
-            object.setUpdatedNow();
-        }
-        addEditLinkToObject(object);
-        storeObject((String)entryId, object);
+        ASObject.Builder<T, ?> builder = object.<ASObject,ASObject.Builder>template(ASBase.withoutFields("editLink","updated"));
+        builder.updatedNow();
+        addEditLinkToObject(builder,object.getId());
+        storeObject((String)entryId, builder.get());
         logger.finest("returning this entry from sampleadapter.updateEntry: " + object.toString());
-        return object;
+        return builder;
     }
 
     @Override



Mime
View raw message