jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r897858 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Date Mon, 11 Jan 2010 13:47:35 GMT
Author: jukka
Date: Mon Jan 11 13:47:34 2010
New Revision: 897858

URL: http://svn.apache.org/viewvc?rev=897858&view=rev
Log:
JCR-2459: Improved error reporting from JcrUtils.getRepository

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=897858&r1=897857&r2=897858&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Mon Jan 11 13:47:34 2010
@@ -96,20 +96,51 @@
      */
     public static Repository getRepository(Map<String, String> parameters)
             throws RepositoryException {
+        String newline = System.getProperty("line.separator");
+
+        // Prepare the potential error message (JCR-2459)
+        StringBuilder log = new StringBuilder("Unable to access a repository");
+        if (parameters != null) {
+            log.append(" with the following settings:");
+            for (Map.Entry<String, String> entry : parameters.entrySet()) {
+                log.append(newline);
+                log.append("    ");
+                log.append(entry.getKey());
+                log.append(": ");
+                log.append(entry.getValue());
+            }
+        } else {
+            log.append(" with the default settings.");
+        }
+
+        // Iterate through the available RepositoryFactories, with logging
+        log.append(newline);
+        log.append("The following RepositoryFactory classes were consulted:");
         Iterator<RepositoryFactory> iterator =
             ServiceRegistry.lookupProviders(RepositoryFactory.class);
-
         while (iterator.hasNext()) {
             RepositoryFactory factory = iterator.next();
-            Repository repository = factory.getRepository(parameters);
-            if (repository != null) {
-                return repository;
+            log.append(newline);
+            log.append("    ");
+            log.append(factory.getClass().getName());
+            try {
+                Repository repository = factory.getRepository(parameters);
+                if (repository != null) {
+                    // We found the requested repository! Return it
+                    // and just ignore the error message being built.
+                    return repository;
+                } else {
+                    log.append(": declined");
+                }
+            } catch (Exception e) {
+                log.append(": ");
+                log.append(e.getMessage());
             }
         }
 
-        throw new RepositoryException(
-                "No repository factory can handle the given configuration: "
-                + parameters);
+        // No matching repository found. Throw an exception with the
+        // detailed information we gathered during the above process.
+        throw new RepositoryException(log.toString());
     }
 
     /**



Mime
View raw message