You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/04/02 14:41:43 UTC

svn commit: r1670894 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/ main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apache/sling/jcr/reso...

Author: cziegeler
Date: Thu Apr  2 12:41:42 2015
New Revision: 1670894

URL: http://svn.apache.org/r1670894
Log:
SLING-4566 : Get array of namespace prefixes only once

Added:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java   (with props)
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java   (with props)
Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/package-info.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java Thu Apr  2 12:41:42 2015
@@ -35,7 +35,10 @@ import org.apache.sling.jcr.resource.int
 /**
  * This implementation of the value map allows to change
  * the properties and save them later on.
+ *
+ * @deprecated Resources should be adapted to a modifiable value map instead
  */
+@Deprecated
 public final class JcrModifiablePropertyMap
     extends JcrPropertyMap
     implements PersistableValueMap {

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java Thu Apr  2 12:41:42 2015
@@ -41,7 +41,10 @@ import org.apache.sling.jcr.resource.int
 /**
  * An implementation of the value map based on a JCR node.
  * @see JcrModifiablePropertyMap
+ *
+ * @deprecated A (JCR) resource should be adapted to a {@link ValueMap}.
  */
+@Deprecated
 public class JcrPropertyMap
     implements ValueMap {
 
@@ -87,7 +90,7 @@ public class JcrPropertyMap
     /**
      * Get the node.
      */
-    Node getNode() {
+    protected Node getNode() {
         return node;
     }
 
@@ -384,7 +387,7 @@ public class JcrPropertyMap
     /**
     * Read namespace prefixes and store as member variable to minimize number of JCR API calls
     */
-    private String[] getNamespacePrefixes() throws RepositoryException {
+    protected String[] getNamespacePrefixes() throws RepositoryException {
         if (this.namespacePrefixes == null) {
             this.namespacePrefixes = getNode().getSession().getNamespacePrefixes();
         }

Added: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java?rev=1670894&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java (added)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java Thu Apr  2 12:41:42 2015
@@ -0,0 +1,51 @@
+/*
+ * 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.jcr.resource.internal;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
+
+/**
+ * This is a helper class used to pass several services/data to the resource
+ * and value map implementations.
+ */
+public class HelperData {
+
+    public final ClassLoader dynamicClassLoader;
+
+    public final PathMapper pathMapper;
+
+    private volatile String[] namespacePrefixes;
+
+    public HelperData(final ClassLoader dynamicClassLoader,
+            final PathMapper pathMapper) {
+        this.dynamicClassLoader = dynamicClassLoader;
+        this.pathMapper = pathMapper;
+    }
+
+    public String[] getNamespacePrefixes(final Session session)
+    throws RepositoryException {
+        if ( this.namespacePrefixes == null ) {
+            this.namespacePrefixes = session.getNamespacePrefixes();
+        }
+        return this.namespacePrefixes;
+    }
+}

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java Thu Apr  2 12:41:42 2015
@@ -59,22 +59,19 @@ public final class JcrModifiableValueMap
     /** Has the node been read completely? */
     private boolean fullyRead;
 
-    /** keep all prefixes for escaping */
-    private String[] namespacePrefixes;
-
-    private final ClassLoader dynamicClassLoader;
+    private final HelperData helper;
 
     /**
      * Constructor
      * @param node The underlying node.
-     * @param dynamicCL Dynamic class loader for loading serialized objects.
+     * @param helper Helper data object
      */
-    public JcrModifiableValueMap(final Node node, final ClassLoader dynamicCL) {
+    public JcrModifiableValueMap(final Node node, final HelperData helper) {
         this.node = node;
         this.cache = new LinkedHashMap<String, JcrPropertyMapCacheEntry>();
         this.valueCache = new LinkedHashMap<String, Object>();
         this.fullyRead = false;
-        this.dynamicClassLoader = dynamicCL;
+        this.helper = helper;
     }
 
     /**
@@ -110,7 +107,7 @@ public final class JcrModifiableValueMap
         if ( entry == null ) {
             return null;
         }
-        return entry.convertToType(type, node, dynamicClassLoader);
+        return entry.convertToType(type, node, helper.dynamicClassLoader);
     }
 
     /**
@@ -360,7 +357,7 @@ public final class JcrModifiableValueMap
         // check if colon is neither the first nor the last character
         if (indexOfPrefix > 0 && key.length() > indexOfPrefix + 1) {
             final String prefix = key.substring(0, indexOfPrefix);
-            for (final String existingPrefix : getNamespacePrefixes()) {
+            for (final String existingPrefix : this.helper.getNamespacePrefixes(this.node.getSession())) {
                 if (existingPrefix.equals(prefix)) {
                     return prefix
                             + ":"
@@ -373,16 +370,6 @@ public final class JcrModifiableValueMap
     }
 
     /**
-    * Read namespace prefixes and store as member variable to minimize number of JCR API calls
-    */
-    private String[] getNamespacePrefixes() throws RepositoryException {
-        if (this.namespacePrefixes == null) {
-            this.namespacePrefixes = getNode().getSession().getNamespacePrefixes();
-        }
-        return this.namespacePrefixes;
-    }
-
-    /**
      * Read all properties.
      * @throws IllegalArgumentException if a repository exception occurs
      */
@@ -452,13 +439,13 @@ public final class JcrModifiableValueMap
             this.cache.put(key, entry);
             final String name = escapeKeyName(key);
             if ( NodeUtil.MIXIN_TYPES.equals(name) ) {
-                NodeUtil.handleMixinTypes(node, entry.convertToType(String[].class, node, dynamicClassLoader));
+                NodeUtil.handleMixinTypes(node, entry.convertToType(String[].class, node, this.helper.dynamicClassLoader));
             } else if ( "jcr:primaryType".equals(name) ) {
-                node.setPrimaryType(entry.convertToType(String.class, node, dynamicClassLoader));
+                node.setPrimaryType(entry.convertToType(String.class, node, this.helper.dynamicClassLoader));
             } else if ( entry.isArray() ) {
-                node.setProperty(name, entry.convertToType(Value[].class, node, dynamicClassLoader));
+                node.setProperty(name, entry.convertToType(Value[].class, node, this.helper.dynamicClassLoader));
             } else {
-                node.setProperty(name, entry.convertToType(Value.class, node, dynamicClassLoader));
+                node.setProperty(name, entry.convertToType(Value.class, node, this.helper.dynamicClassLoader));
             }
         } catch (final RepositoryException re) {
             throw new IllegalArgumentException("Value for key " + key + " can't be put into node: " + value, re);

Added: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java?rev=1670894&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java (added)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java Thu Apr  2 12:41:42 2015
@@ -0,0 +1,40 @@
+/*
+ * 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.jcr.resource.internal;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.resource.JcrPropertyMap;
+
+public class JcrValueMap extends JcrPropertyMap {
+
+    private final HelperData helper;
+
+    public JcrValueMap(final Node node, final HelperData helper) {
+        super(node, helper.dynamicClassLoader);
+        this.helper = helper;
+    }
+
+    @Override
+    protected String[] getNamespacePrefixes() throws RepositoryException {
+        return this.helper.getNamespacePrefixes(this.getNode().getSession());
+    }
+
+}

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrValueMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java Thu Apr  2 12:41:42 2015
@@ -39,9 +39,10 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.jcr.resource.JcrModifiablePropertyMap;
-import org.apache.sling.jcr.resource.JcrPropertyMap;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap;
+import org.apache.sling.jcr.resource.internal.JcrValueMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,9 +64,7 @@ class JcrNodeResource extends JcrItemRes
 
     private String resourceSuperType;
 
-    private final ClassLoader dynamicClassLoader;
-
-    private final PathMapper pathMapper;
+    private final HelperData helper;
 
     /**
      * Constructor
@@ -79,11 +78,9 @@ class JcrNodeResource extends JcrItemRes
                            final String path,
                            final String version,
                            final Node node,
-                           final ClassLoader dynamicClassLoader,
-                           final PathMapper pathMapper) {
+                           final HelperData helper) {
         super(resourceResolver, path, version, node, new JcrNodeResourceMetadata(node));
-        this.pathMapper = pathMapper;
-        this.dynamicClassLoader = dynamicClassLoader;
+        this.helper = helper;
         this.resourceSuperType = UNSET_RESOURCE_SUPER_TYPE;
     }
 
@@ -130,13 +127,13 @@ class JcrNodeResource extends JcrItemRes
         } else if (type == InputStream.class) {
             return (Type) getInputStream(); // unchecked cast
         } else if (type == Map.class || type == ValueMap.class) {
-            return (Type) new JcrPropertyMap(getNode(), this.dynamicClassLoader); // unchecked cast
+            return (Type) new JcrValueMap(getNode(), this.helper); // unchecked cast
         } else if (type == PersistableValueMap.class ) {
             // check write
             try {
                 getNode().getSession().checkPermission(getPath(),
                     "set_property");
-                return (Type) new JcrModifiablePropertyMap(getNode(), this.dynamicClassLoader);
+                return (Type) new JcrModifiablePropertyMap(getNode(), this.helper.dynamicClassLoader);
             } catch (AccessControlException ace) {
                 // the user has no write permission, cannot adapt
                 LOGGER.debug(
@@ -153,7 +150,7 @@ class JcrNodeResource extends JcrItemRes
             try {
                 getNode().getSession().checkPermission(getPath(),
                     "set_property");
-                return (Type) new JcrModifiableValueMap(getNode(), this.dynamicClassLoader);
+                return (Type) new JcrModifiableValueMap(getNode(), this.helper);
             } catch (AccessControlException ace) {
                 // the user has no write permission, cannot adapt
                 LOGGER.debug(
@@ -243,7 +240,7 @@ class JcrNodeResource extends JcrItemRes
         try {
             if (getNode().hasNodes()) {
                 return new JcrNodeResourceIterator(getResourceResolver(), path, version,
-                    getNode().getNodes(), this.dynamicClassLoader, pathMapper);
+                    getNode().getNodes(), this.helper);
             }
         } catch (final RepositoryException re) {
             LOGGER.error("listChildren: Cannot get children of " + this, re);

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceIterator.java Thu Apr  2 12:41:42 2015
@@ -27,6 +27,7 @@ import javax.jcr.RepositoryException;
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,9 +51,7 @@ public class JcrNodeResourceIterator imp
     /** The prefetched next iterator entry, null at the end of iterating */
     private Resource nextResult;
 
-    private final ClassLoader dynamicClassLoader;
-
-    private final PathMapper pathMapper;
+    private final HelperData helper;
 
     private final String parentPath;
 
@@ -64,9 +63,8 @@ public class JcrNodeResourceIterator imp
      */
     public JcrNodeResourceIterator(final ResourceResolver resourceResolver,
                                    final NodeIterator nodes,
-                                   final ClassLoader dynamicClassLoader,
-                                   final PathMapper pathMapper) {
-        this(resourceResolver, null, null, nodes, dynamicClassLoader, pathMapper);
+                                   final HelperData helper) {
+        this(resourceResolver, null, null, nodes, helper);
     }
 
     /**
@@ -78,14 +76,12 @@ public class JcrNodeResourceIterator imp
                                    final String parentPath,
                                    final String parentVersion,
                                    final NodeIterator nodes,
-                                   final ClassLoader dynamicClassLoader,
-                                   final PathMapper pathMapper) {
+                                   final HelperData helper) {
         this.resourceResolver = resourceResolver;
         this.parentPath = parentPath;
         this.parentVersion = parentVersion;
         this.nodes = nodes;
-        this.dynamicClassLoader = dynamicClassLoader;
-        this.pathMapper = pathMapper;
+        this.helper = helper;
         this.nextResult = seek();
     }
 
@@ -118,7 +114,7 @@ public class JcrNodeResourceIterator imp
                 final String path = getPath(n);
                 if ( path != null ) {
                     final Resource resource = new JcrNodeResource(resourceResolver,
-                        path, parentVersion, n, dynamicClassLoader, pathMapper);
+                        path, parentVersion, n, helper);
                     LOGGER.debug("seek: Returning Resource {}", resource);
                     return resource;
                 }
@@ -141,6 +137,6 @@ public class JcrNodeResourceIterator imp
         } else {
             path = String.format("%s/%s", parentPath, node.getName());
         }
-        return pathMapper.mapJCRPathToResourcePath(path);
+        return helper.pathMapper.mapJCRPathToResourcePath(path);
     }
 }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java Thu Apr  2 12:41:42 2015
@@ -54,8 +54,7 @@ class JcrPropertyResource extends JcrIte
     public JcrPropertyResource(final ResourceResolver resourceResolver,
                                final String path,
                                final String version,
-                               final Property property,
-                               final PathMapper pathMapper)
+                               final Property property)
     throws RepositoryException {
         super(resourceResolver, path, version, property, new ResourceMetadata());
         this.resourceType = getResourceTypeForNode(property.getParent())

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Thu Apr  2 12:41:42 2015
@@ -27,7 +27,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Queue;
 import java.util.Set;
 
 import javax.jcr.Item;
@@ -67,6 +66,7 @@ import org.apache.sling.api.resource.Val
 import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap;
 import org.apache.sling.jcr.resource.internal.NodeUtil;
 import org.slf4j.Logger;
@@ -112,18 +112,16 @@ public class JcrResourceProvider
     private boolean closed = false;
 
     private final Session session;
-    private final ClassLoader dynamicClassLoader;
+    private final HelperData helper;
     private final RepositoryHolder repositoryHolder;
-    private final PathMapper pathMapper;
 
     public JcrResourceProvider(final Session session,
                                final ClassLoader dynamicClassLoader,
                                final RepositoryHolder repositoryHolder,
                                final PathMapper pathMapper) {
         this.session = session;
-        this.dynamicClassLoader = dynamicClassLoader;
+        this.helper = new HelperData(dynamicClassLoader, pathMapper);
         this.repositoryHolder = repositoryHolder;
-        this.pathMapper = pathMapper;
     }
 
     // ---------- ResourceProvider interface ----------------------------------
@@ -145,7 +143,7 @@ public class JcrResourceProvider
         return getResource(resourceResolver, path, Collections.<String, String> emptyMap());
     }
 
-    
+
     /**
      * @see org.apache.sling.api.resource.ResourceProvider#getResource(org.apache.sling.api.resource.ResourceResolver, java.lang.String)
      */
@@ -208,7 +206,7 @@ public class JcrResourceProvider
      */
     private JcrItemResource createResource(final ResourceResolver resourceResolver,
             final String resourcePath, final Map<String, String> parameters) throws RepositoryException {
-        final String jcrPath = pathMapper.mapResourcePathToJCRPath(resourcePath);
+        final String jcrPath = helper.pathMapper.mapResourcePathToJCRPath(resourcePath);
         if (jcrPath != null && itemExists(jcrPath)) {
             Item item = session.getItem(jcrPath);
             final String version;
@@ -222,7 +220,7 @@ public class JcrResourceProvider
                 log.debug(
                     "createResource: Found JCR Node Resource at path '{}'",
                     resourcePath);
-                final JcrNodeResource resource = new JcrNodeResource(resourceResolver, resourcePath, version, (Node) item, dynamicClassLoader, pathMapper);
+                final JcrNodeResource resource = new JcrNodeResource(resourceResolver, resourcePath, version, (Node) item, helper);
                 resource.getResourceMetadata().setParameterMap(parameters);
                 return resource;
             }
@@ -231,7 +229,7 @@ public class JcrResourceProvider
                 "createResource: Found JCR Property Resource at path '{}'",
                 resourcePath);
             final JcrPropertyResource resource = new JcrPropertyResource(resourceResolver, resourcePath, version,
-                (Property) item, pathMapper);
+                (Property) item);
             resource.getResourceMetadata().setParameterMap(parameters);
             return resource;
         }
@@ -343,7 +341,7 @@ public class JcrResourceProvider
 
         try {
             final QueryResult res = JcrResourceUtil.query(session, query, language);
-            return new JcrNodeResourceIterator(resolver, res.getNodes(), this.dynamicClassLoader, pathMapper);
+            return new JcrNodeResourceIterator(resolver, res.getNodes(), helper);
         } catch (final javax.jcr.query.InvalidQueryException iqe) {
             throw new QuerySyntaxException(iqe.getMessage(), query, language, iqe);
         } catch (final RepositoryException re) {
@@ -390,7 +388,7 @@ public class JcrResourceProvider
                     while ( result == null && rows.hasNext() ) {
                         try {
                             final Row jcrRow = rows.nextRow();
-                            final String resourcePath = pathMapper.mapJCRPathToResourcePath(jcrRow.getPath());
+                            final String resourcePath = helper.pathMapper.mapJCRPathToResourcePath(jcrRow.getPath());
                             if ( resourcePath != null ) {
                                 final Map<String, Object> row = new HashMap<String, Object>();
 
@@ -406,7 +404,7 @@ public class JcrResourceProvider
                                         if (colName.equals(QUERY_COLUMN_PATH)) {
                                             didPath = true;
                                             row.put(colName,
-                                                    pathMapper.mapJCRPathToResourcePath(JcrResourceUtil.toJavaObject(values[i]).toString()));
+                                                    helper.pathMapper.mapJCRPathToResourcePath(JcrResourceUtil.toJavaObject(values[i]).toString()));
                                         }
                                         if (colName.equals(QUERY_COLUMN_SCORE)) {
                                             didScore = true;
@@ -414,7 +412,7 @@ public class JcrResourceProvider
                                     }
                                 }
                                 if (!didPath) {
-                                    row.put(QUERY_COLUMN_PATH, pathMapper.mapJCRPathToResourcePath(jcrRow.getPath()));
+                                    row.put(QUERY_COLUMN_PATH, helper.pathMapper.mapJCRPathToResourcePath(jcrRow.getPath()));
                                 }
                                 if (!didScore) {
                                     row.put(QUERY_COLUMN_SCORE, jcrRow.getScore());
@@ -547,7 +545,7 @@ public class JcrResourceProvider
                 nodeType = null;
             }
         }
-        final String jcrPath = pathMapper.mapResourcePathToJCRPath(resourcePath);
+        final String jcrPath = helper.pathMapper.mapResourcePathToJCRPath(resourcePath);
         if ( jcrPath == null ) {
             throw new PersistenceException("Unable to create node at " + resourcePath, null, resourcePath, null);
         }
@@ -569,7 +567,7 @@ public class JcrResourceProvider
 
             if ( properties != null ) {
                 // create modifiable map
-                final JcrModifiableValueMap jcrMap = new JcrModifiableValueMap(node, this.dynamicClassLoader);
+                final JcrModifiableValueMap jcrMap = new JcrModifiableValueMap(node, this.helper);
                 // check mixin types first
                 final Object value = properties.get(NodeUtil.MIXIN_TYPES);
                 if ( value != null ) {
@@ -591,7 +589,7 @@ public class JcrResourceProvider
                 }
             }
 
-            return new JcrNodeResource(resolver, resourcePath, null, node, this.dynamicClassLoader, pathMapper);
+            return new JcrNodeResource(resolver, resourcePath, null, node, this.helper);
         } catch (final RepositoryException e) {
             throw new PersistenceException("Unable to create node at " + jcrPath, e, resourcePath, null);
         }
@@ -602,7 +600,7 @@ public class JcrResourceProvider
      */
     public void delete(final ResourceResolver resolver, final String resourcePath)
     throws PersistenceException {
-        final String jcrPath = pathMapper.mapResourcePathToJCRPath(resourcePath);
+        final String jcrPath = helper.pathMapper.mapResourcePathToJCRPath(resourcePath);
         if ( jcrPath == null ) {
             throw new PersistenceException("Unable to delete resource at " + resourcePath, null, resourcePath, null);
         }

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/package-info.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/package-info.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/package-info.java Thu Apr  2 12:41:42 2015
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("2.2")
+@Version("2.3")
 package org.apache.sling.jcr.resource;
 
 import aQute.bnd.annotation.Version;

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMapTest.java Thu Apr  2 12:41:42 2015
@@ -73,6 +73,10 @@ public class JcrModifiableValueMapTest e
         super.tearDown();
     }
 
+    private HelperData getHelperData() throws Exception {
+        return new HelperData(null, new PathMapperImpl());
+    }
+
     private Map<String, Object> initialSet() {
         final Map<String, Object> values = new HashMap<String, Object>();
         values.put("string", "test");
@@ -82,11 +86,11 @@ public class JcrModifiableValueMapTest e
     }
 
     public void testStreams() throws Exception {
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
         InputStream stream = new ByteArrayInputStream(TEST_BYTE_ARRAY);
         pvm.put("binary", stream);
         getSession().save();
-        final ModifiableValueMap modifiableValueMap2 = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap modifiableValueMap2 = new JcrModifiableValueMap(this.rootNode, getHelperData());
         assertTrue("The read stream is not what we wrote.", IOUtils.toString(modifiableValueMap2.get("binary", InputStream.class)).equals
                 (TEST_BYTE_ARRAY_TO_STRING));
     }
@@ -94,7 +98,7 @@ public class JcrModifiableValueMapTest e
     public void testPut()
     throws Exception {
         getSession().refresh(false);
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
         assertContains(pvm, initialSet());
         assertNull(pvm.get("something"));
 
@@ -110,14 +114,14 @@ public class JcrModifiableValueMapTest e
         getSession().save();
         assertContains(pvm, currentlyStored);
 
-        final ModifiableValueMap pvm2 = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm2 = new JcrModifiableValueMap(this.rootNode, getHelperData());
         assertContains(pvm2, currentlyStored);
     }
 
     public void testSerializable()
     throws Exception {
         this.rootNode.getSession().refresh(false);
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
         assertContains(pvm, initialSet());
         assertNull(pvm.get("something"));
 
@@ -134,7 +138,7 @@ public class JcrModifiableValueMapTest e
 
         getSession().save();
 
-        final ModifiableValueMap pvm2 = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm2 = new JcrModifiableValueMap(this.rootNode, getHelperData());
         // check if we get the list again
         @SuppressWarnings("unchecked")
         final List<String> strings3 = (List<String>) pvm2.get("something", Serializable.class);
@@ -144,7 +148,7 @@ public class JcrModifiableValueMapTest e
 
     public void testExceptions() throws Exception {
         this.rootNode.getSession().refresh(false);
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(this.rootNode, getHelperData());
         try {
             pvm.put(null, "something");
             fail("Put with null key");
@@ -171,7 +175,7 @@ public class JcrModifiableValueMapTest e
         this.rootNode.getSession().refresh(false);
         final Node testNode = this.rootNode.addNode("testMixins" + System.currentTimeMillis());
         testNode.getSession().save();
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, getHelperData());
 
         final String[] types = pvm.get("jcr:mixinTypes", String[].class);
         final Set<String> exNodeTypes = getMixinNodeTypes(testNode);
@@ -209,7 +213,7 @@ public class JcrModifiableValueMapTest e
 
         final Node testNode = this.rootNode.addNode("nameTest" + System.currentTimeMillis());
         testNode.getSession().save();
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, getHelperData());
         pvm.put(TEST_PATH, VALUE);
         pvm.put(PROP1, VALUE1);
         pvm.put(PROP2, VALUE2);
@@ -217,7 +221,7 @@ public class JcrModifiableValueMapTest e
         getSession().save();
 
         // read with property map
-        final ValueMap vm = new JcrModifiableValueMap(testNode, null);
+        final ValueMap vm = new JcrModifiableValueMap(testNode, getHelperData());
         assertEquals(VALUE, vm.get(TEST_PATH));
         assertEquals(VALUE1, vm.get(PROP1));
         assertEquals(VALUE2, vm.get(PROP2));
@@ -241,14 +245,14 @@ public class JcrModifiableValueMapTest e
         testNode.setProperty(PROP3, VALUE);
         testNode.getSession().save();
 
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, getHelperData());
         pvm.put(PROP3, VALUE3);
         pvm.put("jcr:a:b", VALUE3);
         pvm.put("jcr:", VALUE3);
         getSession().save();
 
         // read with property map
-        final ValueMap vm = new JcrModifiableValueMap(testNode, null);
+        final ValueMap vm = new JcrModifiableValueMap(testNode, getHelperData());
         assertEquals(VALUE3, vm.get(PROP3));
         assertEquals(VALUE3, vm.get("jcr:a:b"));
         assertEquals(VALUE3, vm.get("jcr:"));
@@ -296,13 +300,13 @@ public class JcrModifiableValueMapTest e
         testNode.getSession().save();
 
         // write with property map
-        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, null);
+        final ModifiableValueMap pvm = new JcrModifiableValueMap(testNode, getHelperData());
         pvm.put(PROP2, dateValue2);
         pvm.put(PROP3, calendarValue3);
         getSession().save();
 
         // read with property map
-        final ValueMap vm = new JcrModifiableValueMap(testNode, null);
+        final ValueMap vm = new JcrModifiableValueMap(testNode, getHelperData());
         assertEquals(dateValue1, vm.get(PROP1, Date.class));
         assertEquals(calendarValue1, vm.get(PROP1, Calendar.class));
         assertEquals(dateValue2, vm.get(PROP2, Date.class));

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java Thu Apr  2 12:41:42 2015
@@ -29,14 +29,19 @@ import junit.framework.TestCase;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.commons.testing.jcr.MockNode;
 import org.apache.sling.commons.testing.jcr.MockNodeIterator;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.PathMapperImpl;
 import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
 
 public class JcrNodeResourceIteratorTest extends TestCase {
 
+    private HelperData getHelperData() {
+        return new HelperData(null, new PathMapperImpl());
+    }
+
     public void testEmpty() {
         NodeIterator ni = new MockNodeIterator(null);
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null, new PathMapperImpl());
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, getHelperData());
 
         assertFalse(ri.hasNext());
 
@@ -52,7 +57,7 @@ public class JcrNodeResourceIteratorTest
         String path = "/parent/path/node";
         Node node = new MockNode(path);
         NodeIterator ni = new MockNodeIterator(new Node[] { node });
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null, new PathMapperImpl());
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, getHelperData());
 
         assertTrue(ri.hasNext());
         Resource res = ri.next();
@@ -77,7 +82,7 @@ public class JcrNodeResourceIteratorTest
             nodes[i] = new MockNode(pathBase + i, "some:type" + i);
         }
         NodeIterator ni = new MockNodeIterator(nodes);
