jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r901231 - in /jackrabbit/branches/2.0: ./ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
Date Wed, 20 Jan 2010 15:21:36 GMT
Author: jukka
Date: Wed Jan 20 15:21:35 2010
New Revision: 901231

URL: http://svn.apache.org/viewvc?rev=901231&view=rev
Log:
2.0: Merged revision 901228 (JCR-2459)

Modified:
    jackrabbit/branches/2.0/   (props changed)
    jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
    jackrabbit/branches/2.0/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java

Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jan 20 15:21:35 2010
@@ -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:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,900305,900310,900314,900453,900702,900736,900762-900763,900767,901095,901122,901139,901144,901170,901176,901191,901193,901216
+/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935,897983,897992-897993,897996,898002,898042,898267,898325,898540,898677,898699,898701,898715,898872,899102,899181,899391,899393-899394,899583,899594,899643,900305,900310,900314,900453,900702,900736,900762-900763,900767,900782,901095,901122,901139,901144,901170,901176,901191,901193,901196,901216,901228

Modified: jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=901231&r1=901230&r2=901231&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Wed Jan 20 15:21:35 2010
@@ -139,8 +139,14 @@
                     log.append(": declined");
                 }
             } catch (Exception e) {
-                log.append(": ");
-                log.append(e.getMessage());
+                log.append(": failed");
+                for (Throwable c = e; c != null; c = c.getCause()) {
+                    log.append(newline);
+                    log.append("        because of ");
+                    log.append(c.getClass().getSimpleName());
+                    log.append(": ");
+                    log.append(c.getMessage());
+                }
             }
         }
         log.append(newline);

Modified: jackrabbit/branches/2.0/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java?rev=901231&r1=901230&r2=901231&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
(original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/repository/RmiRepositoryFactory.java
Wed Jan 20 15:21:35 2010
@@ -16,10 +16,16 @@
  */
 package org.apache.jackrabbit.rmi.repository;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
+import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.rmi.Naming;
+import java.rmi.NotBoundException;
+import java.rmi.RemoteException;
 import java.util.Hashtable;
 import java.util.Map;
 
@@ -27,6 +33,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
 import org.apache.jackrabbit.rmi.client.ClientAdapterFactory;
 import org.apache.jackrabbit.rmi.remote.RemoteRepository;
@@ -39,45 +46,100 @@
     @SuppressWarnings("unchecked")
     public Repository getRepository(Map parameters) throws RepositoryException {
         if (parameters != null && parameters.containsKey(REPOSITORY_URI)) {
-            Object parameter = parameters.get(REPOSITORY_URI);
+            URI uri;
             try {
-                URI uri = new URI(parameter.toString().trim());
-                String scheme = uri.getScheme();
-                if ("rmi".equalsIgnoreCase(scheme)) {
-                    return getRepository((RemoteRepository) Naming.lookup(
-                            uri.getSchemeSpecificPart()));
-                } else if ("jndi".equalsIgnoreCase(scheme)) {
-                    Hashtable environment = new Hashtable(parameters);
-                    environment.remove(REPOSITORY_URI);
-                    Object value = new InitialContext(environment).lookup(
-                            uri.getSchemeSpecificPart());
-                    if (value instanceof RemoteRepository) {
-                        return getRepository((RemoteRepository) value);
-                    } else {
-                        return null;
-                    }
-                } else {
-                    InputStream stream = uri.toURL().openStream();
-                    try {
-                        Object remote =
-                            new ObjectInputStream(stream).readObject();
-                        if (remote instanceof RemoteRepository) {
-                            return getRepository((RemoteRepository) remote);
-                        } else {
-                            return null;
-                        }
-                    } finally {
-                        stream.close();
-                    }
-                }
-            } catch (Exception e) {
+                uri = new URI(parameters.get(REPOSITORY_URI).toString().trim());
+            } catch (URISyntaxException e) {
                 return null;
             }
+
+            String scheme = uri.getScheme();
+            if ("rmi".equalsIgnoreCase(scheme)) {
+                return getRmiRepository(uri.getSchemeSpecificPart());
+            } else if ("jndi".equalsIgnoreCase(scheme)) {
+                Hashtable environment = new Hashtable(parameters);
+                environment.remove(REPOSITORY_URI);
+                return getJndiRepository(
+                        uri.getSchemeSpecificPart(), environment);
+            } else {
+                try {
+                    return getUrlRepository(uri.toURL());
+                } catch (MalformedURLException e) {
+                    return null;
+                }
+            }
         } else {
             return null;
         }
     }
 
+    private Repository getUrlRepository(URL url) throws RepositoryException {
+        try {
+            InputStream stream = url.openStream();
+            try {
+                Object remote = new ObjectInputStream(stream).readObject();
+                if (remote instanceof RemoteRepository) {
+                    return getRepository((RemoteRepository) remote);
+                } else {
+                    throw new RepositoryException(
+                            "The resource at URL " + url
+                            + " is not a remote repository stub: "
+                            + remote);
+                }
+            } finally {
+                stream.close();
+            }
+        } catch (ClassNotFoundException e) {
+            throw new RepositoryException(
+                    "The resource at URL " + url
+                    + " requires a class that is not available", e);
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Failed to read the resource at URL " + url, e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private Repository getJndiRepository(String name, Hashtable environment)
+            throws RepositoryException {
+        try {
+            Object value = new InitialContext(environment).lookup(name);
+            if (value instanceof RemoteRepository) {
+                return getRepository((RemoteRepository) value);
+            } else {
+                throw new RepositoryException(
+                        "The JNDI resource " + name
+                        + " is not a remote repository stub: " + value);
+            }
+        } catch (NamingException e) {
+            throw new RepositoryException(
+                    "Failed to look up the JNDI resource " + name, e);
+        }
+    }
+
+    private Repository getRmiRepository(String name)
+            throws RepositoryException {
+        try {
+            Object value = Naming.lookup(name);
+            if (value instanceof RemoteRepository) {
+                return getRepository((RemoteRepository) value);
+            } else {
+                throw new RepositoryException(
+                        "The RMI resource " + name
+                        + " is not a remote repository stub: " + value);
+            }
+        } catch (NotBoundException e) {
+            throw new RepositoryException(
+                    "RMI resource " + name + " not found", e);
+        } catch (MalformedURLException e) {
+            throw new RepositoryException(
+                    "Invalid RMI name: " + name, e);
+        } catch (RemoteException e) {
+            throw new RepositoryException(
+                    "Failed to look up the RMI resource " + name, e);
+        }
+    }
+
     private Repository getRepository(RemoteRepository remote) {
         return new ClientAdapterFactory().getRepository(remote);
     }



Mime
View raw message