cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r567656 - in /cocoon/trunk/core/cocoon-expression-language: cocoon-expression-language-api/ cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/ cocoon-expression-language-impl/src/main/java/org/apache/cocoon/objectmo...
Date Mon, 20 Aug 2007 11:13:16 GMT
Author: gkossakowski
Date: Mon Aug 20 04:13:15 2007
New Revision: 567656

URL: http://svn.apache.org/viewvc?rev=567656&view=rev
Log:
COCOON-2085: Introduced and implemented setParent() method in ObjectModel.
  * Method getAll() returns MultiMap now. Added dependency on commons-collections in cocoon-expression-language-api.
  * Implemented UnmodifiableMultiMap helper class.
  * Added test case for setParent().

Added:
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
  (with props)
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml
  (contents, props changed)
      - copied, changed from r567300, cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModel.xml
Removed:
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModel.xml
Modified:
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/pom.xml
    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/objectmodel/ObjectModelImpl.java
    cocoon/trunk/core/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/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/pom.xml?rev=567656&r1=567655&r2=567656&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/pom.xml (original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/pom.xml Mon
Aug 20 04:13:15 2007
@@ -51,4 +51,10 @@
     </site>
   </distributionManagement>
 
+  <dependencies>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+  </dependencies>
 </project>

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?rev=567656&r1=567655&r2=567656&view=diff
==============================================================================
--- 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
Mon Aug 20 04:13:15 2007
@@ -18,6 +18,8 @@
 
 import java.util.Map;
 
+import org.apache.commons.collections.MultiMap;
+
 /**
  * ObjectModel is a special {@link Map} that cannot be modified using standard {@link Map}
methods, except
  * {@link #put(Object, Object)} method.
@@ -33,11 +35,10 @@
     public static final String PARAMETERS_PATH = "cocoon/parameters";
 
     /**
-     * @return a {@link org.apache.commons.collections.MultiMap} that contains all stored
values in all context in
-     *         LIFO-compliant order. Returned {@link org.apache.commons.collections.MultiMap}
is
-     *         {@link org.apache.commons.collections.Unmodifiable}.
+     * @return a {@link MultiMap} that contains all stored values in all context in LIFO-compliant
order.
+     *         Returned {@link MultiMap} is {@link org.apache.commons.collections.Unmodifiable}.
      */
-    public Map getAll();
+    public MultiMap getAll();
 
     /**
      * Works exactly the same way as {@link Map#put(Object, Object)} but previous value associated
to <code>key</code>
@@ -82,4 +83,11 @@
      * @see org.apache.commons.jxpath.JXPathBeanInfo.isDynamic() for description of static
and dynamic properties
      */
     public void fillContext();
+    
+    /**
+     * <p>Sets parent object model so newly created instance can inherit values from
parent but cannot modify it.</p>
+     * 
+     * @param parentObjectModel
+     */
+    public void setParent(ObjectModel parentObjectModel);
 }

