jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r892254 - in /jackrabbit/branches/2.0: ./ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
Date Fri, 18 Dec 2009 13:59:33 GMT
Author: jukka
Date: Fri Dec 18 13:59:33 2009
New Revision: 892254

URL: http://svn.apache.org/viewvc?rev=892254&view=rev
Log:
2.0: Merged revision 892253 (JCR-2443)

Modified:
    jackrabbit/branches/2.0/   (props changed)
    jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java

Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec 18 13:59:33 2009
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:891629
+/jackrabbit/trunk:891629,892253

Modified: jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java?rev=892254&r1=892253&r2=892254&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
Fri Dec 18 13:59:33 2009
@@ -65,8 +65,10 @@
      * <code>super.logout()</code> when overriding this method to avoid
      * namespace mappings to be carried over to a new session.
      */
-    public synchronized void logout() {
-        namespaces.clear();
+    public void logout() {
+        synchronized (namespaces) {
+            namespaces.clear();
+        }
     }
 
     //------------------------------------------------< Namespace handling >--
@@ -84,25 +86,27 @@
      * @throws NamespaceException if the namespace is not found
      * @throws RepositoryException if a repository error occurs
      */
-    public synchronized String getNamespacePrefix(String uri)
+    public String getNamespacePrefix(String uri)
             throws NamespaceException, RepositoryException {
-        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
-            if (entry.getValue().equals(uri)) {
-                return entry.getKey();
+        synchronized (namespaces) {
+            for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                if (entry.getValue().equals(uri)) {
+                    return entry.getKey();
+                }
             }
-        }
 
-        // The following throws an exception if the URI is not found, that's OK
-        String prefix = getWorkspace().getNamespaceRegistry().getPrefix(uri);
+            // The following throws an exception if the URI is not found, that's OK
+            String prefix = getWorkspace().getNamespaceRegistry().getPrefix(uri);
 
-        // Generate a new prefix if the global mapping is already taken
-        String base = prefix;
-        for (int i = 2; namespaces.containsKey(prefix); i++) {
-            prefix = base + i;
-        }
+            // Generate a new prefix if the global mapping is already taken
+            String base = prefix;
+            for (int i = 2; namespaces.containsKey(prefix); i++) {
+                prefix = base + i;
+            }
 
-        namespaces.put(prefix, uri);
-        return prefix;
+            namespaces.put(prefix, uri);
+            return prefix;
+        }
     }
 
     /**
@@ -118,24 +122,26 @@
      * @throws NamespaceException if the namespace is not found
      * @throws RepositoryException if a repository error occurs
      */
-    public synchronized String getNamespaceURI(String prefix)
+    public String getNamespaceURI(String prefix)
             throws NamespaceException, RepositoryException {
-        String uri = namespaces.get(prefix);
+        synchronized (namespaces) {
+            String uri = namespaces.get(prefix);
 
-        if (uri == null) {
-            // Not in local mappings, try the global ones
-            uri = getWorkspace().getNamespaceRegistry().getURI(prefix);
-            if (namespaces.containsValue(uri)) {
-                // The global URI is locally mapped to some other prefix,
-                // so there are no mappings for this prefix
-                throw new NamespaceException("Namespace not found: " + prefix);
+            if (uri == null) {
+                // Not in local mappings, try the global ones
+                uri = getWorkspace().getNamespaceRegistry().getURI(prefix);
+                if (namespaces.containsValue(uri)) {
+                    // The global URI is locally mapped to some other prefix,
+                    // so there are no mappings for this prefix
+                    throw new NamespaceException("Namespace not found: " + prefix);
+                }
+                // Add the mapping to the local set, we already know that
+                // the prefix is not taken
+                namespaces.put(prefix, uri);
             }
-            // Add the mapping to the local set, we already know that
-            // the prefix is not taken
-            namespaces.put(prefix, uri);
-        }
 
-        return uri;
+            return uri;
+        }
     }
 
     /**
@@ -149,13 +155,15 @@
      * @return namespace prefixes
      * @throws RepositoryException if a repository error occurs
      */
-    public synchronized String[] getNamespacePrefixes()
+    public String[] getNamespacePrefixes()
             throws RepositoryException {
         for (String uri : getWorkspace().getNamespaceRegistry().getURIs()) {
             getNamespacePrefix(uri);
         }
 
-        return namespaces.keySet().toArray(new String[namespaces.size()]);
+        synchronized (namespaces) {
+            return namespaces.keySet().toArray(new String[namespaces.size()]);
+        }
     }
 
     /**
@@ -170,7 +178,7 @@
      * @throws NamespaceException if the mapping is illegal
      * @throws RepositoryException if a repository error occurs
      */
-    public synchronized void setNamespacePrefix(String prefix, String uri)
+    public void setNamespacePrefix(String prefix, String uri)
             throws NamespaceException, RepositoryException {
         if (prefix == null) {
             throw new IllegalArgumentException("Prefix must not be null");
@@ -190,20 +198,22 @@
                     "Prefix is not a valid XML NCName: " + prefix);
         }
 
-        // Remove existing mapping for the given prefix
-        namespaces.remove(prefix);
-
-        // Remove existing mapping(s) for the given URI
-        Set<String> prefixes = new HashSet<String>();
-        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
-            if (entry.getValue().equals(uri)) {
-                prefixes.add(entry.getKey());
+        synchronized (namespaces) {
+            // Remove existing mapping for the given prefix
+            namespaces.remove(prefix);
+
+            // Remove existing mapping(s) for the given URI
+            Set<String> prefixes = new HashSet<String>();
+            for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                if (entry.getValue().equals(uri)) {
+                    prefixes.add(entry.getKey());
+                }
             }
-        }
-        namespaces.keySet().removeAll(prefixes);
+            namespaces.keySet().removeAll(prefixes);
 
-        // Add the new mapping
-        namespaces.put(prefix, uri);
+            // Add the new mapping
+            namespaces.put(prefix, uri);
+        }
     }
 
     //---------------------------------------------< XML export and import >--



Mime
View raw message