jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r424218 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit: core/ core/nodetype/compact/ core/xml/ name/ util/
Date Fri, 21 Jul 2006 07:50:18 GMT
Author: tripod
Date: Fri Jul 21 00:50:17 2006
New Revision: 424218

URL: http://svn.apache.org/viewvc?rev=424218&view=rev
Log:
JCR-476: Remove recently added getJCRPath()/getQPath() from NamespaceResolver

Added:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java  
(with props)
Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingNamespaceResolver.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/LocalNamespaceMappings.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/AbstractNamespaceResolver.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NamespaceResolver.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/PathFormat.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/util/Locked.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingNamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingNamespaceResolver.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingNamespaceResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/CachingNamespaceResolver.java
Fri Jul 21 00:50:17 2006
@@ -16,18 +16,16 @@
  */
 package org.apache.jackrabbit.core;
 
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NamespaceListener;
+import org.apache.commons.collections.map.LRUMap;
 import org.apache.jackrabbit.name.AbstractNamespaceResolver;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.MalformedPathException;
-import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.IllegalNameException;
 import org.apache.jackrabbit.name.NameFormat;
-import org.apache.commons.collections.map.LRUMap;
+import org.apache.jackrabbit.name.NamespaceListener;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NameCache;
+import org.apache.jackrabbit.name.UnknownPrefixException;
 
 import javax.jcr.NamespaceException;
 import java.util.Map;
@@ -38,7 +36,7 @@
  * mapping is changed.
  */
 class CachingNamespaceResolver
