cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r557305 - in /cocoon/whiteboard/objectmodel/cocoon-expression-language: cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ cocoon-expressi...
Date Wed, 18 Jul 2007 16:00:38 GMT
Author: gkossakowski
Date: Wed Jul 18 09:00:36 2007
New Revision: 557305

URL: http://svn.apache.org/viewvc?view=rev&rev=557305
Log:
COCOON-2086: Implemented local context helper methods for ObjectModel.

Modified:
    cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
    cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
    cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java

Modified: cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java?view=diff&rev=557305&r1=557304&r2=557305
==============================================================================
--- cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
(original)
+++ cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
Wed Jul 18 09:00:36 2007
@@ -37,4 +37,14 @@
      * instead of {@link java.util.Collection} containing that value.
      */
     public Object get(Object key);
+    
+    /**
+     * Marks new local context. Such mark is useful to do a clean up of entries. 
+     */
+    public void markLocalContext();
+    
+    /**
+     * Cleans up entries put to ObjectModel since last {@link #markLocalContext()} call.
+     */
+    public void cleanupLocalContext();
 }

Modified: cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java?view=diff&rev=557305&r1=557304&r2=557305
==============================================================================
--- cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
(original)
+++ cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
Wed Jul 18 09:00:36 2007
@@ -20,12 +20,16 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.ListIterator;
+import java.util.Map;
 
 import org.apache.commons.collections.ArrayStack;
+import org.apache.commons.collections.KeyValue;
 import org.apache.commons.collections.iterators.IteratorChain;
 import org.apache.commons.collections.iterators.ReverseListIterator;
 import org.apache.commons.collections.iterators.SingletonIterator;
+import org.apache.commons.collections.keyvalue.DefaultKeyValue;
 import org.apache.commons.collections.map.AbstractMapDecorator;
 
 /**
@@ -35,8 +39,11 @@
 public class ObjectModelImpl extends AbstractMapDecorator implements ObjectModel {
     //FIXME: It seems that there is no easy way to reuse MuliValueMap
     
+    private ArrayStack localContexts;
+    
     public ObjectModelImpl() {
         super(new HashMap());
+        localContexts = new ArrayStack();
     }
 
     private static class StackReversedIteration extends ArrayStack {
@@ -51,6 +58,9 @@
     }
     
     public Object put(Object key, Object value) {
+        if (!localContexts.empty())
+            ((Collection) localContexts.peek()).add(new DefaultKeyValue(key, value));
+        
         Object valuesForKey = getMap().get(key);
         if (valuesForKey == null) {
             super.put(key, value);
@@ -66,6 +76,18 @@
             return value;
         }
     }
+    
+    public void putAll(Map mapToCopy) {
+        if (!localContexts.empty()) {
+            Collection entries = (Collection)localContexts.peek();
+            for (Iterator keysIterator = mapToCopy.keySet().iterator(); keysIterator.hasNext();)
{
+                Object key = keysIterator.next();
+                entries.add(new DefaultKeyValue(key, mapToCopy.get(key)));
+            }
+        }
+        
+        super.putAll(mapToCopy);
+    }
 
     public Object remove(Object key, Object item) {
         Object valuesForKey = getMap().get(key);
@@ -159,5 +181,19 @@
             return iterator.next();
         }
     }
+
+    public void cleanupLocalContext() {
+        if (localContexts.empty())
+            throw new IllegalStateException("Local contexts stack is empty");
+        Collection removeEntries = (Collection)localContexts.pop();
+        for (Iterator entriesIterator = removeEntries.iterator(); entriesIterator.hasNext();)
{
+            KeyValue entry = (KeyValue) entriesIterator.next();
+            remove(entry.getKey(), entry.getValue());
+        }
+    }
+
+    public void markLocalContext() {
+        localContexts.push(new LinkedList());
+    }
     
-}
+}
\ No newline at end of file

Modified: cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java?view=diff&rev=557305&r1=557304&r2=557305
==============================================================================
--- cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
(original)
+++ cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
Wed Jul 18 09:00:36 2007
@@ -65,4 +65,23 @@
         assertEquals(false, values.contains("bar1"));
     }
     
+    public void testLocalContext() {
+        ObjectModel objectModel = new ObjectModelImpl();
+        
+        objectModel.put("foo", "bar1");
+        objectModel.markLocalContext();
+        objectModel.put("foo", "bar2");
+        objectModel.put("abc", "xyz");
+        
+        assertEquals(true, objectModel.values().contains("bar2"));
+        assertEquals(true, objectModel.values().contains("bar1"));
+        assertEquals(true, objectModel.containsKey("abc"));
+        
+        objectModel.cleanupLocalContext();
+        
+        assertEquals(false, objectModel.values().contains("bar2"));
+        assertEquals(true, objectModel.values().contains("bar1"));
+        assertEquals(false, objectModel.containsKey("abc"));
+    }
+    
 }



Mime
View raw message