cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r557523 - in /cocoon/trunk/core/cocoon-expression-language: cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ cocoon-expression-...
Date Thu, 19 Jul 2007 08:43:26 GMT
Author: gkossakowski
Date: Thu Jul 19 01:43:23 2007
New Revision: 557523

URL: http://svn.apache.org/viewvc?view=rev&rev=557523
Log:
Merged objectmodel branch changes r556277:557520 into trunk.

Added:
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/
      - copied from r557522, cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
  (contents, props changed)
      - copied, changed from r557522, cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
Modified:
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/Expression.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ExpressionContext.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/ExpressionTestCase.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/javascript/JavaScriptTestCase.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jexl/JexlTestCase.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/environment/FOMTestCase.java

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/Expression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/Expression.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/Expression.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/Expression.java
Thu Jul 19 01:43:23 2007
@@ -18,18 +18,20 @@
 
 import java.util.Iterator;
 
+import org.apache.cocoon.objectmodel.ObjectModel;
+
 /**
  * @version $Id$
  */
 public interface Expression {
 
-    Object evaluate(ExpressionContext context)
+    Object evaluate(ObjectModel objectModel)
             throws ExpressionException;
 
-    Iterator iterate(ExpressionContext context)
+    Iterator iterate(ObjectModel objectModel)
             throws ExpressionException;
 
-    void assign(ExpressionContext context, Object value)
+    void assign(ObjectModel objectModel, Object value)
             throws ExpressionException;
 
     String getExpression();
@@ -43,7 +45,7 @@
      * get rid of the getNode method, but have not yet figured out how to get
      * work in JXTG
      */
-    Object getNode(ExpressionContext context) throws ExpressionException;
+    Object getNode(ObjectModel objectModel) throws ExpressionException;
 
     void setProperty(String property, Object value);
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ExpressionContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ExpressionContext.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ExpressionContext.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/components/expression/ExpressionContext.java
Thu Jul 19 01:43:23 2007
@@ -19,6 +19,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.xml.NamespacesTable;
 
 /**
@@ -29,6 +30,11 @@
     private ExpressionContext closure;
     private Object contextBean;
     private NamespacesTable namespaces;
+    /**
+     * This variable will hold instance of a new {@link ObjectModel} implementation.
+     * <b>It's totally a temporary solution!</b>
+     */
+    private ObjectModel objectModel;
 
     public ExpressionContext() {
         this(null);
@@ -89,5 +95,13 @@
             result = closure.get(key);
         }
         return result;
+    }
+
+    public ObjectModel getObjectModel() {
+        return objectModel;
+    }
+
+    public void setObjectModel(ObjectModel objectModel) {
+        this.objectModel = objectModel;
     }
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ObjectModel.java
Thu Jul 19 01:43:23 2007
@@ -16,13 +16,36 @@
  */
 package org.apache.cocoon.objectmodel;
 