-        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null, new PathMapperImpl());
+        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, getHelperData());
 
         for (int i=0; i < nodes.length; i++) {
             assertTrue(ri.hasNext());

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java Thu Apr  2 12:41:42 2015
@@ -31,10 +31,15 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.PathMapperImpl;
 
 public class JcrNodeResourceTest extends JcrItemResourceTestBase {
 
+    private HelperData getHelperData() throws Exception {
+        return new HelperData(null, new PathMapperImpl());
+    }
+
     public void testNtFileNtResource() throws Exception {
 
         String name = "file";
@@ -45,7 +50,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         file = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, getHelperData());
 
         assertEquals(file.getPath(), jnr.getPath());
 
@@ -63,7 +68,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         file = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, getHelperData());
 
         assertEquals(file.getPath(), jnr.getPath());
 
@@ -79,7 +84,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         res = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, getHelperData());
 
         assertEquals(res.getPath(), jnr.getPath());
 
@@ -95,7 +100,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         res = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, getHelperData());
 
         assertEquals(res.getPath(), jnr.getPath());
 
@@ -108,14 +113,14 @@ public class JcrNodeResourceTest extends
         Node node = rootNode.addNode(name, JcrConstants.NT_UNSTRUCTURED);
         getSession().save();
 
-        JcrNodeResource jnr = new JcrNodeResource(null, node.getPath(), null, node, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
         assertEquals(JcrConstants.NT_UNSTRUCTURED, jnr.getResourceType());
 
         String typeName = "some/resource/type";
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(null, node.getPath(), null, node, null, new PathMapperImpl());
+        jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
         assertEquals(typeName, jnr.getResourceType());
     }
 