Added: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java?rev=567656&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
(added)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
Mon Aug 20 04:13:15 2007
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.objectmodel;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.collections.IterableMap;
+import org.apache.commons.collections.MapIterator;
+import org.apache.commons.collections.MultiMap;
+import org.apache.commons.collections.Unmodifiable;
+import org.apache.commons.collections.collection.UnmodifiableCollection;
+import org.apache.commons.collections.iterators.EntrySetMapIterator;
+import org.apache.commons.collections.iterators.UnmodifiableMapIterator;
+import org.apache.commons.collections.map.AbstractMapDecorator;
+import org.apache.commons.collections.map.UnmodifiableEntrySet;
+import org.apache.commons.collections.map.UnmodifiableMap;
+import org.apache.commons.collections.set.UnmodifiableSet;
+
+/**
+ * <p>This class brings equally the same functionality as {@link UnmodifiableMap} but
also implements {@link MultiMap} interface.</p>
+ * 
+ * <p>Use this class to wrap {@link MultiMap MultiMaps} only.</p> 
+ */
+public class UnmodifiableMultiMap extends AbstractMapDecorator implements MultiMap, IterableMap,
Unmodifiable {
+    
+    public static MultiMap decorate(MultiMap map) {
+        if (map instanceof UnmodifiableMultiMap)
+            return map;
+        return new UnmodifiableMultiMap(map);
+    }
+
+    private UnmodifiableMultiMap(MultiMap map) {
+        super(map);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.collections.MultiMap#values()
+     */
+    public Collection values() {
+        Collection coll = super.values();
+        return UnmodifiableCollection.decorate(coll);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.Map#entrySet()
+     */
+    public Set entrySet() {
+        Set set = super.entrySet();
+        return UnmodifiableEntrySet.decorate(set);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.Map#keySet()
+     */
+    public Set keySet() {
+        Set set = super.keySet();
+        return UnmodifiableSet.decorate(set);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.commons.collections.IterableMap#mapIterator()
+     */
+    public MapIterator mapIterator() {
+        if (map instanceof IterableMap) {
+            MapIterator it = ((IterableMap) map).mapIterator();
+            return UnmodifiableMapIterator.decorate(it);
+        } else {
+            MapIterator it = new EntrySetMapIterator(map);
+            return UnmodifiableMapIterator.decorate(it);
+        }
+    }
+    
+    //-----------------------------------------------------------------------
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object put(Object key, Object value) {
+        throw new UnsupportedOperationException();
+    }
+
+    public void putAll(Map mapToCopy) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object remove(Object key) {
+        throw new UnsupportedOperationException();
+    }
+    
+    public Object remove(Object key, Object item) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-api/src/main/java/org/apache/cocoon/objectmodel/UnmodifiableMultiMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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?rev=567656&r1=567655&r2=567656&view=diff
==============================================================================
--- 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
Mon Aug 20 04:13:15 2007
@@ -31,7 +31,6 @@
 import org.apache.commons.collections.keyvalue.DefaultKeyValue;
 import org.apache.commons.collections.map.AbstractMapDecorator;
 import org.apache.commons.collections.map.MultiValueMap;
-import org.apache.commons.collections.map.UnmodifiableMap;
 import org.apache.commons.jxpath.DynamicPropertyHandler;
 import org.apache.commons.jxpath.JXPathBeanInfo;
 import org.apache.commons.jxpath.JXPathIntrospector;
@@ -79,8 +78,8 @@
         return super.get(key);
     }
     
-    public Map getAll() {
-        return UnmodifiableMap.decorate(multiValueMap);
+    public MultiMap getAll() {
+        return UnmodifiableMultiMap.decorate(multiValueMap);
     }
     
     public Object put(Object key, Object value) {
@@ -270,6 +269,16 @@
             return this.value;
         }
         
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.cocoon.objectmodel.ObjectModel#setParent(org.apache.cocoon.objectmodel.ObjectModel)
+     */
+    public void setParent(ObjectModel parentObjectModel) {
+        if (!this.isEmpty())
+            throw new IllegalStateException("Setting parent may occur only if Object Model
is empty.");
+        singleValueMap.putAll(parentObjectModel);
+        multiValueMap.putAll(parentObjectModel.getAll());
     };
     
 }

Copied: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml
(from r567300, cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModel.xml)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml?p2=cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml&p1=cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModel.xml&r1=567300&r2=567656&rev=567656&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModel.xml
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml
Mon Aug 20 04:13:15 2007
@@ -22,11 +22,11 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
 
-    <!-- Default implementation of ObjectModel interface -->
-    <bean name="org.apache.cocoon.objectmodel.ObjectModel"
+    <!-- Default implementation of ObjectModel interface. This bean definition, is a template
actually because it has
+         abstract attribute set to "true". It enables Object Model to be defined as scoped
bean elsewhere. -->
+    <bean name="org.apache.cocoon.objectmodel.ObjectModel.template"
           class="org.apache.cocoon.objectmodel.ObjectModelImpl"
-          scope="call">
-        <aop:scoped-proxy proxy-target-class="false"/>
+          abstract="true">
         <property name="initialEntries">
           <map>
             <entry key="cocoon" value-ref="org.apache.cocoon.objectmodel.provider.CocoonEntryObjectModelProvider"/>

Propchange: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/resources/META-INF/cocoon/spring/ObjectModelTemplate.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/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?rev=567656&r1=567655&r2=567656&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/test/java/org/apache/cocoon/objectmodel/ObjectModelImplTestCase.java
Mon Aug 20 04:13:15 2007
@@ -23,17 +23,20 @@
 
 public class ObjectModelImplTestCase extends TestCase {
     
+    private ObjectModel objectModel;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.objectModel = new ObjectModelImpl();
+    }
+    
     public void testMap() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.put("foo1", "bar1");
         assertEquals("bar2", objectModel.put("foo2", "bar2")); 
         assertEquals(true, objectModel.containsKey("foo1"));
     }
     
     public void testMultiValue() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.markLocalContext();
         objectModel.put("foo", "bar1");
         
@@ -51,8 +54,6 @@
     }
     
     public void testValues() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.put("foo", "bar1");
         Collection values = objectModel.values();
         assertEquals(true, values.contains("bar1"));
@@ -69,8 +70,6 @@
     }
     
     public void testLocalContext() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.put("foo", "bar1");
         objectModel.markLocalContext();
         objectModel.put("foo", "bar2");
@@ -88,8 +87,6 @@
     }
     
     public void testNull() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.markLocalContext();
         objectModel.put("foo", "bar");
         
@@ -107,20 +104,15 @@
     }
     
     public void testThis() {
-        ObjectModel objectModel = new ObjectModelImpl();
         assertEquals(objectModel, objectModel.get("this"));
     }
 
-    public void testKeyAsPath() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
+    public void testKeyAsPath() {        
         objectModel.putAt("foo", "bar");
         assertEquals("bar", objectModel.get("foo"));
     }
 
     public void testPutAt() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.putAt("foo/bar", "xyz");
         assertTrue(objectModel.containsKey("foo"));
         assertTrue(objectModel.get("foo") instanceof Map);
@@ -128,8 +120,6 @@
     }
 
     public void testPathInLocalContext() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.markLocalContext();
         objectModel.putAt("foo/bar", "xyz");
         
@@ -147,9 +137,26 @@
     }
 
     public void testIfMapIsCreated() {
-        ObjectModel objectModel = new ObjectModelImpl();
-        
         objectModel.putAt("foo/bar/xyz", "abc");
         assertTrue(((Map)objectModel.get("foo")).get("bar") instanceof Map);
+    }
+    
+    public void testParent() {
+        ObjectModel parentObjectModel = new ObjectModelImpl();
+        
+        parentObjectModel.put("foo", "bar");
+        parentObjectModel.put("foo2", "xyz");
+        objectModel.setParent(parentObjectModel);
+        
+        assertTrue(objectModel.containsKey("foo"));
+        assertEquals("xyz", objectModel.get("foo2"));
+        
+        objectModel.markLocalContext();
+        objectModel.put("foo", "abc");
+        assertEquals("abc", objectModel.get("foo"));
+        assertEquals(2, ((Collection)objectModel.getAll().get("foo")).size());
+        objectModel.cleanupLocalContext();
+        
+        assertEquals("bar", objectModel.get("foo"));
     }
 }



Mime
View raw message