You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2011/11/10 22:48:48 UTC
svn commit: r1200583 [2/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...
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/ASObject.java Thu Nov 10 21:48:45 2011
@@ -20,20 +20,20 @@ package org.apache.abdera2.activities.mo
import org.joda.time.DateTime;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.abdera2.activities.extra.Extra;
import org.apache.abdera2.activities.model.objects.EmbeddedExperience;
import org.apache.abdera2.activities.model.objects.Mood;
-import org.apache.abdera2.activities.model.objects.PersonObject;
import org.apache.abdera2.activities.model.objects.PlaceObject;
-import org.apache.abdera2.common.anno.AnnoUtil;
+import org.apache.abdera2.common.date.DateTimes;
import org.apache.abdera2.common.iri.IRI;
import org.apache.abdera2.common.selector.Selector;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
@@ -42,7 +42,6 @@ import com.google.common.collect.Iterabl
@SuppressWarnings("unchecked")
public class ASObject extends ASBase {
- private static final long serialVersionUID = -6969558559101109831L;
public static final String ATTACHMENTS = "attachments";
public static final String AUTHOR = "author";
public static final String CONTENT = "content";
@@ -66,79 +65,209 @@ public class ASObject extends ASBase {
public static final String EMBED = "embed";
- public ASObject() {
- setObjectType(AnnoUtil.getName(this));
+ public static ASObjectBuilder makeObject() {
+ return new ASObjectBuilder();
}
- public ASObject(String objectType) {
- setObjectType(objectType);
+ public static ASObjectBuilder makeObject(String objectType) {
+ return new ASObjectBuilder(objectType);
}
- /**
- * Returns the value of the "attachments" property
- */
- public Iterable<ASObject> getAttachments() {
- return checkEmpty((Iterable<ASObject>)getProperty(ATTACHMENTS));
- }
-
- /**
- * Sets the value of the attachments property... note... internally, the
- * list of attachments does not allow for duplicate entries so the collection
- * passed in is changed to a LinkedHashSet, maintaining the order of the
- * entries but eliminating duplicates.
- */
- public void setAttachments(java.util.Collection<ASObject> attachments) {;
- setProperty(ATTACHMENTS, new LinkedHashSet<ASObject>(attachments));
+ public static class ASObjectBuilder extends Builder<ASObject,ASObjectBuilder> {
+ public ASObjectBuilder() {
+ super(ASObject.class, ASObjectBuilder.class);
+ }
+ public ASObjectBuilder(Map<String, Object> map) {
+ super(map, ASObject.class, ASObjectBuilder.class);
+ }
+ public ASObjectBuilder(String objectType) {
+ super(objectType, ASObject.class, ASObjectBuilder.class);
+ }
}
- /**
- * Adds an attachment to the "attachments" property.
- */
- public void addAttachment(ASObject... attachments) {
- Set<ASObject> list = getProperty(ATTACHMENTS);
- if (list == null) {
- list = new LinkedHashSet<ASObject>();
- setProperty(ATTACHMENTS, list);
+ public static abstract class Builder<X extends ASObject, M extends Builder<X,M>>
+ extends ASBase.Builder<X,M> {
+
+ private ImmutableSet.Builder<ASObject> attachments = ImmutableSet.builder();
+ private ImmutableSet.Builder<ASObject> tags = ImmutableSet.builder();
+ private ImmutableSet.Builder<ASObject> replies = ImmutableSet.builder();
+ private ImmutableSet.Builder<String> downdups = ImmutableSet.builder();
+ private ImmutableSet.Builder<String> updups = ImmutableSet.builder();
+ private boolean a,t,r,d,u;
+
+ public Builder(String objectType, Class<X> _class, Class<M> _builder) {
+ super(_class,_builder);
+ set(OBJECTTYPE,objectType);
+ }
+ public Builder(Class<X> _class, Class<M> _builder) {
+ super(_class,_builder);
+ }
+ public Builder(Map<String,Object> map,Class<X> _class, Class<M> _builder) {
+ super(map,_class,_builder);
+ }
+ public M attachment(ASObject object) {
+ if (object == null) return (M)this;
+ if (!a)a=true;
+ attachments.add(object);
+ return (M)this;
+ }
+
+ public M downstreamDuplicate(String id) {
+ if (id == null) return (M)this;
+ if (!d)d=true;
+ downdups.add(id);
+ return (M)this;
+ }
+
+ public M inReplyTo(ASObject object) {
+ if (object == null) return (M)this;
+ if (!r)r=true;
+ replies.add(object);
+ return (M)this;
+ }
+
+ public M tag(ASObject object) {
+ if (object == null) return (M)this;
+ if (!t)t=true;
+ tags.add(object);
+ return (M)this;
+ }
+
+ public M upstreamDuplicate(String id) {
+ if (id == null) return (M)this;
+ if (!u)u=true;
+ updups.add(id);
+ return (M)this;
+ }
+
+ public M author(ASObject object) {
+ set(AUTHOR,object);
+ return (M)this;
+ }
+
+ public M content(String content) {
+ set(CONTENT,content);
+ return (M)this;
+ }
+
+ public M displayName(String displayName) {
+ set(DISPLAYNAME,displayName);
+ return (M)this;
+ }
+
+ public M embed(ASObject object) {
+ set(EMBED,object);
+ return (M)this;
+ }
+
+ public M embeddedExperience(EmbeddedExperience ee) {
+ set(
+ "openSocial",
+ ASBase
+ .make()
+ .set("embed",ee)
+ .get()
+ );
+ return (M)this;
+ }
+
+ public M id(String id) {
+ set(ID,id);
+ return (M)this;
}
- for (ASObject attachment : attachments)
- list.add(attachment);
+
+ public M image(MediaLink link) {
+ set(IMAGE,link);
+ return (M)this;
+ }
+
+ public M location(PlaceObject object) {
+ set(LOCATION,object);
+ return (M)this;
+ }
+
+ public M mood(Mood mood) {
+ set(MOOD,mood);
+ return (M)this;
+ }
+
+ public M objectType(String type) {
+ set(OBJECTTYPE,type);
+ return (M)this;
+ }
+
+ public M published(DateTime dt) {
+ set(PUBLISHED,dt);
+ return (M)this;
+ }
+
+ public M publishedNow() {
+ return published(DateTimes.now());
+ }
+
+ public M rating(double rating) {
+ set(RATING,rating);
+ return (M)this;
+ }
+
+ public M source(ASObject object) {
+ set(SOURCE,object);
+ return (M)this;
+ }
+
+ public M summary(String summary) {
+ set(SUMMARY,summary);
+ return (M)this;
+ }
+
+ public M updated(DateTime dt) {
+ set(UPDATED,dt);
+ return (M)this;
+ }
+
+ public M updatedNow() {
+ return updated(DateTimes.now());
+ }
+
+ public M url(IRI url) {
+ set(URL,url);
+ return (M)this;
+ }
+
+ public M url(String url) {
+ return url(url != null ? new IRI(url) : null);
+ }
+
+ public void preGet() {
+ if (a) set(ATTACHMENTS, attachments.build());
+ if (t) set(TAGS, tags.build());
+ if (r) set(INREPLYTO, replies.build());
+ if (d) set(DOWNSTREAMDUPLICATES, downdups.build());
+ if (u) set(UPSTREAMDUPLICATES, updups.build());
+ }
+
}
-
- /**
- * Return the author of this object
- */
- public <E extends ASObject>E getAuthor() {
- return (E)getProperty(AUTHOR);
+
+ public ASObject(Map<String,Object> map) {
+ super(map,ASObjectBuilder.class,ASObject.class);
}
- /**
- * Return the author of this object, if the author has not been
- * set and create==true, creates a default PersonObject and
- * returns that.
- */
- public <E extends ASObject>E getAuthor(boolean create) {
- ASObject obj = getAuthor();
- if (obj == null && create) {
- obj = new PersonObject();
- setAuthor(obj);
- }
- return (E)obj;
+ public <X extends ASObject, M extends Builder<X,M>>ASObject(Map<String,Object> map, Class<M> _class, Class<X> _obj) {
+ super(map,_class,_obj);
}
/**
- * Set the author of the object
+ * Returns the value of the "attachments" property
*/
- public void setAuthor(ASObject author) {
- setProperty(AUTHOR, author);
+ public Iterable<ASObject> getAttachments() {
+ return checkEmpty((Iterable<ASObject>)getProperty(ATTACHMENTS));
}
/**
- * Set the author of the object
+ * Return the author of this object
*/
- public <E extends ASObject>E setAuthor(String displayName) {
- ASObject obj = getAuthor(true);
- obj.setDisplayName(displayName);
- return (E)obj;
+ public <E extends ASObject>E getAuthor() {
+ return (E)getProperty(AUTHOR);
}
/**
@@ -149,14 +278,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the content of the object
- */
- public void setContent(String content) {
- setProperty(CONTENT, content);
-
- }
-
- /**
* Get the displayName of the object
*/
public String getDisplayName() {
@@ -164,14 +285,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the displayName of the object
- */
- public void setDisplayName(String displayName) {
- setProperty(DISPLAYNAME, displayName);
-
- }
-
- /**
* Return the list of downstream duplicate ids for this object.
* When an object is redistributed by third parties, the value of the "id"
* property may change. When such changes do occur, it becomes difficult
@@ -185,39 +298,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the list of downstream duplicate ids for this object.
- * When an object is redistributed by third parties, the value of the "id"
- * property may change. When such changes do occur, it becomes difficult
- * to track duplicate versions of the same object. The "downstreamDuplicates"
- * and "upstreamDuplicates" properties on the object can be used to track
- * modifications that occur in the "id" of the object in order to make
- * duplication detection easier
- */
- public void setDownstreamDuplicates(Set<String> downstreamDuplicates) {
- setProperty(DOWNSTREAMDUPLICATES, downstreamDuplicates);
-
- }
-
- /**
- * Add an entry to the list of downstream duplicate ids for this object.
- * When an object is redistributed by third parties, the value of the "id"
- * property may change. When such changes do occur, it becomes difficult
- * to track duplicate versions of the same object. The "downstreamDuplicates"
- * and "upstreamDuplicates" properties on the object can be used to track
- * modifications that occur in the "id" of the object in order to make
- * duplication detection easier
- */
- public void addDownstreamDuplicate(String... duplicates) {
- Set<String> downstreamDuplicates = getProperty(DOWNSTREAMDUPLICATES);
- if (downstreamDuplicates == null) {
- downstreamDuplicates = new HashSet<String>();
- setProperty(DOWNSTREAMDUPLICATES, downstreamDuplicates);
- }
- for (String downstreamDuplicate : duplicates)
- downstreamDuplicates.add(downstreamDuplicate);
- }
-
- /**
* Get the id of this object
*/
public String getId() {
@@ -225,14 +305,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the id of this object
- */
- public void setId(String id) {
- setProperty(ID, id);
-
- }
-
- /**
* Get the "image" property
*/
public MediaLink getImage() {
@@ -240,52 +312,12 @@ public class ASObject extends ASBase {
}
/**
- * Set the "image" property
- */
- public void setImage(MediaLink image) {
- setProperty(IMAGE, image);
- }
-
- /**
- * Set the "image" property
- */
- public void setImage(String uri) {
- if (uri == null)
- setImage((MediaLink)null);
- else {
- MediaLink link = getImage();
- if (link == null) {
- link = new MediaLink();
- setProperty(IMAGE,link);
- }
- link.setUrl(uri);
- }
- }
-
- /**
- * Set the "image" property
- */
- public void setImage(IRI uri) {
- setImage(uri != null ? uri.toString() : null);
- }
-
- /**
* Get the objectType
*/
public String getObjectType() {
return getProperty(OBJECTTYPE);
}
-
- /**
- * Set the objectType
- */
- public void setObjectType(String objectType) {
- if (objectType != null &&
- ASObject.class.getSimpleName().equalsIgnoreCase(objectType))
- objectType = null;
- setProperty(OBJECTTYPE, objectType);
- }
-
+
/**
* Get the "published" datetime
*/
@@ -294,20 +326,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "published" datetime
- */
- public void setPublished(DateTime published) {
- setProperty(PUBLISHED, published);
- }
-
- /**
- * Set the "published" property to the current date, time and default timezone
- */
- public void setPublishedNow() {
- setPublished(DateTime.now());
- }
-
- /**
* Get the "summary" property
*/
public String getSummary() {
@@ -315,13 +333,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "summary" property
- */
- public void setSummary(String summary) {
- setProperty(SUMMARY, summary);
- }
-
- /**
* Get the "updated" property
*/
public DateTime getUpdated() {
@@ -329,20 +340,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "updated" property
- */
- public void setUpdated(DateTime updated) {
- setProperty(UPDATED, updated);
- }
-
- /**
- * Set the "updated" property to the current date,time and default timezone
- */
- public void setUpdatedNow() {
- setUpdated(DateTime.now());
- }
-
- /**
* Return the list of upstream duplicate ids for this object.
* When an object is redistributed by third parties, the value of the "id"
* property may change. When such changes do occur, it becomes difficult
@@ -356,39 +353,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the list of upstream duplicate ids for this object.
- * When an object is redistributed by third parties, the value of the "id"
- * property may change. When such changes do occur, it becomes difficult
- * to track duplicate versions of the same object. The "downstreamDuplicates"
- * and "upstreamDuplicates" properties on the object can be used to track
- * modifications that occur in the "id" of the object in order to make
- * duplication detection easier
- */
- public void setUpstreamDuplicates(Set<String> upstreamDuplicates) {
- setProperty(UPSTREAMDUPLICATES, upstreamDuplicates);
-
- }
-
- /**
- * Add to the list of upstream duplicate ids for this object.
- * When an object is redistributed by third parties, the value of the "id"
- * property may change. When such changes do occur, it becomes difficult
- * to track duplicate versions of the same object. The "downstreamDuplicates"
- * and "upstreamDuplicates" properties on the object can be used to track
- * modifications that occur in the "id" of the object in order to make
- * duplication detection easier
- */
- public void addUpstreamDuplicate(String... duplicates) {
- Set<String> upstreamDuplicates = getProperty(UPSTREAMDUPLICATES);
- if (upstreamDuplicates == null) {
- upstreamDuplicates = new HashSet<String>();
- setProperty(UPSTREAMDUPLICATES, upstreamDuplicates);
- }
- for (String upstreamDuplicate : duplicates)
- upstreamDuplicates.add(upstreamDuplicate);
- }
-
- /**
* Get the url of this object
*/
public IRI getUrl() {
@@ -396,13 +360,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the url of this object
- */
- public void setUrl(IRI url) {
- setProperty(URL,url);
- }
-
- /**
* Get the collection of objects this object is considered a response to
*/
public Iterable<ASObject> getInReplyTo() {
@@ -420,28 +377,7 @@ public class ASObject extends ASBase {
list.add(obj);
return list;
}
-
- /**
- * Set the collection of objects this object is considered a response to.
- * Note that duplicates are removed
- */
- public void setInReplyTo(java.util.Collection<ASObject> inReplyTo) {
- setProperty(INREPLYTO, new LinkedHashSet<ASObject>(inReplyTo));
- }
-
- /**
- * Add a new object this object is considered a response to
- */
- public void addInReplyTo(ASObject... inReplyTos) {
- Set<ASObject> list = getProperty(INREPLYTO);
- if (list == null) {
- list = new LinkedHashSet<ASObject>();
- setProperty(INREPLYTO, list);
- }
- for (ASObject inReplyTo : inReplyTos)
- list.add(inReplyTo);
- }
-
+
/**
* Get the "location" property
*/
@@ -450,14 +386,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "location" property
- */
- public void setLocation(PlaceObject location) {
- setProperty(LOCATION, location);
- location.setObjectType(null);
- }
-
- /**
* Get the "mood" property
*/
public Mood getMood() {
@@ -465,13 +393,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "mood" property
- */
- public void setMood(Mood mood) {
- setProperty(MOOD, mood);
- }
-
- /**
* Get the "source" property
*/
public <E extends ASObject>E getSource() {
@@ -479,13 +400,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the "source" property
- */
- public void setSource(ASObject source) {
- setProperty(SOURCE, source);
- }
-
- /**
* Get the collection of tags for this object
*/
public Iterable<ASObject> getTags() {
@@ -493,27 +407,6 @@ public class ASObject extends ASBase {
}
/**
- * Set the collection of tags for this object. Duplicates
- * will be removed.
- */
- public void setTags(java.util.Collection<ASObject> tags) {
- setProperty(TAGS, new LinkedHashSet<ASObject>(tags));
- }
-
- /**
- * Add an object to the collection of tags for this object
- */
- public void addTag(ASObject... tags) {
- Set<ASObject> list = getProperty(TAGS);
- if (list == null) {
- list = new LinkedHashSet<ASObject>();
- setProperty(TAGS, list);
- }
- for (ASObject tag : tags)
- list.add(tag);
- }
-
- /**
* @see org.apache.abdera2.activities.model.ASObject.getEmbeddedExperience()
* {"embed":{...}}
*/
@@ -522,27 +415,12 @@ public class ASObject extends ASBase {
}
/**
- * @see org.apache.abdera2.activities.model.ASObject.setEmbeddedExperience()
- * {"embed":{...}}
- */
- public void setEmbed(ASObject embed) {
- setProperty(EMBED,embed);
- }
-
- /**
* Get the "rating" property
*/
public double getRating() {
return (Double)getProperty(RATING);
}
- /**
- * Set the "rating" property
- */
- public void setRating(double rating) {
- setProperty(RATING, rating);
- }
-
public String toString() {
StringBuilder sb = new StringBuilder();
String objectType = getObjectType();
@@ -579,42 +457,13 @@ public class ASObject extends ASBase {
*
* {"openSocial":{"embed":{...}}}
*/
- public void setEmbeddedExperience(EmbeddedExperience embed) {
- ASBase os = getProperty("openSocial");
- if (os == null) {
- os = new ASBase();
- setProperty("openSocial", os);
- }
- os.setProperty("embed", embed);
- }
-
- /**
- * "Embedded Experiences" were introduced to Activity Streams
- * by the OpenSocial 2.0 specification, while functionally not
- * specific to OpenSocial, the spec defines that the "Embedded
- * Experience" document has to be wrapped within an "openSocial"
- * extension property. Other applications, such as Google+, however,
- * use the "embed" property directly within an object without the
- * "openSocial" wrapper. To use the "embed" property without
- * the "openSocial" wrapper, use the setEmbed/getEmbed properties
- * on ASObject. To use OpenSocial style Embedded Experiences,
- * use the setEmbeddedExperience/getEmbeddedExperience/hasEmbeddedExperience
- * methods. The OpenSocial style Embedded Experience should be used
- * primarily to associate OpenSocial Gadgets with an activity
- * object while the alternative "embed" can be used to reference
- * any kind of embedded content.
- *
- * {"openSocial":{"embed":{...}}}
- */
public EmbeddedExperience getEmbeddedExperience() {
if (!has("openSocial")) return null;
ASBase os = getProperty("openSocial");
if (!os.has("embed")) return null;
ASBase e = os.getProperty("embed");
- if (!(e instanceof EmbeddedExperience)) {
+ if (!(e instanceof EmbeddedExperience))
e = e.as(EmbeddedExperience.class);
- os.setProperty("embed", e);
- }
return (EmbeddedExperience) e;
}
@@ -649,142 +498,10 @@ public class ASObject extends ASBase {
return list;
}
- /**
- * Begins creating a new object using the fluent factory api
- */
- public static <X extends ASObjectGenerator<T>,T extends ASObject>X make() {
- return (X)new ASObjectGenerator<T>();
+ public <T extends ASObject,M extends Builder<T,M>>T as(Class<T> type, String newObjectType) {
+ return (T)as(type,withoutFields("objectType"))
+ .<T,M>template()
+ .objectType(newObjectType).get();
}
- public static class ASObjectGenerator<T extends ASObject> extends Generator<T> {
-
- public ASObjectGenerator() {
- super((Class<? extends T>) ASObject.class);
- startNew();
- }
-
- public ASObjectGenerator(Class<? extends T> _class) {
- super(_class);
- startNew();
- }
-
- public <X extends ASObjectGenerator<T>>X attachment(ASObject object) {
- item.addAttachment(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X downstreamDuplicate(String id) {
- item.addDownstreamDuplicate(id);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X inReplyTo(ASObject object) {
- item.addInReplyTo(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X tag(ASObject object) {
- item.addTag(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X upstreamDuplicate(String id) {
- item.addUpstreamDuplicate(id);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X author(ASObject object) {
- item.setAuthor(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X content(String content) {
- item.setContent(content);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X displayName(String displayName) {
- item.setDisplayName(displayName);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X embed(ASObject object) {
- item.setEmbed(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X embeddedExperience(EmbeddedExperience ee) {
- item.setEmbeddedExperience(ee);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X id(String id) {
- item.setId(id);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X image(MediaLink link) {
- item.setImage(link);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X location(PlaceObject object) {
- item.setLocation(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X mood(Mood mood) {
- item.setMood(mood);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X objectType(String type) {
- item.setObjectType(type);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X published(DateTime dt) {
- item.setPublished(dt);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X publishedNow() {
- item.setPublishedNow();
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X rating(double rating) {
- item.setRating(rating);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X source(ASObject object) {
- item.setSource(object);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X summary(String summary) {
- item.setSummary(summary);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X updated(DateTime dt) {
- item.setUpdated(dt);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X updatedNow() {
- item.setUpdatedNow();
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X url(IRI url) {
- item.setUrl(url);
- return (X)this;
- }
-
- public <X extends ASObjectGenerator<T>>X url(String url) {
- return url(new IRI(url));
- }
- }
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/AbstractCollectionWriter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/AbstractCollectionWriter.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/AbstractCollectionWriter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/AbstractCollectionWriter.java Thu Nov 10 21:48:45 2011
@@ -21,6 +21,10 @@ public abstract class AbstractCollection
public abstract void complete();
+ public <X extends CollectionWriter>X writeHeader(ASBase.Builder<?,?> base) {
+ return writeHeader(base.get());
+ }
+
public <X extends CollectionWriter>X writeHeader(ASBase base) {
if (_items || _header)
throw new IllegalStateException();
@@ -37,6 +41,10 @@ public abstract class AbstractCollection
return (X)this;
}
+ public <X extends CollectionWriter>X writeObject(ASObject.Builder<?, ?> object) {
+ return writeObject(object.get());
+ }
+
public <X extends CollectionWriter>X writeObject(ASObject object) {
if (!_items) {
startItems();
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Activity.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Activity.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Activity.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Activity.java Thu Nov 10 21:48:45 2011
@@ -18,18 +18,17 @@
package org.apache.abdera2.activities.model;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
import java.lang.Iterable;
-import org.apache.abdera2.activities.model.objects.PersonObject;
-import org.apache.abdera2.activities.model.objects.ServiceObject;
import org.apache.abdera2.common.anno.Name;
import org.apache.abdera2.common.iri.IRI;
import org.apache.abdera2.common.selector.Selector;
import org.joda.time.DateTime;
+import com.google.common.collect.ImmutableSet;
+
/**
* An Activity. Represents some action that has been taken. At it's core,
* every Activity consists of an Actor (who performed the action), a Verb
@@ -39,10 +38,8 @@ import org.joda.time.DateTime;
* "post", the Object is "a photo" and the Target is "his album".
*/
@SuppressWarnings("unchecked")
-@Name("activity")
public class Activity extends ASObject {
- private static final long serialVersionUID = -3284781784555866672L;
public static final String ACTOR = "actor";
public static final String CONTENT = "content";
public static final String GENERATOR = "generator";
@@ -74,73 +71,133 @@ public class Activity extends ASObject {
}
};
- public Activity() {}
-
- public Activity(
- ASObject actor,
- Verb verb) {
- setActor(actor);
- setVerb(verb);
- }
-
- public Activity(
- ASObject actor,
- Verb verb,
- ASObject object) {
- setActor(actor);
- setVerb(verb);
- setObject(object);
- }
-
- public Activity(
- ASObject actor,
- Verb verb,
- ASObject object,
- ASObject target) {
- setActor(actor);
- setVerb(verb);
- setObject(object);
- setTarget(target);
+ /**
+ * Begin creating a new Activity object using the fluent factory API
+ */
+ public static ActivityBuilder makeActivity() {
+ return new ActivityBuilder("activity");
}
- public ASObject getActor() {
- return getProperty(ACTOR);
+ @Name("activity")
+ public static class ActivityBuilder extends Builder<Activity,ActivityBuilder> {
+ public ActivityBuilder() {
+ super(Activity.class,ActivityBuilder.class);
+ }
+ public ActivityBuilder(Map<String, Object> map) {
+ super(map, Activity.class,ActivityBuilder.class);
+ }
+ public ActivityBuilder(String objectType) {
+ super(objectType,Activity.class,ActivityBuilder.class);
+ }
}
- /**
- * Returns the Actor Object... if an actor object
- * does not yet exist and create==true, a default
- * PersonObject will be created and set as the
- * object and returned.
- */
- public <E extends ASObject>E getActor(boolean create) {
- ASObject obj = getActor();
- if (obj == null && create) {
- obj = new PersonObject();
- setActor(obj);
+ public static abstract class Builder<X extends Activity, M extends Builder<X,M>>
+ extends ASObject.Builder<X,M> {
+
+ private final ImmutableSet.Builder<ASObject> to =
+ ImmutableSet.builder();
+ private final ImmutableSet.Builder<ASObject> bto =
+ ImmutableSet.builder();
+ private final ImmutableSet.Builder<ASObject> cc =
+ ImmutableSet.builder();
+ private final ImmutableSet.Builder<ASObject> bcc =
+ ImmutableSet.builder();
+ boolean a,b,c,d;
+
+ 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 to(ASObject object) {
+ a = true;
+ to.add(object);
+ return (M)this;
+ }
+ public M cc(ASObject object) {
+ b = true;
+ cc.add(object);
+ return (M)this;
+ }
+ public M bcc(ASObject object) {
+ c = true;
+ bcc.add(object);
+ return (M)this;
+ }
+ public M bto(ASObject object) {
+ d = true;
+ bto.add(object);
+ return (M)this;
+ }
+ public M actor(ASObject object) {
+ set(ACTOR,object);
+ return (M)this;
+ }
+ public M generator(ASObject object) {
+ set(GENERATOR,object);
+ return (M)this;
+ }
+ public M icon(MediaLink link) {
+ set(ICON,link);
+ return (M)this;
+ }
+ public M object(ASObject object) {
+ set(OBJECT,object);
+ return (M)this;
+ }
+ public M provider(ASObject object) {
+ set(PROVIDER,object);
+ return (M)this;
+ }
+ public M target(ASObject object) {
+ set(TARGET,object);
+ return (M)this;
+ }
+ public M title(String title) {
+ set(TITLE,title);
+ return (M)this;
+ }
+ public M verb(Verb verb) {
+ set(VERB,verb);
+ return (M)this;
+ }
+ public M displayName(String displayName) {
+ title(displayName);
+ return (M)this;
+ }
+ public M image(MediaLink link) {
+ icon(link);
+ return (M)this;
+ }
+ public M author(ASObject author) {
+ actor(author);
+ return (M)this;
+ }
+ public void preGet() {
+ if (a) set(Audience.TO.label(),to.build());
+ if (b) set(Audience.CC.label(),cc.build());
+ if (c) set(Audience.BCC.label(),bcc.build());
+ if (d) set(Audience.BTO.label(),bto.build());
}
- return (E)obj;
}
- /**
- * Set the Actor for this Activity.
- */
- public void setActor(ASObject actor) {
- setProperty(ACTOR, actor);
+ public Activity(Map<String,Object> map) {
+ super(map,ActivityBuilder.class,Activity.class);
}
- /**
- * Set the Actor's displayName for this activity.
- * If the Actor has not yet been set, a default
- * PersonObject will be created with the specified
- * displayName. If the Actor object has already
- * been set, this will change the displayName to
- * that specified.
- */
- public <E extends ASObject>E setActor(String displayName) {
- ASObject obj = getActor(true);
- obj.setDisplayName(displayName);
- return (E)obj;
+ public <X extends Activity, M extends Builder<X,M>>Activity(Map<String,Object> map, Class<M> _class, Class<X> _obj) {
+ super(map,_class, _obj);
+ }
+
+ public ASObject getActor() {
+ return getProperty(ACTOR);
}
/**
@@ -151,13 +208,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "content" property for this activity
- */
- public void setContent(String content) {
- setProperty(CONTENT, content);
- }
-
- /**
* Return the ASObject value of the "generator" property for this
* activity.
*/
@@ -166,39 +216,6 @@ public class Activity extends ASObject {
}
/**
- * Return the ASObject value for the "generator" property for this
- * activity. If the generator has not yet been set and create==true,
- * a default ServiceObject will be created, set and returned.
- */
- public <E extends ASObject>E getGenerator(boolean create) {
- ASObject obj = getGenerator();
- if (obj == null && create) {
- obj = new ServiceObject();
- setGenerator(obj);
- }
- return (E)obj;
- }
-
- /**
- * Set the value of the "generator" property for this Activity
- */
- public void setGenerator(ASObject generator) {
- setProperty(GENERATOR, generator);
- }
-
- /**
- * Set the value of the "generator" properties displayName.
- * If the generator has not yet been set, a default ServiceObject
- * will be created, set and returned. Otherwise, the displayName
- * of the existing object will be changed to that specified.
- */
- public <E extends ASObject>E setGenerator(String displayName) {
- ASObject obj = getGenerator(true);
- obj.setDisplayName(displayName);
- return (E)obj;
- }
-
- /**
* Return the value of the "icon" property
*/
public MediaLink getIcon() {
@@ -206,40 +223,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "icon" property
- */
- public void setIcon(MediaLink icon) {
- setProperty(ICON, icon);
- }
-
- /**
- * Set the value of the "icon" property. If the
- * property has not yet been set, the MediaLink
- * will be created.
- */
- public void setIcon(String uri) {
- if (uri == null)
- setProperty(ICON,null);
- else {
- MediaLink link = getIcon();
- if (link == null) {
- link = new MediaLink();
- setIcon(link);
- }
- link.setUrl(uri);
- }
- }
-
- /**
- * Set the value of the "icon" property. If the
- * property has not yet been set, the MediaLink
- * will be created.
- */
- public void setIcon(IRI uri) {
- setIcon(uri != null ? uri.toString() : null);
- }
-
- /**
* Get the value of the "id" property
*/
public String getId() {
@@ -247,20 +230,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "id" property
- */
- public void setId(String id) {
- setProperty(ID, id);
- }
-
- /**
- * set the value of the "id" property
- */
- public void setId(IRI id) {
- setId(id != null ? id.toString() : null);
- }
-
- /**
* Get the Activities Object property
*/
public <E extends ASObject>E getObject() {
@@ -268,13 +237,6 @@ public class Activity extends ASObject {
}
/**
- * Set the Activities Object property
- */
- public void setObject(ASObject object) {
- setProperty(OBJECT, object);
- }
-
- /**
* Get the value of the Activities "published" property
*/
public DateTime getPublished() {
@@ -282,20 +244,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the Activities "published" property
- */
- public void setPublished(DateTime published) {
- setProperty(PUBLISHED, published);
- }
-
- /**
- * Set the value of the Activities "published" property using the current date, time and default timezone
- */
- public void setPublishedNow() {
- setPublished(DateTime.now());
- }
-
- /**
* Get the value of the Activities "provider" property
*/
public <E extends ASObject>E getProvider() {
@@ -303,39 +251,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the Activities "provider" property.
- * If the value has not yet been set, a default ServiceObject
- * will be created, set and returned
- */
- public <E extends ASObject>E getProvider(boolean create) {
- ASObject obj = getProvider();
- if (obj == null && create) {
- obj = new ServiceObject();
- setProvider(obj);
- }
- return (E)obj;
- }
-
- /**
- * Set the value of the Activities "provider" property
- */
- public void setProvider(ASObject provider) {
- setProperty(PROVIDER, provider);
- }
-
- /**
- * Set the displayName of the Activities "provider" property.
- * If the object has not yet been created, a default
- * ServiceObject will be created, otherwise the displayName
- * will be changed to the provided value
- */
- public <E extends ASObject>E setProvider(String displayName) {
- ASObject obj = getProvider(true);
- obj.setDisplayName(displayName);
- return (E)obj;
- }
-
- /**
* Get the value of Activities "target" property
*/
public <E extends ASObject>E getTarget() {
@@ -343,13 +258,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the Activities "target" property
- */
- public void setTarget(ASObject target) {
- setProperty(TARGET, target);
- }
-
- /**
* Get the value of the "title" property
*/
public String getTitle() {
@@ -357,14 +265,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "title" property
- */
- public void setTitle(String title) {
- setProperty(TITLE, title);
-
- }
-
- /**
* Get the value of the "updated" property
*/
public DateTime getUpdated() {
@@ -372,20 +272,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "updated" property
- */
- public void setUpdated(DateTime updated) {
- setProperty(UPDATED, updated);
- }
-
- /**
- * Set the value of the "updated" property to the current date, time and default timezone
- */
- public void setUpdatedNow() {
- setUpdated(DateTime.now());
- }
-
- /**
* Get the value of the "url" property
*/
public IRI getUrl() {
@@ -393,13 +279,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "url" property
- */
- public void setUrl(IRI url) {
- setProperty(URL, url);
- }
-
- /**
* Get the value of the "verb" property
*/
public Verb getVerb() {
@@ -407,20 +286,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "verb" property
- */
- public void setVerb(Verb verb) {
- setProperty(VERB, verb);
- }
-
- /**
- * Set the value of the "verb" property
- */
- public void setVerb(String verb) {
- setVerb(verb != null ? Verb.get(verb) : null);
- }
-
- /**
* Get the value of the "author" property.. for Activity
* objects, the "author" property is mapped to the "actor"
* property in order to avoid duplication of content.
@@ -432,39 +297,6 @@ public class Activity extends ASObject {
}
/**
- * Set the value of the "author" property.. for Activity
- * objects, the "author" property is mapped to the "actor"
- * property in orde to avoid duplication of content.
- * If you want to set the actual "author" property, use
- * setProperty("author",val)
- */
- public <E extends ASObject>E getAuthor(boolean create) {
- return (E)getActor(create);
- }
-
- /**
- * Set the value of the "author" property.. for Activity
- * objects, the "author" property is mapped to the "actor"
- * property in orde to avoid duplication of content.
- * If you want to set the actual "author" property, use
- * setProperty("author",val)
- */
- public void setAuthor(ASObject author) {
- setActor(author);
- }
-
- /**
- * Set the value of the "author" property.. for Activity
- * objects, the "author" property is mapped to the "actor"
- * property in order to avoid duplication of content.
- * If you want to set the actual "author" property, use
- * setProperty("author",val)
- */
- public <E extends ASObject>E setAuthor(String displayName) {
- return (E)setActor(displayName);
- }
-
- /**
* Get the "displayName" property. For Activity objects, the
* "displayName" property is mapped to the "title" property.
* If you want to get the actual "displayName" property,
@@ -475,16 +307,6 @@ public class Activity extends ASObject {
}
/**
- * Set the "displayName" property. For Activity objects, the
- * "displayName" property is mapped to the "title" property.
- * If you want to set the actual "displayName" property,
- * us setProperty("displayName",val)
- */
- public void setDisplayName(String displayName) {
- setTitle(displayName);
- }
-
- /**
* Get the "image" property. For Activity objects, the
* "image" property is mapped to the "icon" property.
* If you want to get the actual "image" property,
@@ -495,16 +317,6 @@ public class Activity extends ASObject {
}
/**
- * Set the "image" property. For Activity objects, the
- * "image" property is mapped to the "icon" property.
- * If you want to set the actual "image" property,
- * us setProperty("image",val)
- */
- public void setImage(MediaLink image) {
- setIcon(image);
- }
-
- /**
* Get the specified target audience for the activity
*/
public Iterable<ASObject> getAudience(Audience audience) {
@@ -523,91 +335,6 @@ public class Activity extends ASObject {
if (selector.apply(obj))
list.add(obj);
return list;
- }
+ }
- /**
- * Set the target audience for the activity
- */
- public void setAudience(Audience audience, Set<ASObject> set) {
- setProperty(audience.label(), set);
- }
-
- /**
- * Add one or more entities to the target audience of the activity.
- * Unlike setAudience, this will not overwrite the existing audience
- * property values.
- */
- public void addAudience(Audience audience, ASObject... objs) {
- Set<ASObject> list = getProperty(audience.label());
- if (list == null) {
- list = new HashSet<ASObject>();
- setProperty(audience.label(),list);
- }
- for (ASObject obj : objs)
- list.add(obj);
- }
-
- /**
- * Begin creating a new Activity object using the fluent factory API
- */
- public static <T extends Activity>ActivityGenerator<T> makeActivity() {
- return new ActivityGenerator<T>();
- }
-
- public static class ActivityGenerator<T extends Activity> extends ASObjectGenerator<T> {
- ActivityGenerator() {
- super((Class<? extends T>) Activity.class);
- }
- protected ActivityGenerator(Class<? extends T> _class) {
- super(_class);
- }
- public <X extends ActivityGenerator<T>>X to(ASObject object) {
- item.addAudience(Audience.TO, object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X cc(ASObject object) {
- item.addAudience(Audience.CC, object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X bcc(ASObject object) {
- item.addAudience(Audience.BCC, object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X bto(ASObject object) {
- item.addAudience(Audience.BTO, object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X actor(ASObject object) {
- item.setActor(object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X generator(ASObject object) {
- item.setGenerator(object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X icon(MediaLink link) {
- item.setIcon(link);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X object(ASObject object) {
- item.setObject(object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X provider(ASObject object) {
- item.setProvider(object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X target(ASObject object) {
- item.setTarget(object);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X title(String title) {
- item.setTitle(title);
- return (X)this;
- }
- public <X extends ActivityGenerator<T>>X verb(Verb verb) {
- item.setVerb(verb);
- return (X)this;
- }
- }
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Collection.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Collection.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Collection.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/Collection.java Thu Nov 10 21:48:45 2011
@@ -18,14 +18,16 @@
package org.apache.abdera2.activities.model;
import java.util.ArrayList;
-import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.abdera2.common.anno.Name;
import org.apache.abdera2.common.iri.IRI;
import org.apache.abdera2.common.selector.Selector;
+import com.google.common.collect.ImmutableSet;
+
/**
* An Activity Streams Collection... used as the root object of
* JSON Activity Streams documents and as the value for a variety
@@ -34,17 +36,125 @@ import org.apache.abdera2.common.selecto
* the array of items inline, the "url" property can be used to
* reference an external Collection document.
*/
-@Name("collection")
public class Collection<T extends ASObject>
extends ASObject {
- private static final long serialVersionUID = 1530068180553259077L;
public static final String TOTAL_ITEMS = "totalItems";
public static final String URL = "url";
public static final String ITEMS = "items";
public static final String OBJECT_TYPES = "objectTypes";
/**
+ * Begin making a new collection object using the fluent factory api
+ */
+ public static <T extends ASObject>CollectionBuilder<T> makeCollection() {
+ return new CollectionBuilder<T>("collection");
+ }
+
+ public static <T extends ASObject>Collection<T> makeCollection(Iterable<T> items) {
+ return Collection.<T>makeCollection().items(items).get();
+ }
+
+ public static <T extends ASObject>Collection<T> makeCollection(T... items) {
+ return Collection.<T>makeCollection().items(items).get();
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T extends ASObject>Class<Collection<T>> _class(Class<?> _class) {
+ return (Class<Collection<T>>) _class;
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T extends ASObject>Class<CollectionBuilder<T>> _builder(Class<?> _class) {
+ return (Class<CollectionBuilder<T>>) _class;
+ }
+
+ @Name("collection")
+ public static class CollectionBuilder<T extends ASObject>
+ extends Builder<T,Collection<T>,CollectionBuilder<T>> {
+
+ public CollectionBuilder() {
+ super(
+ Collection.<T>_class(Collection.class),
+ Collection.<T>_builder(CollectionBuilder.class));
+ }
+
+ public CollectionBuilder(Map<String, Object> map) {
+ super(map, Collection.<T>_class(Collection.class),
+ Collection.<T>_builder(CollectionBuilder.class));
+ }
+
+ public CollectionBuilder(String objectType) {
+ super(objectType, Collection.<T>_class(Collection.class),
+ Collection.<T>_builder(CollectionBuilder.class));
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static abstract class Builder<T extends ASObject, X extends ASObject, M extends Builder<T,X,M>>
+ extends ASObject.Builder<X,M> {
+ private final ImmutableSet.Builder<T> items =
+ ImmutableSet.builder();
+ private final ImmutableSet.Builder<String> types =
+ ImmutableSet.builder();
+ boolean a,b,c;
+ 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 item(T item) {
+ if (item == null) return (M)this;
+ a=true;
+ items.add(item);
+ return (M)this;
+ }
+ public M items(T... items) {
+ for (T item : items)
+ item(item);
+ return (M)this;
+ }
+ public M items(Iterable<T> items) {
+ for (T item : items)
+ item(item);
+ return (M)this;
+ }
+ public M objectTypes(String... types) {
+ if (types.length == 0) return (M)this;
+ b=true;
+ for (String type : types)
+ this.types.add(type);
+ return (M)this;
+ }
+ public M totalItems(int count) {
+ c = true;
+ set(TOTAL_ITEMS, Math.max(0,count));
+ return (M)this;
+ }
+ public void preGet() {
+ Set<T> i = items.build();
+ if(b) set(OBJECT_TYPES, types.build());
+ if(a) {
+ if (!c) set(TOTAL_ITEMS, i.size());
+ map.put(ITEMS, i);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection(Map<String,Object> map) {
+ super(map,CollectionBuilder.class,Collection.class);
+ }
+
+ public <X extends Collection<T>, M extends Builder<T,X,M>>Collection(Map<String,Object> map, Class<M> _class, Class<X> _obj) {
+ super(map,_class,_obj);
+ }
+
+ /**
* Return the value of the "totalItems" property... this does not
* necessarily reflect the actual number of items in the "items"
* iterator.
@@ -54,14 +164,6 @@ public class Collection<T extends ASObje
}
/**
- * Set the value of the "totalItems" property
- */
- public Collection<T> setTotalItems(int totalItems) {
- setProperty(TOTAL_ITEMS, totalItems);
- return this;
- }
-
- /**
* Get the url of this collection
*/
public IRI getUrl() {
@@ -69,13 +171,6 @@ public class Collection<T extends ASObje
}
/**
- * Set the url of this collection
- */
- public void setUrl(IRI url) {
- setProperty(URL, url);
- }
-
- /**
* Get the list of objectTypes expected to be found in this collection
*/
public Iterable<String> getObjectTypes() {
@@ -83,27 +178,6 @@ public class Collection<T extends ASObje
}
/**
- * Set the list of objectTypes expected to be found in this collection
- */
- public void setObjectTypes(java.util.Collection<String> types) {
- setProperty(OBJECT_TYPES,new LinkedHashSet<String>(types));
- }
-
- /**
- * Add a new objectType to the list of objectTypes expected to be found
- * in this collection
- */
- public void addObjectType(String... objectTypes) {
- Set<String> list = getProperty(OBJECT_TYPES);
- if (list == null) {
- list = new LinkedHashSet<String>();
- setProperty(OBJECT_TYPES, list);
- }
- for (String objectType : objectTypes)
- list.add(objectType);
- }
-
- /**
* get the items collection using the specified selector as a filter
*/
public Iterable<T> getItems(Selector<T> selector) {
@@ -121,90 +195,5 @@ public class Collection<T extends ASObje
public Iterable<T> getItems() {
return checkEmpty((Iterable<T>)getProperty(ITEMS));
}
-
- /**
- * Get the items contained in this collection. If no "items"
- * property exists, a new LinkedHashSet will be created, set
- * and returned if create == true;
- */
- public Iterable<T> getItems(boolean create) {
- Iterable<T> items = getItems();
- if (items == null && create) {
- items = new LinkedHashSet<T>();
- setProperty(ITEMS,items);
- }
- return items;
- }
-
- /**
- * Set the items in this collection, overwriting the existing value.
- * setting this will change the value of the "totalItems" property
- * to reflect the number of items passed in.
- */
- public void setItems(java.util.Collection<T> items) {
- setProperty(ITEMS, new LinkedHashSet<T>(items));
- setTotalItems(items.size());
- }
-
- /**
- * Set the items in this collection, overwriting the existing value.
- * setting this will change the value of the "totalItems" property
- * to reflect the number of items passed in.
- */
- public void setItems(Iterable<T> items) {
- Set<T> set = new LinkedHashSet<T>();
- for (T item : items) set.add(item);
- setItems(set);
- }
-
- /**
- * Add an item to this collection
- * setting this will change the value of the "totalItems" property
- * to reflect the number of items passed in.
- */
- public void addItem(T... items) {
- Set<T> list = getProperty(ITEMS);
- if (list == null) {
- list = new LinkedHashSet<T>();
- setProperty(ITEMS, list);
- }
- for (T item : items)
- list.add(item);
- setTotalItems(list.size());
- }
-
- /**
- * Begin making a new collection object using the fluent factory api
- */
- public static <T extends ASObject>CollectionGenerator<T> makeCollection() {
- return new CollectionGenerator<T>();
- }
-
- @SuppressWarnings("unchecked")
- public static class CollectionGenerator<T extends ASObject>
- extends ASObjectGenerator<Collection<T>> {
-
- @SuppressWarnings("rawtypes")
- private static <T extends ASObject>Class<? extends Collection<T>> t(Class _class) {
- return (Class<? extends Collection<T>>) _class;
- }
-
- public CollectionGenerator() {
- super(CollectionGenerator.<T>t(Collection.class));
- }
-
- public CollectionGenerator(Class<? extends Collection<T>> _class) {
- super(_class);
- }
-
- public <X extends CollectionGenerator<T>>X totalItems(int items) {
- item.setTotalItems(items);
- return (X)this;
- }
-
- public <X extends CollectionGenerator<T>>X item(T item) {
- this.item.addItem(item);
- return (X)this;
- }
- }
+
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/CollectionWriter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/CollectionWriter.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/CollectionWriter.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/CollectionWriter.java Thu Nov 10 21:48:45 2011
@@ -12,11 +12,15 @@ public interface CollectionWriter {
*/
<X extends CollectionWriter>X writeHeader(ASBase base);
+ <X extends CollectionWriter>X writeHeader(ASBase.Builder<?,?> base);
+
/**
* Writes an object to the items array of the Collection
*/
<X extends CollectionWriter>X writeObject(ASObject object);
+ <X extends CollectionWriter>X writeObject(ASObject.Builder<?,?> object);
+
/**
* Writes one or more objects to the items array of the Collection
*/
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/IO.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/IO.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/IO.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/IO.java Thu Nov 10 21:48:45 2011
@@ -28,10 +28,12 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import org.apache.abdera2.common.Discover;
-import org.apache.abdera2.common.anno.AnnoUtil;
+import org.apache.abdera2.activities.io.gson.GsonIO;
import org.apache.abdera2.common.anno.DefaultImplementation;
+import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableSet;
+
/**
* Primary interface for serializing/deserializing Activity objects.
* The write/parse operations on IO should be considered threadsafe,
@@ -49,18 +51,71 @@ import org.apache.abdera2.common.anno.De
* is to use two separate IO instances each configured with the
* appropriate property and object type mappings.
*/
-@DefaultImplementation("org.apache.abdera2.activities.io.gson.GsonIO")
public abstract class IO {
- protected boolean autoclose = false;
- protected String defcharset = "UTF-8";
-
- /**
- * True if streams and writers should be automatically closed when
- * the IO instance is done with them. Applies to both reads and writes
- */
- public void setAutoClose(boolean autoclose) {
- this.autoclose = true;
+ @DefaultImplementation("org.apache.abdera2.activities.io.gson.GsonIO.Builder")
+ public static abstract class Builder implements Supplier<IO> {
+
+ protected ImmutableSet.Builder<TypeAdapter<?>> adapters =
+ ImmutableSet.builder();
+ protected boolean autoclose;
+ protected boolean prettyprint;
+ protected String charset = "UTF-8";
+ public Builder autoClose() {
+ this.autoclose = true;
+ return this;
+ }
+ public Builder prettyPrint() {
+ this.prettyprint = true;
+ return this;
+ }
+ public Builder charset(String charset) {
+ this.charset = charset;
+ return this;
+ }
+
+ public Builder adapter(TypeAdapter<?> adapter) {
+ adapters.add(adapter);
+ return this;
+ }
+
+ public Builder adapter(TypeAdapter<?>... adapters) {
+ for (TypeAdapter<?> adapter : adapters)
+ adapter(adapter);
+ return this;
+ }
+
+ public Builder adapter(Iterable<TypeAdapter<?>> adapters) {
+ for (TypeAdapter<?> adapter : adapters)
+ adapter(adapter);
+ return this;
+ }
+
+ /**
+ * Adds a mapping of a property name to a specific value class. The
+ * serializer/deserializer will use this to select the appropriate
+ * type adapter for the property.
+ */
+ public abstract Builder property(String name, Class<?> _class);
+
+ /**
+ * Registers an appropriate objectType mapping for the object. This is
+ * used to automatically select an appropriate class for individual
+ * "objectType" values.
+ */
+ @SuppressWarnings("rawtypes")
+ public abstract <X extends ASObject.Builder>Builder object(Class<? extends X>... _class);
+
+ }
+
+ protected final boolean autoclose;
+ protected final boolean prettyPrint;
+ protected final String charset;
+
+ protected IO(Builder builder) {
+ this.autoclose = builder.autoclose;
+ this.prettyPrint = builder.prettyprint;
+ this.charset = builder.charset;
}
/**
@@ -71,29 +126,8 @@ public abstract class IO {
return autoclose;
}
- /**
- * Adds a mapping of a property name to a specific value class. The
- * serializer/deserializer will use this to select the appropriate
- * type adapter for the property.
- */
- public abstract void addPropertyMapping(String name, Class<?> _class);
-
- /**
- * Registers an appropriate objectType mapping for the object. This is
- * used to automatically select an appropriate class for individual
- * "objectType" values.
- */
- public abstract void addObjectMapping(Class<? extends ASObject>... _class);
-
- /**
- * Set the default character set used when parsing InputStreams
- */
- public void setDefaultCharset(String charset) {
- this.defcharset = charset!=null?charset:"UTF-8";
- }
-
public String getDefaultCharset() {
- return defcharset;
+ return charset;
}
public String write(
@@ -116,7 +150,7 @@ public abstract class IO {
try {
OutputStreamWriter writer =
new OutputStreamWriter(
- out,charset!=null?charset:defcharset);
+ out,charset!=null?charset:this.charset);
write(base,writer);
writer.flush();
} catch (Throwable t) {
@@ -203,19 +237,17 @@ public abstract class IO {
private static synchronized void set_cached(IO io, TypeAdapter<?>... adapters) {
map.put(new CacheKey(adapters),io);
}
+
+ public static Builder make() {
+ return new GsonIO.Builder();
+ }
public static IO get(TypeAdapter<?>... adapters) {
IO io = get_cached(adapters);
if (io == null) {
- String defaultImpl =
- AnnoUtil.getDefaultImplementation(IO.class);
- io = Discover.locate(
- IO.class,
- defaultImpl,
- (Object)adapters);
- if (io != null)
- set_cached(io,adapters);
- }
+ io = new GsonIO.Builder().adapter(adapters).get();
+ set_cached(io,adapters);
+ }
return io;
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/MediaLink.java Thu Nov 10 21:48:45 2011
@@ -17,106 +17,112 @@
*/
package org.apache.abdera2.activities.model;
+import java.util.Map;
+
import org.apache.abdera2.common.iri.IRI;
/**
* Represents the Activity Streams Media Link construct.
*/
-public class MediaLink extends ASBase {
+public final class MediaLink extends ASBase {
- private static final long serialVersionUID = -2003166656259290419L;
public static final String DURATION = "duration";
public static final String HEIGHT = "height";
public static final String WIDTH = "width";
public static final String URL = "url";
- public MediaLink() {}
-
- public MediaLink(IRI url) {
- setUrl(url);
- }
-
- public MediaLink(
- IRI url,
- int height,
- int width,
- int duration) {
- setUrl(url);
- setHeight(height);
- setWidth(width);
- setDuration(duration);
- }
-
- public int getDuration() {
- return (Integer)getProperty(DURATION);
- }
-
- public void setDuration(int duration) {
- setProperty(DURATION, duration < 0 ? null : duration);
- }
-
- public int getHeight() {
- return (Integer)getProperty(HEIGHT);
- }
-
- public void setHeight(int height) {
- setProperty(HEIGHT, height < 0 ? null : height);
- }
-
- public int getWidth() {
- return (Integer)getProperty(WIDTH);
- }
-
- public void setWidth(int width) {
- setProperty(WIDTH, width < 0 ? null : width);
+ public static Builder makeMediaLink() {
+ return new Builder();
}
- public IRI getUrl() {
- return getProperty(URL);
+ public static MediaLink makeMediaLink(String iri) {
+ return makeMediaLink().url(iri).get();
}
- public void setUrl(IRI url) {
- setProperty(URL, url);
+ public static MediaLink makeMediaLink(IRI iri) {
+ return makeMediaLink().url(iri).get();
}
- public void setUrl(String url) {
- setUrl(new IRI(url));
+ public static MediaLink makeMediaLink(
+ String iri,
+ int height,
+ int width,
+ int duration) {
+ return makeMediaLink()
+ .url(iri)
+ .height(height)
+ .width(width)
+ .duration(duration)
+ .get();
}
- public static MediaLinkGenerator makeMediaLink() {
- return new MediaLinkGenerator();
+ public static MediaLink makeMediaLink(
+ IRI iri,
+ int height,
+ int width,
+ int duration) {
+ return makeMediaLink()
+ .url(iri)
+ .height(height)
+ .width(width)
+ .duration(duration)
+ .get();
}
- public static class MediaLinkGenerator extends Generator<MediaLink> {
+ public final static class Builder
+ extends ASBase.Builder<MediaLink,Builder> {
- public MediaLinkGenerator() {
- super(MediaLink.class);
+ public Builder() {
+ super(MediaLink.class,Builder.class);
}
- public MediaLinkGenerator duration(int duration) {
- item.setDuration(duration);
- return this;
+ public Builder(Map<String,Object> map) {
+ super(map,MediaLink.class,Builder.class);
}
- public MediaLinkGenerator height(int height) {
- item.setHeight(height);
+ public Builder duration(int duration) {
+ set(DURATION,Math.max(0,duration));
return this;
}
- public MediaLinkGenerator width(int width) {
- item.setWidth(width);
+ public Builder height(int height) {
+ set(HEIGHT,Math.max(0,height));
return this;
}
- public MediaLinkGenerator url(IRI iri) {
- item.setUrl(iri);
+ public Builder width(int width) {
+ set(WIDTH,Math.max(0,width));
return this;
}
- public MediaLinkGenerator url(String uri) {
- item.setUrl(new IRI(uri));
+ public Builder url(IRI iri) {
+ set(URL,iri);
return this;
}
+
+ public Builder url(String uri) {
+ return url(new IRI(uri));
+ }
+ }
+
+ MediaLink(Map<String,Object> map) {
+ super(map,Builder.class,MediaLink.class);
+ }
+
+ public int getDuration() {
+ return (Integer)getProperty(DURATION);
+ }
+
+ public int getHeight() {
+ return (Integer)getProperty(HEIGHT);
+ }
+
+ public int getWidth() {
+ return (Integer)getProperty(WIDTH);
+ }
+
+ public IRI getUrl() {
+ return getProperty(URL);
}
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AccountObject.java Thu Nov 10 21:48:45 2011
@@ -1,68 +1,82 @@
package org.apache.abdera2.activities.model.objects;
+import java.util.Map;
+
+import org.apache.abdera2.activities.model.ASObject;
import org.apache.abdera2.common.anno.Name;
-@Name("account")
public class AccountObject
extends ServiceObject {
- private static final long serialVersionUID = 1058258637558799759L;
- public AccountObject() {
- super();
+ public AccountObject(Map<String,Object> map) {
+ super(map,AccountBuilder.class,AccountObject.class);
}
-
- public AccountObject(String displayName) {
- super(displayName);
+
+ public <X extends AccountObject, M extends Builder<X,M>>AccountObject(Map<String,Object> map, Class<M> _class, Class<X> _obj) {
+ super(map,_class,_obj);
}
public String getDomain() {
return getProperty("domain");
}
- public void setDomain(String domain) {
- setProperty("domain", domain);
- }
-
public String getUsername() {
return getProperty("username");
}
- public void setUsername(String username) {
- setProperty("username", username);
- }
-
public String getUserId() {
return getProperty("userId");
}
- public void setUserId(String userid) {
- setProperty("userId", userid);
+ public static AccountBuilder makeAccount() {
+ return new AccountBuilder("account");
}
- public static <T extends AccountObject>AccountGenerator<T> makeAccount() {
- return new AccountGenerator<T>();
+ public static AccountObject makeAccount(String domain, String username, String userid) {
+ return makeAccount()
+ .domain(domain)
+ .username(username)
+ .userId(userid)
+ .get();
+ }
+
+ @Name("account")
+ public static class AccountBuilder extends Builder<AccountObject,AccountBuilder> {
+ public AccountBuilder() {
+ super(AccountObject.class,AccountBuilder.class);
+ }
+ public AccountBuilder(Map<String, Object> map) {
+ super(map,AccountObject.class,AccountBuilder.class);
+ }
+ public AccountBuilder(String objectType) {
+ super(objectType, AccountObject.class,AccountBuilder.class);
+ }
}
@SuppressWarnings("unchecked")
- public static class AccountGenerator<T extends AccountObject> extends ServiceObjectGenerator<T> {
- public AccountGenerator() {
- super((Class<? extends T>) AccountObject.class);
- }
- public AccountGenerator(Class<T> _class) {
- super(_class);
- }
- public <X extends AccountGenerator<T>>X domain(String domain) {
- item.setDomain(domain);
- return (X)this;
- }
- public <X extends AccountGenerator<T>>X username(String username) {
- item.setUsername(username);
- return (X)this;
- }
- public <X extends AccountGenerator<T>>X userId(String userid) {
- item.setUserId(userid);
- return (X)this;
+ public static abstract class Builder<X extends AccountObject,M extends Builder<X,M>>
+ extends ASObject.Builder<X,M> {
+ public Builder(Class<X>_class,Class<M>_builder) {
+ super(_class,_builder);
+ }
+ public Builder(String objectType,Class<X>_class,Class<M>_builder) {
+ super(objectType,_class,_builder);
+ }
+ public Builder(Map<String,Object> map,Class<X>_class,Class<M>_builder) {
+ super(map,_class,_builder);
+ }
+ public M domain(String domain) {
+ set("domain",domain);
+ return (M)this;
+ }
+ public M username(String username) {
+ set("username",username);
+ return (M)this;
}
+ public M userId(String userid) {
+ set("userId",userid);
+ return (M)this;
+ }
}
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AdditionalEventProperties.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AdditionalEventProperties.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AdditionalEventProperties.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AdditionalEventProperties.java Thu Nov 10 21:48:45 2011
@@ -14,13 +14,17 @@ import org.apache.abdera2.activities.mod
*/
public interface AdditionalEventProperties {
<T extends ASObject>T getHost();
- void setHost(ASObject host);
<T extends ASObject>T getOffers();
- void setOffers(ASObject offers);
<T extends ASObject>T getSubEvents();
- void setSubEvents(ASObject subEvents);
<T extends ASObject>T getSuperEvent();
- void setSuperEvent(ASObject superEvent);
<T extends ASObject>T getPerformers();
- void setPerformers(ASObject performers);
+
+ public static interface Builder {
+ Builder host(ASObject host);
+ Builder offers(ASObject offers);
+ Builder subEvents(ASObject subEvents);
+ Builder superEvent(ASObject superEvent);
+ Builder performers(ASObject performers);
+ }
+
}
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/Address.java Thu Nov 10 21:48:45 2011
@@ -17,13 +17,13 @@
*/
package org.apache.abdera2.activities.model.objects;
+import java.util.Map;
+
import org.apache.abdera2.activities.model.ASObject;
import org.apache.abdera2.common.anno.Name;
-@Name("address")
public class Address extends ASObject {
- private static final long serialVersionUID = -6352046844998504401L;
public static final String FORMATTED = "formatted";
public static final String STREETADDRESS = "streetAddress";
public static final String LOCALITY = "locality";
@@ -31,54 +31,38 @@ public class Address extends ASObject {
public static final String POSTALCODE = "postalCode";
public static final String COUNTRY = "country";
- public String getFormatted() {
- return getProperty(FORMATTED);
+ public Address(Map<String,Object> map) {
+ super(map,AddressBuilder.class,Address.class);
}
- public void setFormatted(String formatted) {
- setProperty(FORMATTED, formatted);
+ public <X extends Address, M extends Builder<X,M>>Address(Map<String,Object> map, Class<M> _class,Class<X>_obj) {
+ super(map,_class,_obj);
}
- public String getStreetAddress() {
- return getProperty(STREETADDRESS);
+ public String getFormatted() {
+ return getProperty(FORMATTED);
}
- public void setStreetAddress(String streetAddress) {
- setProperty(STREETADDRESS, streetAddress);
+ public String getStreetAddress() {
+ return getProperty(STREETADDRESS);
}
public String getLocality() {
return getProperty(LOCALITY);
}
- public void setLocality(String locality) {
- setProperty(LOCALITY, locality);
- }
-
public String getRegion() {
return getProperty(REGION);
}
- public void setRegion(String region) {
- setProperty(REGION, region);
- }
-
public String getPostalCode() {
return getProperty(POSTALCODE);
}
- public void setPostalCode(String postalCode) {
- setProperty(POSTALCODE, postalCode);
- }
-
public String getCountry() {
return getProperty(COUNTRY);
}
- public void setCountry(String country) {
- setProperty(COUNTRY, country);
- }
-
public String toString() {
StringBuilder buf = new StringBuilder();
if (getFormatted() != null) {
@@ -89,41 +73,58 @@ public class Address extends ASObject {
return buf.toString();
}
- public static <T extends Address>AddressGenerator<T> makeAddress() {
- return new AddressGenerator<T>();
+ public static AddressBuilder makeAddress() {
+ return new AddressBuilder("address");
+ }
+
+ @Name("address")
+ public static class AddressBuilder extends Builder<Address,AddressBuilder> {
+ public AddressBuilder() {
+ super(Address.class,AddressBuilder.class);
+ }
+ public AddressBuilder(Map<String, Object> map) {
+ super(map, Address.class,AddressBuilder.class);
+ }
+ public AddressBuilder(String objectType) {
+ super(objectType, Address.class,AddressBuilder.class);
+ }
}
@SuppressWarnings("unchecked")
- public static class AddressGenerator<T extends Address> extends ASObjectGenerator<T> {
- public AddressGenerator() {
- super((Class<? extends T>) Address.class);
- }
- public AddressGenerator(Class<T> _class) {
- super(_class);
- }
- public <X extends AddressGenerator<T>>X country(String country) {
- item.setCountry(country);
- return (X)this;
- }
- public <X extends AddressGenerator<T>>X formatted(String formatted) {
- item.setFormatted(formatted);
- return (X)this;
- }
- public <X extends AddressGenerator<T>>X locality(String locality) {
- item.setLocality(locality);
- return (X)this;
- }
- public <X extends AddressGenerator<T>>X postalCode(String postalCode) {
- item.setPostalCode(postalCode);
- return (X)this;
- }
- public <X extends AddressGenerator<T>>X region(String region) {
- item.setRegion(region);
- return (X)this;
- }
- public <X extends AddressGenerator<T>>X streetAddress(String address) {
- item.setStreetAddress(address);
- return (X)this;
+ public static abstract class Builder<X extends Address, M extends Builder<X,M>>
+ extends ASObject.Builder<X,M> {
+ public Builder(Class<X> _class, Class<M> _builder) {
+ super(_class,_builder);
+ }
+ public Builder(String objectType,Class<X> _class, Class<M> _builder) {
+ super(objectType,_class,_builder);
+ }
+ public Builder(Map<String,Object> map,Class<X> _class, Class<M> _builder) {
+ super(map,_class,_builder);
+ }
+ public M country(String country) {
+ set(COUNTRY,country);
+ return (M)this;
+ }
+ public M formatted(String formatted) {
+ set(FORMATTED,formatted);
+ return (M)this;
+ }
+ public M locality(String locality) {
+ set(LOCALITY,locality);
+ return (M)this;
+ }
+ public M postalCode(String postalCode) {
+ set(POSTALCODE,postalCode);
+ return (M)this;
+ }
+ public M region(String region) {
+ set(REGION, region);
+ return (M)this;
+ }
+ public M streetAddress(String address) {
+ set(STREETADDRESS,address);
+ return (M)this;
}
}
}
Added: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AlertObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AlertObject.java?rev=1200583&view=auto
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AlertObject.java (added)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AlertObject.java Thu Nov 10 21:48:45 2011
@@ -0,0 +1,155 @@
+package org.apache.abdera2.activities.model.objects;
+
+import java.util.Map;
+
+import org.apache.abdera2.activities.io.gson.Properties;
+import org.apache.abdera2.activities.io.gson.Property;
+import org.apache.abdera2.activities.model.ASObject;
+import org.apache.abdera2.common.anno.Name;
+import org.apache.abdera2.common.date.DateTimes;
+import org.joda.time.DateTime;
+
+import static java.lang.Math.*;
+
+public class AlertObject
+ extends ASObject {
+
+
+ public AlertObject(Map<String,Object> map) {
+ super(map,AlertBuilder.class,AlertObject.class);
+ }
+
+ public <X extends AlertObject, M extends Builder<X,M>>AlertObject(Map<String,Object> map, Class<M> _class, Class<X> _obj) {
+ super(map,_class,_obj);
+ }
+
+ public static final String CERTAINTY = "certainty";
+ public static final String SEVERITY = "severity";
+ public static final String URGENCY = "urgency";
+ public static final String EFFECTIVE = "effective";
+ public static final String ONSET = "onset";
+ public static final String EXPIRES = "expires";
+
+ /**
+ * Certainty is established using a range between 0.0 and 1.0
+ * where 0.0 indicates 0% likelihood of occurrence, and 1.0
+ * indicates 100% likelihood.
+ */
+ public double getCertainty() {
+ double c = (Double)getProperty(CERTAINTY);
+ return min(1.0,max(0.00, c));
+ }
+
+ /**
+ * Severity is established using a range between 0 and 100,
+ * where 1 indicates the highest possible severity and
+ * 100 indicates the lowest, and 0 indicates a system-defined
+ * default severity
+ */
+ public int getSeverity() {
+ int i = (Integer)getProperty(SEVERITY);
+ return min(100,max(0,i));
+ }
+
+ /**
+ * Urgency is established using a range between 0 and 100,
+ * where 1 indicates the highest possible urgency and
+ * 100 indicates the lowest, and 0 indicates a system-defined
+ * default urgency
+ */
+ public int getUrgency() {
+ int i = (Integer)getProperty(SEVERITY);
+ return min(100,max(0,i));
+ }
+
+ public DateTime getEffective() {
+ return getProperty(EFFECTIVE);
+ }
+
+ public DateTime getOnset() {
+ return getProperty(ONSET);
+ }
+
+ public DateTime getExpires() {
+ return getProperty(EXPIRES);
+ }
+
+ public static AlertBuilder makeAlert() {
+ return new AlertBuilder("alert");
+ }
+
+ public static AlertBuilder makeAlert(
+ double certainty,
+ int severity,
+ int urgency) {
+ return makeAlert()
+ .certainty(certainty)
+ .severity(severity)
+ .urgency(urgency);
+ }
+
+ @Name("alert")
+ @Properties({
+ @Property(name="expires",to=DateTime.class),
+ @Property(name="onset",to=DateTime.class),
+ @Property(name="effective",to=DateTime.class)
+ })
+ public static class AlertBuilder extends Builder<AlertObject,AlertBuilder> {
+ public AlertBuilder() {
+ super(AlertObject.class,AlertBuilder.class);
+ }
+ public AlertBuilder(Map<String, Object> map) {
+ super(map, AlertObject.class,AlertBuilder.class);
+ }
+ public AlertBuilder(String objectType) {
+ super(objectType, AlertObject.class,AlertBuilder.class);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static abstract class Builder<X extends AlertObject,M extends Builder<X,M>>
+ extends ASObject.Builder<X,M> {
+ public Builder(Class<X>_class,Class<M>_builder) {
+ super(_class,_builder);
+ }
+ public Builder(String objectType,Class<X>_class,Class<M>_builder) {
+ super(objectType,_class,_builder);
+ }
+ public Builder(Map<String,Object> map,Class<X>_class,Class<M>_builder) {
+ super(map,_class,_builder);
+ }
+ public M expires(DateTime expires) {
+ set(EXPIRES, expires);
+ return (M)this;
+ }
+ public M expiresNow() {
+ return expires(DateTimes.now());
+ }
+ public M onset(DateTime onset) {
+ set(ONSET,onset);
+ return (M)this;
+ }
+ public M onsetNow() {
+ return onset(DateTimes.now());
+ }
+ public M effective(DateTime effective) {
+ set(EFFECTIVE,effective);
+ return (M)this;
+ }
+ public M effectiveNow() {
+ return effective(DateTimes.now());
+ }
+ public M certainty(double c) {
+ set(CERTAINTY,min(1.0,max(0.00,c)));
+ return (M)this;
+ }
+ public M severity(int c) {
+ set(SEVERITY,min(100,max(0,c)));
+ return (M)this;
+ }
+ public M urgency(int c) {
+ set(URGENCY,min(100,max(0,c)));
+ return (M)this;
+ }
+ }
+}
Propchange: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AlertObject.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/ArticleObject.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/ArticleObject.java?rev=1200583&r1=1200582&r2=1200583&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/ArticleObject.java (original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/ArticleObject.java Thu Nov 10 21:48:45 2011
@@ -17,32 +17,36 @@
*/
package org.apache.abdera2.activities.model.objects;
+import java.util.Map;
+
import org.apache.abdera2.activities.model.ASObject;
import org.apache.abdera2.common.anno.Name;
-@Name("article")
public class ArticleObject
extends ASObject {
-
- private static final long serialVersionUID = -9127545085992655433L;
- public ArticleObject() {}
+ public static <T extends ArticleObject>Builder makeArticle() {
+ return new Builder("article");
+ }
- public ArticleObject(String displayName) {
- setDisplayName(displayName);
+ @Name("article")
+ public static class Builder extends ASObject.Builder<ArticleObject,Builder> {
+ public Builder() {
+ super(ArticleObject.class,Builder.class);
+ }
+ public Builder(String objectType) {
+ super(objectType,ArticleObject.class,Builder.class);
+ }
+ public Builder(Map<String,Object> map) {
+ super(map,ArticleObject.class,Builder.class);
+ }
}
- public static <T extends ArticleObject>ArticleObjectGenerator<T> makeArticle() {
- return new ArticleObjectGenerator<T>();
+ public ArticleObject(Map<String,Object> map) {
+ super(map,Builder.class,ArticleObject.class);
}
- public static class ArticleObjectGenerator<T extends ArticleObject> extends ASObjectGenerator<T> {
- @SuppressWarnings("unchecked")
- public ArticleObjectGenerator() {
- super((Class<? extends T>) ArticleObject.class);
- }
- public ArticleObjectGenerator(Class<? extends T> _class) {
- super(_class);
- }
+ public <X extends ArticleObject, M extends ASObject.Builder<X,M>>ArticleObject(Map<String,Object> map, Class<M> _class, Class<X>_obj) {
+ super(map,_class,_obj);
}
}