@@ -127,7 +132,7 @@ public class JcrNodeResourceTest extends
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, typeName);
         getSession().save();
 
-        Resource jnr = new JcrNodeResource(null, node.getPath(), null, node, null, new PathMapperImpl());
+        Resource jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
         assertEquals(typeName, jnr.getResourceType());
 
         // default super type is null
@@ -138,7 +143,7 @@ public class JcrNodeResourceTest extends
         typeNode.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, superTypeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(null, typeNode.getPath(), null, typeNode, null, new PathMapperImpl());
+        jnr = new JcrNodeResource(null, typeNode.getPath(), null, typeNode, getHelperData());
         assertEquals(JcrConstants.NT_UNSTRUCTURED, jnr.getResourceType());
         assertEquals(superTypeName, jnr.getResourceSuperType());
 
@@ -147,7 +152,7 @@ public class JcrNodeResourceTest extends
         node.setProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, otherSuperTypeName);
         getSession().save();
 
-        jnr = new JcrNodeResource(null, node.getPath(), null, node, null, new PathMapperImpl());
+        jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
         assertEquals(typeName, jnr.getResourceType());
         assertEquals(otherSuperTypeName, jnr.getResourceSuperType());
 
@@ -155,7 +160,7 @@ public class JcrNodeResourceTest extends
         node.getProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY).remove();
         getSession().save();
 
