jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r543975 - in /jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client: URLRMIRepository.java URLRMIRepositoryFactory.java
Date Sun, 03 Jun 2007 20:12:06 GMT
Author: jukka
Date: Sun Jun  3 13:12:06 2007
New Revision: 543975

URL: http://svn.apache.org/viewvc?view=rev&rev=543975
Log:
JCR-956: Support for accessing a remote repository using a URL

Added:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java
  (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java
  (with props)

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java?view=auto&rev=543975
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java
Sun Jun  3 13:12:06 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.rmi.client;
+
+import java.net.URL;
+
+import org.apache.jackrabbit.commons.repository.ProxyRepository;
+
+/**
+ * Proxy for a remote repository accessed via a URL. The configured URL is
+ * dereferenced lazily during each method call. Thus the resource pointed to
+ * by the URL does not need to exist when this class is instantiated. The
+ * resource can also be replaced with another remote repository instance
+ * during the lifetime of an instance of this class.
+ *
+ * @since 1.4
+ */
+public class URLRMIRepository extends ProxyRepository {
+
+    /**
+     * Creates a proxy for the remote repository at the given URL.
+     *
+     * @param factory local adapter factory
+     * @param url URL of the remote repository
+     */
+    public URLRMIRepository(LocalAdapterFactory factory, URL url) {
+        super(new URLRMIRepositoryFactory(factory, url));
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java?view=auto&rev=543975
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java
Sun Jun  3 13:12:06 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.rmi.client;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.net.URL;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
+import org.apache.jackrabbit.rmi.remote.RemoteRepository;
+
+/**
+ * Factory that looks up a remote repository from a given URL.
+ *
+ * @since 1.4
+ */
+public class URLRMIRepositoryFactory implements RepositoryFactory {
+
+    /**
+     * Local adapter factory.
+     */
+    private final LocalAdapterFactory factory;
+
+    /**
+     * URL of the remote repository.
+     */
+    private final URL url;
+
+    /**
+     * Creates a factory for looking up a remote repository from a URL.
+     *
+     * @param factory local adapter factory
+     * @param url URL or the remote repository
+     */
+    public URLRMIRepositoryFactory(LocalAdapterFactory factory, URL url) {
+        this.factory = factory;
+        this.url = url;
+    }
+
+    /**
+     * Looks up and returns a remote repository from the configured URL.
+     *
+     * @return local adapter for the remote repository
+     * @throws RepositoryException if the repository could not be accessed
+     */
+    public Repository getRepository() throws RepositoryException {
+        try {
+            ObjectInputStream input = new ObjectInputStream(url.openStream());
+            try {
+                Object remote = input.readObject();
+                if (remote instanceof RemoteRepository) {
+                    return factory.getRepository((RemoteRepository) remote);
+                } else if (remote == null) {
+                    throw new RepositoryException(
+                            "Remote repository not found: The resource at "
+                            + url + " is null");
+                } else {
+                    throw new RepositoryException(
+                            "Invalid remote repository: The resource at "
+                            + url + " is an instance of "
+                            + remote.getClass().getName());
+                }
+            } finally {
+                input.close();
+            }
+        } catch (ClassNotFoundException e) {
+            throw new RepositoryException(
+                    "Invalid remote repository: The resource at " + url
+                    + " is an instance of an unknown class", e);
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Remote repository not found: The resource at " + url
+                    + " could not be retrieved", e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/URLRMIRepositoryFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message