abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1201343 - in /abdera/abdera2: activities/src/main/java/org/apache/abdera2/activities/model/objects/ common/src/main/java/org/apache/abdera2/common/security/ examples/src/main/java/org/apache/abdera2/examples/activities/
Date Sat, 12 Nov 2011 22:10:29 GMT
Author: jmsnell
Date: Sat Nov 12 22:10:28 2011
New Revision: 1201343

URL: http://svn.apache.org/viewvc?rev=1201343&view=rev
Log: (empty)

Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/model/objects/AdditionalEventProperties.java
    abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/Activities.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/BinaryDataObjectExample.java
    abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/ExtendingBaseObjectExample.java

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=1201343&r1=1201342&r2=1201343&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
Sat Nov 12 22:10:28 2011
@@ -18,7 +18,8 @@
 package org.apache.abdera2.activities.model.objects;
 
 import org.apache.abdera2.activities.model.ASObject;
-
+import org.apache.abdera2.activities.extra.Extra.ExtensionObject;
+import org.apache.abdera2.activities.extra.Extra.ExtensionBuilder;
 /**
  * Additional extension properties for the EventObject...
  * attach this interface to an EventObject using the 
@@ -29,14 +30,16 @@ import org.apache.abdera2.activities.mod
  * avp.setOffers(...);
  * ...
  */
-public interface AdditionalEventProperties {
+public interface AdditionalEventProperties
+  extends ExtensionObject {
   <T extends ASObject>T getHost();
   <T extends ASObject>T getOffers();
   <T extends ASObject>T getSubEvents();
   <T extends ASObject>T getSuperEvent();
   <T extends ASObject>T getPerformers();
   
-  public static interface Builder {
+  public static interface Builder
+    extends ExtensionBuilder {
     Builder host(ASObject host);
     Builder offers(ASObject offers);
     Builder subEvents(ASObject subEvents);

Modified: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java?rev=1201343&r1=1201342&r2=1201343&view=diff
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java
(original)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/security/HashHelper.java
Sat Nov 12 22:10:28 2011
@@ -29,6 +29,7 @@ import java.util.Arrays;
 import javax.crypto.Mac;
 
 import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.selector.AbstractSelector;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.binary.Hex;
 
@@ -126,7 +127,8 @@ public final class HashHelper {
     }
   }
   
-  public static abstract class Hasher 
+  public static abstract class Hasher
+    extends AbstractSelector<String>
     implements Supplier<String> {
     public <T extends Hasher>T update(byte[] buf) {
       update(buf,0,buf.length);
@@ -140,6 +142,11 @@ public final class HashHelper {
     public String name() {
       return getClass().getSimpleName().toLowerCase();
     }
+    // checks to see if the passed in hash matches this one
+    public boolean select(Object check) {
+      if (check == null) return false;
+      return get().equalsIgnoreCase(check.toString());
+    }
   }
     
   public static Function<byte[],String> md5() {

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=1201343&r1=1201342&r2=1201343&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
Sat Nov 12 22:10:28 2011
@@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
 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.IO;
 import static org.apache.abdera2.activities.model.Verb.FOLLOW;
@@ -12,15 +13,24 @@ import static org.apache.abdera2.activit
 
 public class Activities {
 
+  
+  // The IO class is the main component for parsing/serializing
+  // acivity streams objects. They are immutable and threadsafe
+  // and can be safely set within a static final variable. 
+  // 
+  // Each IO Instance has it's own configuration of type adapters
+  // and property registrations that tell the deserializer how
+  // to interpret the input data. A single application can 
+  // utilize many individual IO instances if necessary, but 
+  // for most applications, one is all you'll ever actually need
+  private static final IO io = IO.get();
+  
+  
   public static void main(String... args) throws Exception {
     
-    // Simple Activities Example
-    IO io = IO.get();
-    
-    
     // A simple fluent factory model can be used to create 
     // activities and their associated objects... several
-    // of the methods here are statically imported so be
+    // of the methods used here are statically imported so be
     // sure to take a look at the import statements at 
     // the top of the class to see where various bits are 
     // coming from.
@@ -31,15 +41,11 @@ public class Activities {
     // once created
     Activity activity = 
       makeActivity()
-        .actor(
-          makePerson()
-            .displayName("James")
-            .get())
+        .actor(makePerson("James").get())
         .verb(FOLLOW)
         .object(
-          makePerson()
+          makePerson("John Doe")
             .email("john.doe@example.org")
-            .displayName("John Doe")
             .get())
         .get();
     

Modified: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/BinaryDataObjectExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/BinaryDataObjectExample.java?rev=1201343&r1=1201342&r2=1201343&view=diff
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/BinaryDataObjectExample.java
(original)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/activities/BinaryDataObjectExample.java
Sat Nov 12 22:10:28 2011
@@ -22,12 +22,11 @@ import static org.apache.abdera2.activit
  */
 public class BinaryDataObjectExample {
 
+  private final static IO io = IO.get();
+  
   public static void main(String... args) throws Exception {
     
-    IO io = IO.get();
-    
     // First prepare the data we wish to include
-    // within the object...
     URL url = BinaryDataObjectExample.class.getResource("/info.png");
     DataHandler dataHandler = new DataHandler(url); 
     
@@ -37,7 +36,7 @@ public class BinaryDataObjectExample {
         .attachment(
           makeBinary()
             .data(
-              dataHandler, 
+              dataHandler, // the data will be automatically base64 encoded
               new Md5(),   // generate an md5 hash and set an "md5" property.. we could also
do an hmac here
               DEFLATE)     // apply deflate compression to the data before encoding it
             .get())
@@ -63,8 +62,7 @@ public class BinaryDataObjectExample {
       check.update(buf, 0, r);
     
     // check the md5 hash to show that the input data and output data are the same
-    String checks = check.get();
-    System.out.println(checks.equalsIgnoreCase(md5));
+    check.checkElement(md5);
     
   }
   

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=1201343&r1=1201342&r2=1201343&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
Sat Nov 12 22:10:28 2011
@@ -1,11 +1,11 @@
 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;
+import static org.apache.abdera2.activities.model.objects.EventObject.makeEvent;
+import static org.apache.abdera2.activities.model.Collection.makeCollection;
+import static org.apache.abdera2.activities.model.objects.PersonObject.makePerson;
 
 /**
  * Quick example that shows how new object types can be
@@ -17,24 +17,19 @@ import org.apache.abdera2.activities.mod
 public class ExtendingBaseObjectExample {
 
   public static void main(String... args) throws Exception {
-    IO io = IO.get();
-    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
-    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");
+    makeEvent("hangout")
+      .extend(    // dynamically extend the builder using the specified interface...
+        AdditionalEventProperties.Builder.class)
+          .host(makePerson("James").get())
+          .performers(makePerson("Bob").get())
+          .<EventBuilder>unwrap()
+          .attending(
+            makeCollection()
+              .item(makePerson("Joe").get())
+            .get()).get().writeTo(
+              IO.get(),
+              System.out,
+              "UTF-8");
   }
   
 }



Mime
View raw message