Author: cziegeler
Date: Sun Mar 16 09:42:06 2014
New Revision: 1578011

URL: http://svn.apache.org/r1578011
Log:
SLING-3451 : Support for deep reads from a value map

Added:
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
   (with props)
Modified:
    
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
    
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java

Added: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java?rev=1578011&view=auto
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
 (added)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
 Sun Mar 16 09:42:06 2014
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.api.wrappers;
+
+import org.apache.sling.api.resource.ModifiableValueMap;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+
+/**
+ * A value map wrapper which implements deep reading of properties
+ * based on the resource tree and also supports {@link ModifiableValueMap}.
+ * @since 2.5
+ */
+public class DeepReadModifiableValueMapDecorator
+    extends DeepReadValueMapDecorator
+    implements ModifiableValueMap {
+
+    public DeepReadModifiableValueMapDecorator(final Resource resource, final 
ValueMap base) {
+        super(resource, base);
+    }
+}

Propchange: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/DeepReadModifiableValueMapDecorator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java?rev=1578011&r1=1578010&r2=1578011&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
 (original)
+++ 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/MongoDBResource.java
 Sun Mar 16 09:42:06 2014
@@ -23,6 +23,7 @@ import org.apache.sling.api.resource.Mod
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.wrappers.DeepReadModifiableValueMapDecorator;
 import org.apache.sling.api.wrappers.DeepReadValueMapDecorator;
 
 import com.mongodb.DBObject;
@@ -122,7 +123,7 @@ public class MongoDBResource extends Abs
             return (AdapterType) new DeepReadValueMapDecorator(this, new 
ReadableValueMap(this.dbObject));
         } else if ( type == ModifiableValueMap.class ) {
             this.dbObject = 
this.provider.getUpdatedDBObject(this.resourcePath, this.dbObject);
-            return (AdapterType) new DeepReadValueMapDecorator(this, new 
ChangeableValueMap(this));
+            return (AdapterType) new DeepReadModifiableValueMapDecorator(this, 
new ChangeableValueMap(this));
         }
 
         return super.adaptTo(type);

Modified: 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java?rev=1578011&r1=1578010&r2=1578011&view=diff
==============================================================================
--- 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
 (original)
+++ 
sling/trunk/contrib/extensions/mongodb/src/main/java/org/apache/sling/mongodb/impl/ReadableValueMap.java
 Sun Mar 16 09:42:06 2014
@@ -38,17 +38,18 @@ public class ReadableValueMap implements
     }
 
     protected void createValueMap(final DBObject dbObject) {
-        final Map<String, Object> map = new HashMap<String, Object>();
         if (dbObject == null) {
             this.valueMap = Collections.<String, Object> emptyMap();
-        }
-        for(final String key : dbObject.keySet()) {
-            final String name = MongoDBResourceProvider.keyToPropName(key);
-            if ( name != null ) {
-                map.put(key, dbObject.get(name));
+        } else {
+            final Map<String, Object> map = new HashMap<String, Object>();
+            for(final String key : dbObject.keySet()) {
+                final String name = MongoDBResourceProvider.keyToPropName(key);
+                if ( name != null ) {
+                    map.put(key, dbObject.get(name));
+                }
             }
+            this.valueMap = Collections.unmodifiableMap(map);
         }
-        this.valueMap = Collections.unmodifiableMap(map);
     }
 
     /**
@@ -204,7 +205,7 @@ public class ReadableValueMap implements
 
     /**
      * Converts the object to an array of the given type
-     * @param obj tje object or object array
+     * @param obj the object or object array
      * @param type the component type of the array
      * @return and array of type T
      */


Reply via email to