+import java.util.Map;
+
 import org.apache.commons.collections.MultiMap;
 
 /**
- * ObjectModel is just a {@link MultiMap} with little more constrained contracts.
+ * ObjectModel is a special {@link Map} that can have multiple values associated to the same
key. If there is only one
+ * value associated with key then ObjectModel will behave exactly as {@link Map}. If there
is more than one value associated with
+ * key then ObjectModel's methods will operate on {@link java.util.Collection Collections}
associated with key. 
  * 
- * The only difference is that Collection for each key is compliant with LIFO list constracts.

+ * Another constrain is that {@link java.util.Collection} for each key is compliant with
LIFO list constracts. 
  */
 public interface ObjectModel extends MultiMap {
+    
+    public static final String CONTEXTBEAN = "contextBean";
+    public static final String NAMESPACE = "namespace";
 
+    
+    /** 
+     * This method behaves almost exactly as {@link MultiMap#get(Object)} method. The only
difference is that value itself is returned
+     * 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/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/javascript/JavaScriptExpression.java
Thu Jul 19 01:43:23 2007
@@ -21,7 +21,7 @@
 import java.io.StringReader;
 
 import org.apache.cocoon.components.expression.AbstractExpression;
-import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.components.expression.ExpressionException;
 import org.apache.cocoon.components.expression.jexl.JSIntrospector;
 import org.apache.cocoon.components.flow.javascript.JavaScriptFlowHelper;
@@ -59,12 +59,12 @@
         }
     }
 
-    public Object evaluate(ExpressionContext context) throws ExpressionException {
+    public Object evaluate(ObjectModel objectModel) throws ExpressionException {
         Context ctx = Context.enter();
         try {
             Scriptable scope = ctx.newObject(FlowObjectModelHelper.getScope());
             // Populate the scope
-            Iterator iter = context.entrySet().iterator();
+            Iterator iter = objectModel.entrySet().iterator();
             while (iter.hasNext()) {
                 Map.Entry entry = (Map.Entry) iter.next();
                 String key = (String) entry.getKey();
@@ -87,8 +87,8 @@
         }
     }
 
-    public Iterator iterate(ExpressionContext context) throws ExpressionException {
-        Object result = evaluate(context);
+    public Iterator iterate(ObjectModel objectModel) throws ExpressionException {
+        Object result = evaluate(objectModel);
         if (result == null)
             return EMPTY_ITER;
 
@@ -107,11 +107,11 @@
         return iter;
     }
 
-    public void assign(ExpressionContext context, Object value) throws ExpressionException
{
+    public void assign(ObjectModel objectModel, Object value) throws ExpressionException
{
         throw new UnsupportedOperationException("assignment not implemented for javascript
expressions");
     }
 
-    public Object getNode(ExpressionContext context) throws ExpressionException {
-        return evaluate(context);
+    public Object getNode(ObjectModel objectModel) throws ExpressionException {
+        return evaluate(objectModel);
     }
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jexl/JexlExpression.java
Thu Jul 19 01:43:23 2007
@@ -21,7 +21,7 @@
 import java.util.Map;
 
 import org.apache.cocoon.components.expression.AbstractExpression;
-import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.components.expression.ExpressionException;
 import org.apache.commons.jexl.JexlContext;
 import org.apache.commons.jexl.util.Introspector;
@@ -43,17 +43,17 @@
         }
     }
 
-    public Object evaluate(ExpressionContext context) throws ExpressionException {
+    public Object evaluate(ObjectModel objectModel) throws ExpressionException {
         try {
-            return this.compiledExpression.evaluate(new ContextAdapter(context));
+            return this.compiledExpression.evaluate(new ContextAdapter(objectModel));
         } catch (Exception e) {
             throw new ExpressionException("Couldn't evaluate expression " + getExpression(),
e);
         }
     }
 
-    public Iterator iterate(ExpressionContext context) throws ExpressionException {
+    public Iterator iterate(ObjectModel objectModel) throws ExpressionException {
         Iterator iter = null;
-        Object result = evaluate(context);
+        Object result = evaluate(objectModel);
         if (result != null) {
             /*
              * The Info object is supposed to contain the script location where
@@ -74,27 +74,27 @@
         return iter;
     }
 
-    public void assign(ExpressionContext context, Object value) throws ExpressionException
{
+    public void assign(ObjectModel objectModel, Object value) throws ExpressionException
{
         throw new UnsupportedOperationException("Assign is not yet implemented for Jexl");
     }
 
-    public Object getNode(ExpressionContext context) throws ExpressionException {
-        return evaluate(context);
+    public Object getNode(ObjectModel objectModel) throws ExpressionException {
+        return evaluate(objectModel);
     }
 
     private static class ContextAdapter implements JexlContext {
-        private final ExpressionContext context;
+        private Map objectModel;
 
-        public ContextAdapter(ExpressionContext context) {
-            this.context = context;
+        public ContextAdapter(Map objectModel) {
+            this.objectModel = objectModel;
         }
 
         public Map getVars() {
-            return this.context.getVars();
+            return this.objectModel;
         }
 
         public void setVars(Map map) {
-            this.context.setVars(map);
+            this.objectModel = map;
         }
     }
 

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/components/expression/jxpath/JXPathExpression.java
Thu Jul 19 01:43:23 2007
@@ -21,10 +21,12 @@
 import java.util.List;
 
 import org.apache.cocoon.components.expression.Expression;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.expression.ExpressionException;
 import org.apache.cocoon.components.expression.jexl.JSIntrospector;
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.util.jxpath.NamespacesTablePointer;
+import org.apache.cocoon.xml.NamespacesTable;
+import org.apache.commons.collections.ArrayStack;
 import org.apache.commons.jxpath.CompiledExpression;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.jxpath.Pointer;
@@ -50,14 +52,14 @@
         this.compiledExpression = JXPathContext.compile(expression);
     }
 
-    public Object evaluate(ExpressionContext context)
+    public Object evaluate(ObjectModel objectModel)
         throws ExpressionException{
-        return this.compiledExpression.getValue(getContext(context));
+        return this.compiledExpression.getValue(getContext(objectModel));
     }
 
-    public Iterator iterate(ExpressionContext context)
+    public Iterator iterate(ObjectModel objectModel)
         throws ExpressionException {
-        final JXPathContext jxpathContext = getContext(context);
+        final JXPathContext jxpathContext = getContext(objectModel);
         Object val =
             this.compiledExpression.getPointer(jxpathContext, this.expression).getNode();
         // FIXME: workaround for JXPath bug
@@ -82,9 +84,9 @@
                 };
     }
 
-    public void assign(ExpressionContext context, Object value)
+    public void assign(ObjectModel objectModel, Object value)
         throws ExpressionException {
-        this.compiledExpression.setValue(getContext(context), value);
+        this.compiledExpression.setValue(getContext(objectModel), value);
     }
 
     public String getExpression() {
@@ -101,9 +103,9 @@
     }
 
     // Hack: try to prevent JXPath from converting result to a String
-    public Object getNode(ExpressionContext context) throws ExpressionException {
+    public Object getNode(ObjectModel objectModel) throws ExpressionException {
         Iterator iter =
-            this.compiledExpression.iteratePointers(getContext(context));
+            this.compiledExpression.iteratePointers(getContext(objectModel));
         if (iter.hasNext()) {
             Pointer first = (Pointer)iter.next();
             if (iter.hasNext()) {
@@ -129,33 +131,40 @@
         return null;
     }
 
-    private JXPathContext getContext(ExpressionContext context) {
+    private JXPathContext getContext(ObjectModel objectModel) {
         // This could be made more efficient by caching the
         // JXPathContext within the Context object.
-        JXPathContext jxcontext = JXPathContext.newContext(context.getContextBean());
-        jxcontext.setVariables(new VariableAdapter(context));
-        jxcontext.setLenient(this.lenient);
-        jxcontext.setNamespaceContextPointer(new NamespacesTablePointer(context.getNamespaces()));
-        return jxcontext;
+        
+        Object contextBean = objectModel.get(ObjectModel.CONTEXTBEAN);
+        if (contextBean instanceof ArrayStack)
+            contextBean = ((ArrayStack) contextBean).peek();
+        JXPathContext jxobjectModel = JXPathContext.newContext(contextBean);
+        jxobjectModel.setVariables(new VariableAdapter(objectModel));
+        jxobjectModel.setLenient(this.lenient);
+        Object namespaces = objectModel.get(ObjectModel.NAMESPACE);
+        if (namespaces instanceof ArrayStack)
+            namespaces = ((ArrayStack)namespaces).peek();
+        jxobjectModel.setNamespaceContextPointer(new NamespacesTablePointer((NamespacesTable)namespaces));
+        return jxobjectModel;
     }
 
     private static class VariableAdapter implements Variables {
-        private ExpressionContext context;
+        private ObjectModel objectModel;
 
-        public VariableAdapter(ExpressionContext context) {
-            this.context = context;
+        public VariableAdapter(ObjectModel objectModel) {
+            this.objectModel = objectModel;
         }
 
         public void declareVariable(String name, Object value) {
-            this.context.put(name, value);
+            this.objectModel.put(name, value);
         }
 
         public Object getVariable(String name) {
-            return this.context.get(name);
+            return this.objectModel.get(name);
         }
 
         public boolean isDeclaredVariable(String name) {
-            return this.context.containsKey(name);
+            return this.objectModel.containsKey(name);
         }
 
         public void undeclareVariable(String name) {

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmodel/ObjectModelImpl.java
Thu Jul 19 01:43:23 2007
@@ -16,31 +16,36 @@
  */
 package org.apache.cocoon.objectmodel;
 
+import java.util.AbstractCollection;
+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.Factory;
+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.map.MultiValueMap;
+import org.apache.commons.collections.iterators.SingletonIterator;
+import org.apache.commons.collections.keyvalue.DefaultKeyValue;
+import org.apache.commons.collections.map.AbstractMapDecorator;
 
 /**
  * Prototype implementation of {@link ObjectModel} interface. It <b>must</b>
be initialized manually for now.
  *
  */
-public class ObjectModelImpl extends MultiValueMap implements ObjectModel {
-
+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(), new Factory() {
-        
-            public Object create() {
-                return new StackReversedIteration();
-            }
-        
-        });
+        super(new HashMap());
+        localContexts = new ArrayStack();
     }
