abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1176208 - /abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java
Date Tue, 27 Sep 2011 05:43:21 GMT
Author: jmsnell
Date: Tue Sep 27 05:43:20 2011
New Revision: 1176208

URL: http://svn.apache.org/viewvc?rev=1176208&view=rev
Log:
Better handling of context resolution with lists and iterable values

Modified:
    abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java

Modified: abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java?rev=1176208&r1=1176207&r2=1176208&view=diff
==============================================================================
--- abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java
(original)
+++ abdera/abdera2/activities/src/main/java/org/apache/abdera2/activities/extra/ASContext.java
Tue Sep 27 05:43:20 2011
@@ -26,9 +26,15 @@ public final class ASContext 
     this.base = base;
   }
   
-  @SuppressWarnings("unchecked")
+  @SuppressWarnings({ "unchecked", "rawtypes" })
   public <T> T resolve(String var) {
-    return (T)base.getProperty(var);
+    Object obj = base.getProperty(var);
+    if (obj instanceof Iterable) {
+      return (T)new IterableWrapper((Iterable)obj);
+    }
+    return obj instanceof ASBase ? 
+      (T)new ASContext((ASBase)obj) :
+      (T)base.getProperty(var);
   }
 
   public void clear() {
@@ -42,4 +48,49 @@ public final class ASContext 
   public Iterator<String> iterator() {
     return base.iterator();
   }
+  
+  @SuppressWarnings("rawtypes")
+  public static class IterableWrapper 
+    implements Iterable {
+
+    private final Iterable i;
+    
+    IterableWrapper(Iterable i) {
+      this.i = i;
+    }
+    
+    public Iterator iterator() {
+      return new IteratorWrapper(i.iterator());
+    }
+    
+  }
+  
+  @SuppressWarnings("rawtypes")
+  public static class IteratorWrapper 
+    implements Iterator {
+
+    private final Iterator i;
+    
+    IteratorWrapper(Iterator i) {
+      this.i = i;
+    }
+    
+    public boolean hasNext() {
+      return i.hasNext();
+    }
+
+    public Object next() {
+      Object obj = i.next();
+      if (obj instanceof ASBase) 
+        return new ASContext((ASBase)obj);
+      if (obj instanceof Iterable)
+        return new IterableWrapper((Iterable)obj);
+      return obj;
+    }
+
+    public void remove() {
+      i.remove();
+    }
+    
+  }
 }
\ No newline at end of file



Mime
View raw message