You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/12/18 14:58:33 UTC
svn commit: r892253 -
/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
Author: jukka
Date: Fri Dec 18 13:58:33 2009
New Revision: 892253
URL: http://svn.apache.org/viewvc?rev=892253&view=rev
Log:
JCR-2443: AbstractSession should not synchronize on the session instance
Modified:
jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java?rev=892253&r1=892252&r2=892253&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java Fri Dec 18 13:58: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 >--