-        jnr = new JcrNodeResource(null, node.getPath(), null, node, null, new PathMapperImpl());
+        jnr = new JcrNodeResource(null, node.getPath(), null, node, getHelperData());
         assertEquals(typeName, jnr.getResourceType());
         assertNull(jnr.getResourceSuperType());
     }
@@ -168,7 +173,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         res = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, res.getPath(), null, res, getHelperData());
 
         final Map<?, ?> props = jnr.adaptTo(Map.class);
 
@@ -235,7 +240,7 @@ public class JcrNodeResourceTest extends
         getSession().save();
 
         file = rootNode.getNode(name);
-        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, null, new PathMapperImpl());
+        JcrNodeResource jnr = new JcrNodeResource(null, file.getPath(), null, file, getHelperData());
 
         assertEquals(utf8bytes, jnr.adaptTo(InputStream.class));
         assertEquals(utf8bytes.length, jnr.getResourceMetadata().getContentLength());

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResourceTest.java Thu Apr  2 12:41:42 2015
@@ -30,7 +30,6 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.jcr.resource.internal.PathMapperImpl;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -73,7 +72,7 @@ public class JcrPropertyResourceTest {
                 allowing(property).getType(); will(returnValue(data.getValue()));
                 allowing(property).getString(); will(returnValue(stringValue));
             }});
