sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r787268 - in /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal: JcrResourceResolver2.java JcrResourceResolverFactoryImpl.java
Date Mon, 22 Jun 2009 15:13:00 GMT
Author: cziegeler
Date: Mon Jun 22 15:12:59 2009
New Revision: 787268

URL: http://svn.apache.org/viewvc?rev=787268&view=rev
Log:
SLING-1012, SLING-1017 : Apply patches from Ian Boston: Fix registration of JcrResourceTypeProviders
and optimize creation of the resource type provider array.

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=787268&r1=787267&r2=787268&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Mon Jun 22 15:12:59 2009
@@ -24,7 +24,6 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
-import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -259,7 +258,7 @@
         if (fragmentQueryMark < 0) {
             fragmentQueryMark = resourcePath.indexOf('?');
         }
-        
+
         // cut fragment or query off the resource path
         String mappedPath;
         final String fragmentQuery;
@@ -272,7 +271,7 @@
             fragmentQuery = null;
             mappedPath = resourcePath;
         }
-        
+
 
         // cut off scheme and host, if the same as requested
         String schemehostport;
@@ -318,12 +317,12 @@
                 buf.append('/');
                 buf.append(names.removeLast());
             }
-            
+
             // reappend the resolutionPathInfo
             if (resolutionPathInfo != null) {
                 buf.append(resolutionPathInfo);
             }
-            
+
             // and then we have the mapped path to work on
             mappedPath = buf.toString();
 
@@ -756,18 +755,18 @@
         if (factory.isMangleNamespacePrefixes() && absPath.contains(MANGLE_NAMESPACE_OUT_SUFFIX))
{
             Pattern p = Pattern.compile(MANGLE_NAMESPACE_OUT);
             Matcher m = p.matcher(absPath);
-            
+
             StringBuffer buf = new StringBuffer();
             while (m.find()) {
                 String replacement = MANGLE_NAMESPACE_IN_PREFIX + m.group(1) + MANGLE_NAMESPACE_IN_SUFFIX;
                 m.appendReplacement(buf, replacement);
             }
-            
+
             m.appendTail(buf);
-            
+
             absPath = buf.toString();
         }
-        
+
         return absPath;
     }
 
@@ -783,24 +782,24 @@
                     // throws if "namespace" is not a registered
                     // namespace prefix
                     getSession().getNamespaceURI(namespace);
-                    
+
                     String replacement = MANGLE_NAMESPACE_OUT_PREFIX
                         + namespace + MANGLE_NAMESPACE_OUT_SUFFIX;
                     m.appendReplacement(buf, replacement);
-                    
+
                 } catch (NamespaceException ne) {
-                    
+
                     // not a valid prefix
                     log.debug(
                         "unmangleNamespaces: '{}' is not a prefix, not unmangling",
                         namespace);
-                    
+
                 } catch (RepositoryException re) {
-                    
+
                     log.warn(
                         "unmangleNamespaces: Problem checking namespace '{}'",
                         namespace, re);
-                    
+
                 }
             }
             m.appendTail(buf);

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java?rev=787268&r1=787267&r2=787268&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverFactoryImpl.java
Mon Jun 22 15:12:59 2009
@@ -149,11 +149,16 @@
     private SlingRepository repository;
 
     /**
-     * The (optional) resource type providers.
+     * The (optional) resource type providers, working copy.
      */
     protected final List<JcrResourceTypeProviderEntry> jcrResourceTypeProviders = new
ArrayList<JcrResourceTypeProviderEntry>();
 
     /**
+     * An array of the above, updates when changes are created.
+     */
+    private JcrResourceTypeProvider[] jcrResourceTypeProvidersArray;
+
+    /**
      * List of ResourceProvider services bound before activation of the
      * component.
      */
@@ -165,6 +170,7 @@
      */
     protected List<ServiceReference> delayedJcrResourceTypeProviders = new LinkedList<ServiceReference>();
 
+
     protected ComponentContext componentContext;
 
     // helper for the new JcrResourceResolver2
@@ -187,6 +193,7 @@
     // whether to mangle paths with namespaces or not
     private boolean mangleNamespacePrefixes;
 
+
     public JcrResourceResolverFactoryImpl() {
         this.rootProviderEntry = new ResourceProviderEntry("/", null, null);
     }
@@ -205,18 +212,7 @@
     }
 
     protected JcrResourceTypeProvider[] getJcrResourceTypeProviders() {
-        JcrResourceTypeProvider[] providers = null;
-        synchronized (this.jcrResourceTypeProviders) {
-            if (this.jcrResourceTypeProviders.size() > 0) {
-                providers = new JcrResourceTypeProvider[this.jcrResourceTypeProviders.size()];
-                int index = 0;
-                final Iterator<JcrResourceTypeProviderEntry> i = this.jcrResourceTypeProviders.iterator();
-                while (i.hasNext()) {
-                    providers[index] = i.next().provider;
-                }
-            }
-        }
-        return providers;
+        return jcrResourceTypeProvidersArray;
     }
 
     // ---------- Implementation helpers --------------------------------------
