jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r396303 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: SearchManager.java nodetype/NodeTypeManagerImpl.java xml/ImportHandler.java
Date Sun, 23 Apr 2006 18:49:25 GMT
Author: jukka
Date: Sun Apr 23 11:49:24 2006
New Revision: 396303

URL: http://svn.apache.org/viewcvs?rev=396303&view=rev
Log:
JCR-409: Use the new NamespaceRegistryImpl.safeRegisterNamespace() method to simplify and
safeguard namespace registration.

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=396303&r1=396302&r2=396303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Sun Apr 23 11:49:24 2006
@@ -210,7 +210,7 @@
      * @throws RepositoryException if the search manager cannot be initialized
      */
     public SearchManager(SearchConfig config,
-                         final NamespaceRegistry nsReg,
+                         final NamespaceRegistryImpl nsReg,
                          NodeTypeRegistry ntReg,
                          ItemStateManager itemMgr,
                          NodeId rootNodeId,
@@ -246,18 +246,8 @@
         };
 
         // register namespaces
-        try {
-            nsReg.getPrefix(NS_XS_URI);
-        } catch (NamespaceException e) {
-            // not yet known
-            nsReg.registerNamespace(NS_XS_PREFIX, NS_XS_URI);
-        }
-        try {
-            nsReg.getPrefix(NS_FN_URI);
-        } catch (RepositoryException e) {
-            // not yet known
-            nsReg.registerNamespace(NS_FN_PREFIX, NS_FN_URI);
-        }
+        nsReg.safeRegisterNamespace(NS_XS_PREFIX, NS_XS_URI);
+        nsReg.safeRegisterNamespace(NS_FN_PREFIX, NS_FN_URI);
 
         Properties params = config.getParameters();
         queryImplClassName = params.getProperty(PARAM_QUERY_IMPL, DEFAULT_QUERY_IMPL_CLASS);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java?rev=396303&r1=396302&r2=396303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeManagerImpl.java
Sun Apr 23 11:49:24 2006
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.util.IteratorHelper;
 import org.apache.jackrabbit.util.name.NamespaceMapping;
 import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.NamespaceRegistryImpl;
 import org.apache.jackrabbit.core.nodetype.compact.CompactNodeTypeDefReader;
 import org.apache.jackrabbit.core.nodetype.compact.ParseException;
 import org.apache.jackrabbit.core.nodetype.xml.NodeTypeReader;
@@ -32,8 +33,6 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
-import javax.jcr.NamespaceException;
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -77,7 +76,7 @@
      * automatically registered when new node type definition files are
      * read.
      */
-    private final NamespaceRegistry nsReg;
+    private final NamespaceRegistryImpl nsReg;
 
     /**
      * The root node definition.
@@ -114,7 +113,7 @@
      * @param nsResolver namespace resolver
      */
     public NodeTypeManagerImpl(
-            NodeTypeRegistry ntReg, NamespaceRegistry nsReg,
+            NodeTypeRegistry ntReg, NamespaceRegistryImpl nsReg,
             NamespaceResolver nsResolver) {
         this.nsResolver = nsResolver;
         this.ntReg = ntReg;
@@ -341,41 +340,6 @@
     }
 
     /**
-     * Registers a single namespace bypassing registration if the namespace
-     * is already registered. A unique prefix is automatically genenerated
-     * if the given prefix is already mapped to another namespace.
-     *
-     * @param prefix The namespace prefix
-     * @param uri The namespace URI
-     * @throws RepositoryException if a repository error occurs
-     */
-    protected void registerNamespace(String prefix, String uri)
-            throws RepositoryException {
-        try {
-            // Check if the uri is already registered
-            nsReg.getPrefix(uri);
-        } catch (NamespaceException e1) {
-            // The uri is not in the registry. The prefix may be with another
-            // uri or it may not be (the ideal scenario).  In either case,
-            // attempt to register it and add a incrementing sequence number
-            // to the prefix until it no longer conflicts with any existing
-            // prefix.
-            String original = prefix;
-            for (int i = 2; true; i++) {
-                try {
-                    // Attempt to register the prefix and uri... if the prefix
-                    // is already registered an exception will be thrown due
-                    // to an attempt to remap.
-                    nsReg.registerNamespace(prefix, uri);
-                    return;
-                } catch (NamespaceException e2) {
-                    prefix = original + i;
-                }
-            }
-        }
-    }
-
-    /**
      * Registers the node types defined in the given XML stream.  This
      * is a trivial implementation that just invokes the existing
      * {@link NodeTypeReader} and {@link NodeTypeRegistry} methods and
@@ -395,7 +359,8 @@
                 Enumeration prefixes = namespaces.propertyNames();
                 while (prefixes.hasMoreElements()) {
                     String prefix = (String) prefixes.nextElement();
-                    registerNamespace(prefix, namespaces.getProperty(prefix));
+                    nsReg.safeRegisterNamespace(
+                            prefix, namespaces.getProperty(prefix));
                 }
             }
 
@@ -437,7 +402,7 @@
               Iterator iterator = nsMap.entrySet().iterator();
               while (iterator.hasNext()) {
                   Map.Entry entry = (Map.Entry) iterator.next();
-                  registerNamespace(
+                  nsReg.safeRegisterNamespace(
                           (String) entry.getKey(), (String) entry.getValue());
               }
 

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java?rev=396303&r1=396302&r2=396303&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/ImportHandler.java
Sun Apr 23 11:49:24 2006
@@ -151,27 +151,11 @@
     public void startPrefixMapping(String prefix, String uri)
             throws SAXException {
         localNamespaceMappings.put(prefix, uri);
-
         try {
-            // this will trigger NamespaceException if namespace is unknown
-            nsReg.getPrefix(uri);
-        } catch (NamespaceException nse) {
-            try {
-                // namespace is not yet registered ...
-                if (prefix.length() == 0) {
-                    /**
-                     * the xml document specifies a default namespace
-                     * (i.e. an empty prefix); we need to create a random
-                     * prefix as the empty prefix is reserved according
-                     * to the JCR spec.
-                     */
-                    prefix = nsReg.getUniquePrefix(uri);
-                }
-                // register new namespace
-                nsReg.registerNamespace(prefix, uri);
-            } catch (RepositoryException re) {
-                throw new SAXException(re);
-            }
+            // Register the namespace unless already registered
+            nsReg.safeRegisterNamespace(prefix, uri);
+        } catch (RepositoryException re) {
+            throw new SAXException(re);
         }
     }
 



Mime
View raw message