-            final JcrPropertyResource propResource = new JcrPropertyResource(resolver, "/path/to/string-property", null, property, new PathMapperImpl());
+            final JcrPropertyResource propResource = new JcrPropertyResource(resolver, "/path/to/string-property", null, property);
             assertEquals("Byte length of " +  stringValue, stringByteLength, propResource.getResourceMetadata().getContentLength());
         }
     }

Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java?rev=1670894&r1=1670893&r2=1670894&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java (original)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrTestNodeResource.java Thu Apr  2 12:41:42 2015
@@ -22,13 +22,14 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.jcr.resource.internal.HelperData;
 import org.apache.sling.jcr.resource.internal.PathMapperImpl;
 
 public class JcrTestNodeResource extends JcrNodeResource {
 
     public JcrTestNodeResource(ResourceResolver resourceResolver, Node node,
             ClassLoader dynamicClassLoader) throws RepositoryException {
-        super(resourceResolver, node.getPath(), null, node, dynamicClassLoader, new PathMapperImpl());
+        super(resourceResolver, node.getPath(), null, node, new HelperData(null, new PathMapperImpl()));
     }
 
 }



Re: svn commit: r1670894 - in /sling/trunk/bundles/jcr/resource/src: main/java/org/apache/sling/jcr/resource/ main/java/org/apache/sling/jcr/resource/internal/ main/java/org/apache/sling/jcr/resource/internal/helper/jcr/ test/java/org/apache/sling/jcr/reso...