-    
+
     private static class StackReversedIteration extends ArrayStack {
         
         public Iterator iterator() {
@@ -51,4 +56,144 @@
             throw new UnsupportedOperationException();
         }
     }
-}
+    
+    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);
+            return value;
+        }
+        else if (valuesForKey instanceof StackReversedIteration)
+            return ((StackReversedIteration) valuesForKey).add(value) ? value : null;
+        else {
+            StackReversedIteration stack = new StackReversedIteration();
+            stack.add(valuesForKey);
+            stack.add(value);
+            super.put(key, stack);
+            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);
+        if (valuesForKey == null)
+            return null;
+        else if (valuesForKey instanceof StackReversedIteration) {
+            StackReversedIteration stack = (StackReversedIteration)valuesForKey;
+            boolean changed = stack.remove(item);
+            if (stack.size() == 1) {
+                super.put(key, stack.pop());
+                changed = true;
+            }
+            return changed ? item : null;
+        } 
+        else
+            return super.remove(key);
+    }
+    
+    /**
+     * Gets the total size of the map by counting all the values.
+     *
+     * @return the total size of the map counting all values
+     */
+    public int totalSize() {
+        int total = 0;
+        Collection values = getMap().values();
+        for (Iterator it = values.iterator(); it.hasNext();) {
+            Object object = it.next();
+            if (object instanceof StackReversedIteration)
+                total += ((Collection) object).size();
+            else
+                total++;
+        }
+        return total;
+    }
+    
+    public Collection values() {
+        return new Values();
+    }
+    
+    private class Values extends AbstractCollection {
+        public Iterator iterator() {
+            final IteratorChain chain = new IteratorChain();
+            for (Iterator it = keySet().iterator(); it.hasNext();) {
+                Object key = it.next();
+                Object object = get(key);
+                if (object instanceof StackReversedIteration)
+                    chain.addIterator(new ValuesIterator(key));
+                else
+                    //TODO: Implement removing
+                    chain.addIterator(new SingletonIterator(object, false));
+            }
+            return chain;
+        }
+
+        public int size() {
+            return totalSize();
+        }
+
+        public void clear() {
+            ObjectModelImpl.this.clear();
+        }
+    }
+
+    /**
+     * Inner class that provides the values iterator.
+     */
+    private class ValuesIterator implements Iterator {
+        private final Object key;
+        private final Collection values;
+        private final Iterator iterator;
+
+        public ValuesIterator(Object key) {
+            this.key = key;
+            this.values = (Collection)getMap().get(key);
+            this.iterator = values.iterator();
+        }
+
+        public void remove() {
+            iterator.remove();
+            if (values.isEmpty()) {
+                ObjectModelImpl.this.remove(key);
+            }
+        }
+
+        public boolean hasNext() {
+            return iterator.hasNext();
+        }
+
+        public Object next() {
+            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/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/environment/FlowObjectModelHelper.java
Thu Jul 19 01:43:23 2007
@@ -19,10 +19,10 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper;
 import org.apache.cocoon.environment.TemplateObjectModelHelper;
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.mozilla.javascript.Context;
 import org.mozilla.javascript.NativeJavaPackage;
 import org.mozilla.javascript.Scriptable;
@@ -64,15 +64,17 @@
     /**
      * Create an expression context that contains the object model
      */
-    public static ExpressionContext getFOMExpressionContext(final Map objectModel, 
+    public static ObjectModel getNewObjectModelWithFOM(final Map objectModel, 
                                                             final Parameters parameters)
{
-        ExpressionContext context = new ExpressionContext();
         Map expressionContext = TemplateObjectModelHelper.getTemplateObjectModel(objectModel,
parameters);
-        FlowObjectModelHelper.addJavaPackages( expressionContext );
-        context.setVars( expressionContext );
-        context.setContextBean(FlowHelper.getContextObject(objectModel));
+        FlowObjectModelHelper.addJavaPackages(expressionContext);
+        
+        //FIXME: It's a temporary code!
+        org.apache.cocoon.objectmodel.ObjectModel newObjectModel = new org.apache.cocoon.objectmodel.ObjectModelImpl();
+        newObjectModel.putAll(expressionContext);
+        newObjectModel.put(org.apache.cocoon.objectmodel.ObjectModel.CONTEXTBEAN, FlowHelper.getContextObject(objectModel));
 
-        return context;
+        return newObjectModel;
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/ExpressionTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/ExpressionTestCase.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/ExpressionTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/ExpressionTestCase.java
Thu Jul 19 01:43:23 2007
@@ -17,33 +17,34 @@
 package org.apache.cocoon.components.expression;
 
 import org.apache.cocoon.CocoonTestCase;
+import org.apache.cocoon.objectmodel.ObjectModelImpl;
 
 public class ExpressionTestCase extends CocoonTestCase {
 
-    public void testContext() {
-        ExpressionContext parentContext = new ExpressionContext();
+    /*public void testContext() {
+        ObjectModel parentContext = new ObjectModelImpl();
         parentContext.put("var1", "foo");
         parentContext.put("var2", "bar");
 
-        ExpressionContext context = new ExpressionContext(parentContext);
-        context.put("var1", "zonk");
+        ObjectModel objectModel = new ObjectModel(parentContext);
+        objectModel.put("var1", "zonk");
 
         assertEquals("foo", parentContext.get("var1"));
         assertEquals("bar", parentContext.get("var2"));
-        assertEquals("zonk", context.get("var1"));
-        assertEquals("bar", context.get("var2"));
+        assertEquals("zonk", objectModel.get("var1"));
+        assertEquals("bar", objectModel.get("var2"));
     }
 
     public void testContextBean() {
-        ExpressionContext parentContext = new ExpressionContext();
+        ObjectModel parentContext = new ObjectModel();
         parentContext.setContextBean("foo");
 
-        ExpressionContext context = new ExpressionContext(parentContext);
-        context.setContextBean("bar");
+        ObjectModel objectModel = new ObjectModel(parentContext);
+        objectModel.setContextBean("bar");
 
         assertEquals("foo", parentContext.getContextBean());
-        assertEquals("bar", context.getContextBean());
-    }
+        assertEquals("bar", objectModel.getContextBean());
+    }*/
 
     public void testFactoryJexl() throws ExpressionException {
         ExpressionFactory factory = (ExpressionFactory) this.getBeanFactory().getBean(ExpressionFactory.ROLE);
@@ -52,7 +53,7 @@
         Expression expression = factory.getExpression("jexl", "1+2");
         assertNotNull("Test expression compilation", expression);
 
-        assertEquals(new Long(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Long(3), expression.evaluate(new ObjectModelImpl()));
     }
 
     public void testFactoryJXPath() throws ExpressionException {
@@ -62,7 +63,7 @@
         Expression expression = factory.getExpression("jxpath", "1+2");
         assertNotNull("Test expression compilation", expression);
 
-        assertEquals(new Double(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Double(3), expression.evaluate(new ObjectModelImpl()));
     }
 
     public void testFactoryPluggable() throws ExpressionException {
@@ -71,15 +72,15 @@
 
         Expression expression = factory.getExpression("1+2");
         assertNotNull("Test expression compilation", expression);
-        assertEquals(new Double(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Double(3), expression.evaluate(new ObjectModelImpl()));
 
         expression = factory.getExpression("jexl:1+2");
         assertNotNull("Test expression compilation", expression);
-        assertEquals(new Long(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Long(3), expression.evaluate(new ObjectModelImpl()));
 
         expression = factory.getExpression("jxpath:1+2");
         assertNotNull("Test expression compilation", expression);
-        assertEquals(new Double(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Double(3), expression.evaluate(new ObjectModelImpl()));
     }
 }
 

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/javascript/JavaScriptTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/javascript/JavaScriptTestCase.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/javascript/JavaScriptTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/javascript/JavaScriptTestCase.java
Thu Jul 19 01:43:23 2007
@@ -22,8 +22,9 @@
 
 import org.apache.cocoon.components.expression.Expression;
 import org.apache.cocoon.components.expression.ExpressionCompiler;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.expression.ExpressionException;
+import org.apache.cocoon.objectmodel.ObjectModel;
+import org.apache.cocoon.objectmodel.ObjectModelImpl;
 
 /**
  * @version $Id$
@@ -33,27 +34,27 @@
     public void testExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JavaScriptCompiler();
         Expression expression = compiler.compile("js", "1+2");
-        Object result = expression.evaluate(new ExpressionContext());
+        Object result = expression.evaluate(new ObjectModelImpl());
         assertEquals(new Integer(3), result);
     }
 
     public void testContextExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JavaScriptCompiler();
-        ExpressionContext context = new ExpressionContext();
-        context.put("a", new Long(1));
-        context.put("b", new Long(2));
+        ObjectModel objectModel = new ObjectModelImpl();
+        objectModel.put("a", new Long(1));
+        objectModel.put("b", new Long(2));
         Expression expression = compiler.compile("js", "a+b");
-        Object result = expression.evaluate(context);
+        Object result = expression.evaluate(objectModel);
         assertEquals(new Double(3), result);
     }
 
     public void testIterator() throws ExpressionException {
         ExpressionCompiler compiler = new JavaScriptCompiler();
-        ExpressionContext context = new ExpressionContext();
+        ObjectModel objectModel = new ObjectModelImpl();
         String[] arr = { "foo" };
-        context.put("arr", arr);
+        objectModel.put("arr", arr);
         Expression expression = compiler.compile("jexl", "arr");
-        Iterator iter = expression.iterate(context);
+        Iterator iter = expression.iterate(objectModel);
         assertTrue("hasNext", iter.hasNext());
         assertEquals("foo", iter.next());
         assertFalse("hasNext", iter.hasNext());

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jexl/JexlTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jexl/JexlTestCase.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jexl/JexlTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jexl/JexlTestCase.java
Thu Jul 19 01:43:23 2007
@@ -19,35 +19,37 @@
 import java.util.Iterator;
 
 import junit.framework.TestCase;
+
 import org.apache.cocoon.components.expression.Expression;
 import org.apache.cocoon.components.expression.ExpressionCompiler;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.expression.ExpressionException;
+import org.apache.cocoon.objectmodel.ObjectModel;
+import org.apache.cocoon.objectmodel.ObjectModelImpl;
 
 public class JexlTestCase extends TestCase {
 
     public void testExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JexlCompiler();
         Expression expression = compiler.compile("jexl", "1+2");
-        assertEquals(new Long(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Long(3), expression.evaluate(new ObjectModelImpl()));
     }
 
     public void testContextExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JexlCompiler();
-        ExpressionContext context = new ExpressionContext();
-        context.put("a", new Long(1));
-        context.put("b", new Long(2));
+        ObjectModel objectModel = new ObjectModelImpl();
+        objectModel.put("a", new Long(1));
+        objectModel.put("b", new Long(2));
         Expression expression = compiler.compile("jexl", "a+b");
-        assertEquals(new Long(3), expression.evaluate(context));
+        assertEquals(new Long(3), expression.evaluate(objectModel));
     }
 
     public void testIterator() throws ExpressionException {
         ExpressionCompiler compiler = new JexlCompiler();
-        ExpressionContext context = new ExpressionContext();
+        ObjectModel objectModel = new ObjectModelImpl();
         String[] arr = {"foo"};
-        context.put("arr", arr);
+        objectModel.put("arr", arr);
         Expression expression = compiler.compile("jexl", "arr");
-        Iterator iter = expression.iterate(context);
+        Iterator iter = expression.iterate(objectModel);
         assertTrue("hasNext", iter.hasNext());
         assertEquals("foo", iter.next());
         assertFalse("hasNext", iter.hasNext());

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/components/expression/jxpath/JXPathTestCase.java
Thu Jul 19 01:43:23 2007
@@ -16,40 +16,39 @@
  */
 package org.apache.cocoon.components.expression.jxpath;
 
-import java.util.Iterator;
-
 import junit.framework.TestCase;
+
 import org.apache.cocoon.components.expression.Expression;
 import org.apache.cocoon.components.expression.ExpressionCompiler;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.expression.ExpressionException;
+import org.apache.cocoon.objectmodel.ObjectModelImpl;
 
 public class JXPathTestCase extends TestCase {
 
     public void testExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JXPathCompiler();
         Expression expression = compiler.compile("jxpath", "1+2");
-        assertEquals(new Double(3), expression.evaluate(new ExpressionContext()));
+        assertEquals(new Double(3), expression.evaluate(new ObjectModelImpl()));
     }
 
-    public void testContextExpression() throws ExpressionException {
+    /*public void testContextExpression() throws ExpressionException {
         ExpressionCompiler compiler = new JXPathCompiler();
-        ExpressionContext context = new ExpressionContext();
-        context.put("a", new Long(1));
-        context.put("b", new Long(2));
+        ObjectModel objectModel = new ObjectModel();
+        objectModel.put("a", new Long(1));
+        objectModel.put("b", new Long(2));
         Expression expression = compiler.compile("jxpath", "$a+$b");
-        assertEquals(new Double(3), expression.evaluate(context));
+        assertEquals(new Double(3), expression.evaluate(objectModel));
     }
 
     public void testIterator() throws ExpressionException {
         ExpressionCompiler compiler = new JXPathCompiler();
-        ExpressionContext context = new ExpressionContext();
+        ObjectModel objectModel = new ObjectModel();
         String[] arr = {"foo"};
-        context.setContextBean(arr);
+        objectModel.setContextBean(arr);
         Expression expression = compiler.compile("jxpath", ".");
-        Iterator iter = expression.iterate(context);
+        Iterator iter = expression.iterate(objectModel);
         assertTrue("hasNext", iter.hasNext());
         assertEquals("foo", iter.next());
         assertFalse("!hasNext", iter.hasNext());
-    }
+    }*/
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/environment/FOMTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/environment/FOMTestCase.java?view=diff&rev=557523&r1=557522&r2=557523
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/environment/FOMTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/environment/FOMTestCase.java
Thu Jul 19 01:43:23 2007
@@ -17,41 +17,42 @@
 package org.apache.cocoon.environment;
 
 import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.SitemapComponentTestCase;
 import org.apache.cocoon.components.expression.Expression;
-import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.expression.ExpressionException;
 import org.apache.cocoon.components.expression.ExpressionFactory;
+import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.objectmodel.ObjectModel;
 import org.apache.cocoon.template.environment.FlowObjectModelHelper;
 
-public class FOMTestCase extends SitemapComponentTestCase {
+public class FOMTestCase extends ContainerTestCase {
 
     public void testFOMJexl() throws ExpressionException {
         ExpressionFactory factory = (ExpressionFactory) this.getBeanFactory().getBean(ExpressionFactory.ROLE);
         Parameters parameters = new Parameters();
         parameters.setParameter("test", "foo");
-        ExpressionContext fomContext =
-            FlowObjectModelHelper.getFOMExpressionContext(getObjectModel(), parameters);
+        ObjectModel objectModel =
+            FlowObjectModelHelper.getNewObjectModelWithFOM(getObjectModel(), parameters);
 
         Expression expression = factory.getExpression("jexl", "cocoon.parameters.test");
-        assertEquals("foo", expression.evaluate(fomContext));
+        assertEquals("foo", expression.evaluate(objectModel));
 
         expression = factory.getExpression("jexl", "cocoon.request.protocol");
-        assertEquals("HTTP/1.1", expression.evaluate(fomContext));
+        assertEquals("HTTP/1.1", expression.evaluate(objectModel));
     }
 
     public void testFOMJXPath() throws ExpressionException {
         ExpressionFactory factory = (ExpressionFactory) this.getBeanFactory().getBean(ExpressionFactory.ROLE);
         Parameters parameters = new Parameters();
         parameters.setParameter("test", "foo");
-        ExpressionContext fomContext =
-            FlowObjectModelHelper.getFOMExpressionContext(getObjectModel(), parameters);
+        ObjectModel objectModel =
+            FlowObjectModelHelper.getNewObjectModelWithFOM(getObjectModel(), parameters);
 
         Expression expression = factory.getExpression("jxpath", "$cocoon/parameters/test");
-        assertEquals("foo", expression.evaluate(fomContext));
+        assertEquals("foo", expression.evaluate(objectModel));
 
         expression = factory.getExpression("jxpath", "$cocoon/request/protocol");
-        assertEquals("HTTP/1.1", expression.evaluate(fomContext));
+        assertEquals("HTTP/1.1", expression.evaluate(objectModel));
     }
+    
 }
 

Copied: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
(from r557522, 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/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java?view=diff&rev=557523&p1=cocoon/whiteboard/objectmodel/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java&r1=557522&p2=cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java&r2=557523
==============================================================================
    (empty)

Propchange: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message