@@ -362,30 +358,14 @@
         this.componentContext = null;
     }
 
-    private ResourcePattern[] getResourcePatterns(String[] patternList) {
-        // regexps
-        List<ResourcePattern> patterns = new ArrayList<ResourcePattern>();
-        if (patternList != null) {
-            for (final String p : patternList) {
-                int pos = p.lastIndexOf('|');
-                if (pos == -1) {
-                    log.error("Invalid regexp: {}", p);
-                } else {
-                    final String replString = p.substring(pos + 1);
-                    final Pattern pat = Pattern.compile(p.substring(0, pos));
-                    patterns.add(new ResourcePattern(pat, replString));
-                }
-            }
-        }
-        return patterns.toArray(new ResourcePattern[patterns.size()]);
-    }
-
     protected void processDelayedJcrResourceTypeProviders() {
         synchronized (this.jcrResourceTypeProviders) {
             for (ServiceReference reference : delayedJcrResourceTypeProviders) {
                 this.addJcrResourceTypeProvider(reference);
             }
             delayedJcrResourceTypeProviders.clear();
+            updateJcrResourceTypeProvidersArray();
+
         }
     }
 
@@ -422,9 +402,9 @@
     }
 
     protected void bindResourceProvider(ServiceReference reference) {
-        
+
         String serviceName = getServiceName(reference);
-        
+
         if (componentContext == null) {
 
             log.debug("bindResourceProvider: Delaying {}", serviceName);
@@ -433,9 +413,9 @@
             delayedResourceProviders.add(reference);
 
         } else {
-            
+
             log.debug("bindResourceProvider: Binding {}", serviceName);
-            
+
             String[] roots = OsgiUtil.toStringArray(reference.getProperty(ResourceProvider.ROOTS));
             if (roots != null && roots.length > 0) {
 
@@ -443,7 +423,7 @@
                     "ResourceProvider", reference);
 
                 // synchronized insertion of new resource providers into
-                // the tree to not inadvertandly loose an entry
+                // the tree to not inadvertently loose an entry
                 synchronized (this) {
 
                     for (String root : roots) {
@@ -467,7 +447,7 @@
                     }
                 }
             }
-            
+
             log.debug("bindResourceProvider: Bound {}", serviceName);
         }
     }
@@ -475,14 +455,14 @@
     protected void unbindResourceProvider(ServiceReference reference) {
 
         String serviceName = getServiceName(reference);
-        
+
         log.debug("unbindResourceProvider: Unbinding {}", serviceName);
 
         String[] roots = OsgiUtil.toStringArray(reference.getProperty(ResourceProvider.ROOTS));
         if (roots != null && roots.length > 0) {
 
             // synchronized insertion of new resource providers into
-            // the tree to not inadvertandly loose an entry
+            // the tree to not inadvertently loose an entry
             synchronized (this) {
 
                 for (String root : roots) {
@@ -495,13 +475,13 @@
                     // owns it. This may be the case if adding the provider
                     // yielded an ResourceProviderEntryException
                     rootProviderEntry.removeResourceProvider(root);
-                    
+
                     log.debug("unbindResourceProvider: root={} ({})", root,
                         serviceName);
                 }
             }
         }
-        
+
         log.debug("unbindResourceProvider: Unbound {}", serviceName);
     }
 
@@ -511,6 +491,7 @@
                 delayedJcrResourceTypeProviders.add(reference);
             } else {
                 this.addJcrResourceTypeProvider(reference);
+                updateJcrResourceTypeProvidersArray();
             }
         }
     }
@@ -526,9 +507,28 @@
                     i.remove();
                 }
             }
+            updateJcrResourceTypeProvidersArray();
         }
     }
 
+    /**
+     * Updates the JcrResourceTypeProviders array, this method is not thread safe and should
only be
+     * called from a synchronized block.
+     */
+    protected void updateJcrResourceTypeProvidersArray() {
+        JcrResourceTypeProvider[] providers = null;
+        if (this.jcrResourceTypeProviders.size() > 0) {
+            providers = new JcrResourceTypeProvider[this.jcrResourceTypeProviders.size()];
+            int index = 0;
+            final Iterator<JcrResourceTypeProviderEntry> i = this.jcrResourceTypeProviders.iterator();
+            while (i.hasNext()) {
+                providers[index] = i.next().provider;
+                index++;
+            }
+        }
+        jcrResourceTypeProvidersArray = providers;
+    }
+
     // ---------- internal helper ----------------------------------------------
 
     /** Returns the JCR repository used by this factory */
@@ -550,7 +550,7 @@
             this.provider = p;
         }
     }
-    
+
     private String getServiceName(ServiceReference reference) {
         if (log.isDebugEnabled()) {
             StringBuilder snBuilder = new StringBuilder(64);



Mime
View raw message