Posted by Robert Munteanu <ro...@apache.org>.
Hi,

On Thu, 2015-04-02 at 12:41 +0000, cziegeler@apache.org wrote:
> Added:
> sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java
> URL:
> http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java?rev=1670894&view=auto
> ==============================================================================
> ---
> sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java (added)
> +++
> sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java Thu Apr  2 12:41:42 2015
> @@ -0,0 +1,51 @@
> +/*
> + * 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.jcr.resource.internal;
> +
> +import javax.jcr.RepositoryException;
> +import javax.jcr.Session;
> +
> +import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
> +
> +/**
> + * This is a helper class used to pass several services/data to the
> resource
> + * and value map implementations.
> + */
> +public class HelperData {
> +
> +    public final ClassLoader dynamicClassLoader;
> +
> +    public final PathMapper pathMapper;
> +
> +    private volatile String[] namespacePrefixes;
> +
> +    public HelperData(final ClassLoader dynamicClassLoader,
> +            final PathMapper pathMapper) {
> +        this.dynamicClassLoader = dynamicClassLoader;
> +        this.pathMapper = pathMapper;
> +    }
> +
> +    public String[] getNamespacePrefixes(final Session session)
> +    throws RepositoryException {
> +        if ( this.namespacePrefixes == null ) {
> +            this.namespacePrefixes = session.getNamespacePrefixes();
> +        }
> +        return this.namespacePrefixes;
> +    }
> +}


Check-then-set operations with volatile fields isn't atomic. Do we care
about that? If we do, an AtomicReference or a synchronized block might
be a better idea.

Robert