-        implements NamespaceResolver, NamespaceListener {
+        implements NamespaceResolver, NamespaceListener, NameCache {
 
     /**
      * The base namespace resolver.
@@ -84,57 +82,62 @@
     }
 
     /**
-     * @inheritDoc
+     * @deprecated use {@link NameFormat#parse(String, NamespaceResolver)}
      */
     public synchronized QName getQName(String name)
             throws IllegalNameException, UnknownPrefixException {
-        QName qName = (QName) jcrNameToQName.get(name);
-        if (qName == null) {
-            qName = NameFormat.parse(name, this);
-            jcrNameToQName.put(name, qName);
-        }
-        return qName;
+        return NameFormat.parse(name, this);
     }
 
     /**
-     * @inheritDoc
+     * @deprecated use {@link NameFormat#format(QName, NamespaceResolver)}
      */
     public synchronized String getJCRName(QName name)
             throws NoPrefixDeclaredException {
-        String jcrName = (String) qnameToJCRName.get(name);
-        if (jcrName == null) {
-            jcrName = NameFormat.format(name, this);
-            qnameToJCRName.put(name, jcrName);
-        }
-        return jcrName;
+        return NameFormat.format(name, this);
+    }
+
+    /**
+     * Disposes this <code>CachingNamespaceResolver</code>.
+     */
+    public void dispose() {
+        base.removeListener(this);
     }
 
+    //------------------------------------------------------------< QNameCache >
+
     /**
      * @inheritDoc
-     * As currently paths are not cached, the call is delegated to
-     * {@link PathFormat#parse(String, NamespaceResolver)}.
      */
-    public Path getQPath(String jcrPath) throws MalformedPathException {
-        return PathFormat.parse(jcrPath, this);
+    public synchronized QName retrieveName(String jcrName) {
+        return (QName) jcrNameToQName.get(jcrName);
     }
 
     /**
      * @inheritDoc
-     * As currently paths are not cached, the call is delegated to
-     * {@link PathFormat#format(Path, NamespaceResolver)}.
      */
-    public String getJCRPath(Path qPath) throws NoPrefixDeclaredException {
-        return PathFormat.format(qPath, this);
+    public synchronized String retrieveName(QName name) {
+        return (String) qnameToJCRName.get(name);
     }
 
     /**
-     * Disposes this <code>CachingNamespaceResolver</code>.
+     * @inheritDoc
      */
-    public void dispose() {
-        base.removeListener(this);
+    public synchronized void cacheName(String jcrName, QName name) {
+        qnameToJCRName.put(name, jcrName);
+        jcrNameToQName.put(jcrName, name);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public synchronized void evictAllNames() {
+        qnameToJCRName.clear();
+        jcrNameToQName.clear();
     }
 
     //----------------------------------------------------< NamespaceListener >
+
     /**
      * @inheritDoc
      */
@@ -148,8 +151,7 @@
      * Invalidates all cached mappings.
      */
     public void namespaceRemapped(String oldPrefix, String newPrefix, String uri) {
-        qnameToJCRName.clear();
-        jcrNameToQName.clear();
+        evictAllNames();
     }
 
     /**
@@ -157,7 +159,6 @@
      * Invalidates all cached mappings.
      */
     public void namespaceRemoved(String uri) {
-        qnameToJCRName.clear();
-        jcrNameToQName.clear();
+        evictAllNames();
     }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/LocalNamespaceMappings.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/LocalNamespaceMappings.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/LocalNamespaceMappings.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/LocalNamespaceMappings.java
Fri Jul 21 00:50:17 2006
@@ -16,20 +16,17 @@
  */
 package org.apache.jackrabbit.core;
 
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.AbstractNamespaceResolver;
 import org.apache.jackrabbit.name.NamespaceListener;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.util.XMLChar;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Arrays;
 
 /**
  * Manager for local session namespace mappings. This class is
@@ -159,31 +156,7 @@
         nsReg.removeListener(this);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public QName getQName(String name)
-            throws IllegalNameException, UnknownPrefixException {
-        if (prefixToURI.isEmpty()) {
-            // shortcut
-            return nsReg.getQName(name);
-        }
-        try {
-            // first try registry, this might result in a wrong QName because
-            // of locally overlayed mappings
-            QName candidate = nsReg.getQName(name);
-            // make sure global prefix is not hidden because of
-            // locally remapped uri
-            if (!uriToPrefix.containsKey(candidate.getNamespaceURI())) {
-                return candidate;
-            }
-        } catch (UnknownPrefixException e) {
-            // try using local mappings
-        }
-        return super.getQName(name);
-    }
-
-    //----------------------------------------------------< NamespaceResolver >
+    //-----------------------------------------------------< NamespaceResolver >
     /**
      * {@inheritDoc}
      */
@@ -230,25 +203,7 @@
         return nsReg.getPrefix(uri);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public String getJCRName(QName name)
-            throws NoPrefixDeclaredException {
-        if (uriToPrefix.isEmpty()) {
-            // shortcut
-            return nsReg.getJCRName(name);
-        }
-        if (uriToPrefix.containsKey(name.getNamespaceURI())) {
-            // locally remappped
-            return super.getJCRName(name);
-        } else {
-            // use global mapping
-            return nsReg.getJCRName(name);
-        }
-    }
-
-    //----------------------------------------------------< NamespaceListener >
+    //-----------------------------------------------------< NamespaceListener >
     /**
      * @inheritDoc
      * This method gets called when a new namespace is registered in

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
Fri Jul 21 00:50:17 2006
@@ -18,11 +18,9 @@
 
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
-import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.AbstractNamespaceResolver;
-import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.UnknownPrefixException;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NameCache;
 import org.apache.jackrabbit.util.XMLChar;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +41,7 @@
  * A <code>NamespaceRegistryImpl</code> ...
  */
 public class NamespaceRegistryImpl extends AbstractNamespaceResolver
-        implements NamespaceRegistry {
+        implements NamespaceRegistry, NameCache {
 
     private static Logger log = LoggerFactory.getLogger(NamespaceRegistryImpl.class);
 
@@ -383,18 +381,27 @@
         return prefix;
     }
 
+    //------------------------------------------------------------< QNameCache >
     /**
      * {@inheritDoc}
      */
-    public QName getQName(String name)
-            throws IllegalNameException, UnknownPrefixException {
-        return resolver.getQName(name);
+    public QName retrieveName(String jcrName) {
+        // just delegate to internal cache
+        return resolver.retrieveName(jcrName);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public String getJCRName(QName name) throws NoPrefixDeclaredException {
-        return resolver.getJCRName(name);
+    public String retrieveName(QName name) {
+        // just delegate to internal cache
+        return resolver.retrieveName(name);
+    }
+
+    public void cacheName(String jcrName, QName name) {
+        // just delegate to internal cache
+        resolver.cacheName(jcrName, name);
+    }
+
+    public void evictAllNames() {
+        // just delegate to internal cache
+        resolver.evictAllNames();
     }
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/NodeImpl.java Fri
Jul 21 00:50:17 2006
@@ -49,6 +49,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
 import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.util.ChildrenCollectorFilter;
 import org.apache.jackrabbit.util.IteratorHelper;
 import org.apache.jackrabbit.uuid.UUID;
@@ -163,7 +164,7 @@
              * have to build & resolve absolute path)
              */
             if (relPath.indexOf('/') == -1) {
-                QName propName = session.getNamespaceResolver().getQName(relPath);
+                QName propName = NameFormat.parse(relPath, session.getNamespaceResolver());
                 // check if property entry exists
                 NodeState thisState = (NodeState) state;
                 if (thisState.hasPropertyName(propName)) {
@@ -401,7 +402,7 @@
             throws ConstraintViolationException, RepositoryException {
         QName qName;
         try {
-            qName = session.getNamespaceResolver().getQName(name);
+            qName = NameFormat.parse(name, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid property name: " + name, ine);
         } catch (UnknownPrefixException upe) {
@@ -578,7 +579,7 @@
     protected void removeChildProperty(String propName) throws RepositoryException {
         QName qName;
         try {
-            qName = session.getNamespaceResolver().getQName(propName);
+            qName = NameFormat.parse(propName, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid property name: "
                     + propName, ine);
@@ -1866,7 +1867,7 @@
 
         QName name = session.getHierarchyManager().getName(id);
         try {
-            return session.getNamespaceResolver().getJCRName(name);
+            return NameFormat.format(name, session.getNamespaceResolver());
         } catch (NoPrefixDeclaredException npde) {
             // should never get here...
             String msg = "internal error: encountered unregistered namespace "
@@ -2556,7 +2557,7 @@
     public boolean isNodeType(String nodeTypeName) throws RepositoryException {
         QName ntName;
         try {
-            ntName = session.getNamespaceResolver().getQName(nodeTypeName);
+            ntName = NameFormat.parse(nodeTypeName, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid node type name: " + nodeTypeName, ine);
         } catch (UnknownPrefixException upe) {
@@ -2603,7 +2604,7 @@
             ConstraintViolationException, LockException, RepositoryException {
         QName ntName;
         try {
-            ntName = session.getNamespaceResolver().getQName(mixinName);
+            ntName = NameFormat.parse(mixinName, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid mixin type name: " + mixinName, ine);
         } catch (UnknownPrefixException upe) {
@@ -2621,7 +2622,7 @@
             ConstraintViolationException, LockException, RepositoryException {
         QName ntName;
         try {
-            ntName = session.getNamespaceResolver().getQName(mixinName);
+            ntName = NameFormat.parse(mixinName, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid mixin type name: " + mixinName, ine);
         } catch (UnknownPrefixException upe) {
@@ -2656,7 +2657,7 @@
 
         QName ntName;
         try {
-            ntName = session.getNamespaceResolver().getQName(mixinName);
+            ntName = NameFormat.parse(mixinName, session.getNamespaceResolver());
         } catch (IllegalNameException ine) {
             throw new RepositoryException("invalid mixin type name: "
                     + mixinName, ine);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri Jul 21 00:50:17 2006
@@ -25,6 +25,7 @@
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.value.BooleanValue;
 import org.apache.jackrabbit.value.DateValue;
@@ -179,7 +180,7 @@
             case PropertyType.NAME:
                 QName name = (QName) value.internalValue();
                 try {
-                    return session.getNamespaceResolver().getJCRName(name).length();
+                    return NameFormat.format(name, session.getNamespaceResolver()).length();
                 } catch (NoPrefixDeclaredException npde) {
                     // should never happen...
                     String msg = safeGetJCRPath()
@@ -1162,7 +1163,7 @@
 
         QName name = ((PropertyId) id).getName();
         try {
-            return session.getNamespaceResolver().getJCRName(name);
+            return NameFormat.format(name, session.getNamespaceResolver());
         } catch (NoPrefixDeclaredException npde) {
             // should never get here...
             String msg = "internal error: encountered unregistered namespace " + name.getNamespaceURI();

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
Fri Jul 21 00:50:17 2006
@@ -435,7 +435,7 @@
                 if (ntd.getPrimaryItemName() != null) {
                     String name = null;
                     try {
-                        name = nsMapping.getJCRName(ntd.getName());
+                        name = NameFormat.format(ntd.getName(), nsMapping);
                     } catch (NoPrefixDeclaredException e) {
                         // Should never happen, checked earlier
                     }
@@ -589,7 +589,7 @@
                 if (ntd.getPrimaryItemName() != null) {
                     String name = null;
                     try {
-                        name = nsMapping.getJCRName(ntd.getName());
+                        name = NameFormat.format(ntd.getName(), nsMapping);
                     } catch (NoPrefixDeclaredException e) {
                         // Should never happen, checked earlier
                     }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/DocViewImportHandler.java
Fri Jul 21 00:50:17 2006
@@ -239,7 +239,7 @@
         QName[] qnames = new QName[names.length];
         for (int i = 0; i < names.length; i++) {
             try {
-                qnames[i] = nsContext.getQName(names[i]);
+                qnames[i] = NameFormat.parse(names[i], nsContext);
             } catch (NameException ne) {
                 throw new SAXException("Invalid name: " + names[i], ne);
             }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
Fri Jul 21 00:50:17 2006
@@ -17,12 +17,9 @@
 package org.apache.jackrabbit.core.xml;
 
 import org.apache.jackrabbit.name.IllegalNameException;
-import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.name.NameFormat;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
 
@@ -129,14 +126,6 @@
     /** {@inheritDoc} */
     public String getJCRName(QName name) throws NoPrefixDeclaredException {
         return NameFormat.format(name, this);
-    }
-
-    public Path getQPath(String jcrPath) throws MalformedPathException {
-        return PathFormat.parse(jcrPath, this);
-    }
-
-    public String getJCRPath(Path qPath) throws NoPrefixDeclaredException {
-        return PathFormat.format(qPath, this);
     }
 
     /** {@inheritDoc} */

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/AbstractNamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/AbstractNamespaceResolver.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/AbstractNamespaceResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/AbstractNamespaceResolver.java
Fri Jul 21 00:50:17 2006
@@ -38,35 +38,6 @@
     private final Set listeners;
 
     /**
-     * @inheritDoc
-     */
-    public QName getQName(String jcrName)
-            throws IllegalNameException, UnknownPrefixException {
-        return NameFormat.parse(jcrName, this);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public String getJCRName(QName qName) throws NoPrefixDeclaredException {
-        return NameFormat.format(qName, this);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public Path getQPath(String jcrPath) throws MalformedPathException {
-        return PathFormat.parse(jcrPath, this);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public String getJCRPath(Path qPath) throws NoPrefixDeclaredException {
-        return PathFormat.format(qPath, this);
-    }
-
-    /**
      * Creates a <code>AbstractNamespaceResolver</code> without listener
      * support.
      */
@@ -87,6 +58,25 @@
         } else {
             listeners = null;
         }
+    }
+
+    /**
+     * @inheritDoc
+     *
+     * @deprecated use {@link NameFormat#parse(String, NamespaceResolver)} instead.
+     */
+    public QName getQName(String jcrName)
+            throws IllegalNameException, UnknownPrefixException {
+        return NameFormat.parse(jcrName, this);
+    }
+
+    /**
+     * @inheritDoc
+     *
+     * @deprecated use {@link NameFormat#format(QName, NamespaceResolver)} instead.
+     */
+    public String getJCRName(QName qName) throws NoPrefixDeclaredException {
+        return NameFormat.format(qName, this);
     }
 
     //--------------------------------------------< NamespaceListener support >

Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java?rev=424218&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java Fri
Jul 21 00:50:17 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.jackrabbit.name;
+
+/**
+ * The name cache defines an interface that is used by the {@link NameFormat}
+ * and is usually implemented by {@link NamespaceResolver}s.
+ * <p/>
+ * Please note, that the redundant naming of the methods is intentionally in
+ * order to allow a class to implement several caches.
+ */
+public interface NameCache {
+
+    /**
+     * Retrieves a qualified name from the cache for the given jcr name. If the
+     * name is not cached <code>null</code> is returned.
+     *
+     * @param jcrName the jcr name
+     * @return the qualified name or <code>null</code>
+     */
+    public QName retrieveName(String jcrName);
+
+    /**
+     * Retrieves a jcr name from the cache for the given qualified name. If the
+     * name is not cached <code>null</code> is returned.
+     *
+     * @param name the qualified name
+     * @return the jcr name or <code>null</code>
+     */
+    public String retrieveName(QName name);
+
+    /**
+     * Puts a name into the cache.
+     *
+     * @param jcrName the jcr name
+     * @param name the qualified name
+     */
+    public void cacheName(String jcrName, QName name);
+
+    /**
+     * Evicts all names from the cache, i.e. clears it.
+     */
+    public void evictAllNames();
+
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameCache.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url rev

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java Fri
Jul 21 00:50:17 2006
@@ -53,7 +53,9 @@
     };
 
     /**
-     * Parses the <code>jcrName</code> and returns a new <code>QName</code>.
+     * Parses the <code>jcrName</code> and returns a new <code>QName</code>.
If
+     * the passed <code>resolver</code> also an instance of {@link NameCache}
+     * then the parsing is first read from the cache.
      *
      * @param jcrName the name to be parsed
      * @param resolver <code>NamespaceResolver</code> use to retrieve the
@@ -62,7 +64,34 @@
      * @throws IllegalNameException If <code>jcrName</code> is not a valid
      * JCR-style name.
      */
-    public static QName parse(String jcrName, NamespaceResolver resolver) throws IllegalNameException,
UnknownPrefixException {
+    public static QName parse(String jcrName, NamespaceResolver resolver)
+            throws IllegalNameException, UnknownPrefixException {
+
+        if (resolver instanceof NameCache) {
+            QName name = ((NameCache) resolver).retrieveName(jcrName);
+            if (name == null) {
+                name = parseNoCache(jcrName, resolver);
+                ((NameCache) resolver).cacheName(jcrName, name);
+            }
+            return name;
+        } else {
+            return parseNoCache(jcrName, resolver);
+        }
+    }
+
+    /**
+     * Parses the <code>jcrName</code> and returns a new <code>QName</code>,
+     * but does not respect possible caches.
+     *
+     * @param jcrName the name to be parsed
+     * @param resolver <code>NamespaceResolver</code> use to retrieve the
+     * namespace URI from the prefix contained in the given JCR name.
+     * @return qName the new <code>QName</code>
+     * @throws IllegalNameException If <code>jcrName</code> is not a valid
+     * JCR-style name.
+     */
+    private static QName parseNoCache(String jcrName, NamespaceResolver resolver)
+            throws IllegalNameException, UnknownPrefixException {
         String[] parts = parse(jcrName);
         String uri;
         try {
@@ -70,7 +99,6 @@
         } catch (NamespaceException nse) {
             throw new UnknownPrefixException(parts[0]);
         }
-
         return new QName(uri, parts[1]);
     }
 
@@ -140,7 +168,8 @@
 
     /**
      * Returns a string representation of the qualified <code>name</code> in
the
-     * JCR name format.
+     * JCR name format. If the passed <code>resolver</code> also an instance
of
+     * {@link NameCache} then the formatting is first read from the cache.
      *
      * @param qName the qualified name to resolve.
      * @param resolver the namespace resolver.
@@ -150,14 +179,28 @@
      */
     public static String format(QName qName, NamespaceResolver resolver)
             throws NoPrefixDeclaredException {
-        StringBuffer buf = new StringBuffer();
-        format(qName, resolver, buf);
-        return buf.toString();
+
+        if (resolver instanceof NameCache) {
+            String jcrName = ((NameCache) resolver).retrieveName(qName);
+            if (jcrName == null) {
+                StringBuffer buf = new StringBuffer();
+                formatNoCache(qName, resolver, buf);
+                jcrName = buf.toString();
+                ((NameCache) resolver).cacheName(jcrName, qName);
+            }
+            return jcrName;
+
+        } else {
+            StringBuffer buf = new StringBuffer();
+            formatNoCache(qName, resolver, buf);
+            return buf.toString();
+        }
     }
 
     /**
      * Returns a string representation of the qualified <code>name</code> in
the
-     * JCR name format.
+     * JCR name format. If the passed <code>resolver</code> also an instance
of
+     * {@link NameCache} then the formatting is first read from the cache.
      *
      * @param qName the qualified name to resolve.
      * @param resolver the namespace resolver.
@@ -166,6 +209,34 @@
      * @see #format(QName, NamespaceResolver)
      */
     public static void format(QName qName, NamespaceResolver resolver, StringBuffer buffer)
+            throws NoPrefixDeclaredException {
+
+        if (resolver instanceof NameCache) {
+            String jcrName = ((NameCache) resolver).retrieveName(qName);
+            if (jcrName == null) {
+                int l = buffer.length();
+                formatNoCache(qName, resolver, buffer);
+                ((NameCache) resolver).cacheName(buffer.substring(l), qName);
+            } else {
+                buffer.append(jcrName);
+            }
+        } else {
+            formatNoCache(qName, resolver, buffer);
+        }
+    }
+
+    /**
+     * Returns a string representation of the qualified <code>name</code> in
the
+     * JCR name format, but does not respect possible caches.
+     *
+     * @param qName the qualified name to resolve.
+     * @param resolver the namespace resolver.
+     * @param buffer StringBuffer where the prefixed JCR name should be appended to.
+     * @throws NoPrefixDeclaredException if a namespace can not be resolved
+     *
+     * @see #format(QName, NamespaceResolver)
+     */
+    private static void formatNoCache(QName qName, NamespaceResolver resolver, StringBuffer
buffer)
             throws NoPrefixDeclaredException {
         // prefix
         String prefix;

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NamespaceResolver.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NamespaceResolver.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NamespaceResolver.java
Fri Jul 21 00:50:17 2006
@@ -53,6 +53,8 @@
      * @return the QName instance for the raw name.
      * @throws IllegalNameException   if the given name is not a valid JCR name
      * @throws UnknownPrefixException if the JCR name prefix does not resolve
+     *
+     * @deprecated use {@link NameFormat#parse(String, NamespaceResolver)} instead.
      */
     public QName getQName(String jcrName)
             throws IllegalNameException, UnknownPrefixException;
@@ -63,23 +65,9 @@
      * @param qName a qualified name
      * @return the raw JCR name
      * @throws NoPrefixDeclaredException if the namespace can not be resolved
-     */
-    public String getJCRName(QName qName) throws NoPrefixDeclaredException;
-
-    /**
-     * Parses the given prefixed JCR Path into a qualified path.
      *
-     * @param jcrPath the raw path, with potentially prefixed path elements.
-     * @return the Path instance for the raw path.
+     * @deprecated use {@link NameFormat#format(QName, NamespaceResolver)} instead.
      */
-    public Path getQPath(String jcrPath) throws MalformedPathException;
+    public String getJCRName(QName qName) throws NoPrefixDeclaredException;
 
-    /**
-     * Returns the qualified path in the prefixed JCR path format.
-     *
-     * @param qPath a qualified path
-     * @return the corresponding JCR path, eventually containing prefixed elements.
-     * @throws NoPrefixDeclaredException if a namespace can not be resolved
-     */
-    public String getJCRPath(Path qPath) throws NoPrefixDeclaredException;
 }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/PathFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/PathFormat.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/PathFormat.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/PathFormat.java Fri
Jul 21 00:50:17 2006
@@ -250,10 +250,11 @@
      * @throws NoPrefixDeclaredException if the namespace of the path element
      *                                   name can not be resolved
      */
-    private static void format(Path.PathElement element, NamespaceResolver resolver, StringBuffer
buf)
+    private static void format(Path.PathElement element,
+                               NamespaceResolver resolver, StringBuffer buf)
             throws NoPrefixDeclaredException {
         // name
-        buf.append(resolver.getJCRName(element.getName()));
+        NameFormat.format(element.getName(), resolver, buf);
         // index
         int index = element.getIndex();
         /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/util/Locked.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/util/Locked.java?rev=424218&r1=424217&r2=424218&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/util/Locked.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/util/Locked.java Fri Jul
21 00:50:17 2006
@@ -16,6 +16,11 @@
  */
 package org.apache.jackrabbit.util;
 
+import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.SessionNamespaceResolver;
+
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -28,10 +33,6 @@
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.ObservationManager;
 
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.SessionNamespaceResolver;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-
 /**
  * <code>Locked</code> is a utility to synchronize modifications on a lockable
  * node. The modification is applied while the lock on the node is held, thus
@@ -138,7 +139,7 @@
         EventListener listener = null;
         try {
             // check whether the lockable can be locked at all
-            if (!lockable.isNodeType(resolver.getJCRName(QName.MIX_LOCKABLE))) {
+            if (!lockable.isNodeType(NameFormat.format(QName.MIX_LOCKABLE, resolver))) {
                 throw new IllegalArgumentException("Node is not lockable");
             }
 



Mime
View raw message