jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r606928 - in /jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet: ./ jackrabbit/ remote/
Date Wed, 26 Dec 2007 18:29:56 GMT
Author: jukka
Date: Wed Dec 26 10:29:53 2007
New Revision: 606928

URL: http://svn.apache.org/viewvc?rev=606928&view=rev
Log:
JCR-956: Use the existing RepositoryFactory interface instead of recreating it as an abstract
factory method of AbstractRepositoryServlet. As a bonus this automatically makes all repository
binding servlets use lazy loading for the repository.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/AbstractRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/ContextRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/JNDIRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/jackrabbit/JackrabbitRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/JNDIRemoteRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/RMIRemoteRepositoryServlet.java
    jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/URLRemoteRepositoryServlet.java

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/AbstractRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/AbstractRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/AbstractRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/AbstractRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -25,12 +25,20 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.jackrabbit.commons.repository.ProxyRepository;
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
+
 /**
  * Abstract base class for servlets that make a repository available in
  * the servlet context. This class handles the initialization and cleanup
  * tasks of setting up and clearing the configured repository attribute,
  * while a subclass only needs to implement the abstract
- * {@link #getRepository()} method to actually make the repository available.
+ * {@link #getRepositoryFactory()} method that returns a factory for
+ * retrieving the actual content repository.
+ * <p>
+ * The {@link Repository} instance bound to the servlet context is actually
+ * a {@link ProxyRepository} that uses the given {@link RepositoryFactory}
+ * for late binding of the underlying content repository.
  * <p>
  * The default name of the repository attribute is
  * "<code>javax.jcr.Repository</code>", but it can be changed by specifying
@@ -58,12 +66,16 @@
 public abstract class AbstractRepositoryServlet extends HttpServlet {
 
     /**
-     * Retrieves a repository and binds it in servlet context attribute.
+     * Binds a {@link ProxyRepository} with the factory returned by
+     * {@link #getRepositoryFactory()} in the configured servlet
+     * context attribute.
      *
-     * @throws ServletException if the repository can not be retrieved
+     * @throws ServletException if the factory could not be retrieved
      */
     public void init() throws ServletException {
-        getServletContext().setAttribute(getAttributeName(), getRepository());
+        getServletContext().setAttribute(
+                getAttributeName(),
+                new ProxyRepository(getRepositoryFactory()));
     }
 
     /**
@@ -74,19 +86,14 @@
     }
 
     /**
-     * Returns the repository instance to be bound in the servlet context.
-     * This method is invoked once during servlet initialization and is the
-     * only method that a subclass needs to implement.
-     * <p>
-     * Note that the returned repository can be (and often is) a proxy
-     * instance that accesses the actual repository only on demand. This
-     * allows late binding of the repository even though this method gets
-     * called already during servlet initialization.
+     * Returns the repository factory that will be used by the
+     * {@link ProxyRepository} bound to the servlet context.
      *
-     * @return repository instance
-     * @throws ServletException if the repository is not available
+     * @return repository factory
+     * @throws ServletException if the factory could not be created
      */
-    protected abstract Repository getRepository() throws ServletException;
+    protected abstract RepositoryFactory getRepositoryFactory()
+        throws ServletException;
 
     /**
      * Returns the name of the repository attribute. The default
@@ -150,13 +157,12 @@
      * @param request HTTP request
      * @param response HTTP response
      * @throws IOException on IO errors
+     * @throws ServletException on servlet errors
      */
     protected void doGet(
             HttpServletRequest request, HttpServletResponse response)
-            throws IOException {
-        String name = getAttributeName();
-        Repository repository = (Repository)
-            getServletContext().getAttribute(name);
+            throws IOException, ServletException {
+        Repository repository = new ServletRepository(this);
 
         String info = request.getPathInfo();
         if (info == null || info.equals("/")) {
@@ -166,8 +172,10 @@
                 descriptors.setProperty(
                         keys[i], repository.getDescriptor(keys[i]));
             }
+            // TODO: Using UTF-8 instead of ISO-8859-1 would be better, but
+            // would require re-implementing the Properties.store() method
             response.setContentType("text/plain; charset=ISO-8859-1");
-            descriptors.store(response.getOutputStream(), name);
+            descriptors.store(response.getOutputStream(), getAttributeName());
         } else {
             String key = info.substring(1); // skip the leading "/"
             String descriptor = repository.getDescriptor(key);

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/ContextRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/ContextRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/ContextRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/ContextRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -20,7 +20,6 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
-import org.apache.jackrabbit.commons.repository.ProxyRepository;
 import org.apache.jackrabbit.commons.repository.RepositoryFactory;
 
 /**
@@ -62,12 +61,13 @@
     private static final long serialVersionUID = 6222606878557491477L;
 
     /**
-     * Creates and returns a repository proxy for accessing a repository
+     * Creates and returns a repository factory for accessing a repository
      * in the configured servlet context attribute.
      *
-     * @return repository proxy
+     * @return repository factory
      */
-    protected Repository getRepository() throws ServletException {
+    protected RepositoryFactory getRepositoryFactory()
+            throws ServletException {
         String path = getInitParameter("path");
         String name = getInitParameter("name", Repository.class.getName());
 
@@ -82,13 +82,11 @@
                     + name + " of servlet " + getServletName());
         }
 
-        RepositoryFactory factory;
-        if (context != null) {
-            factory = new CrossContextRepositoryFactory(context, path, name);
+        if (path != null) {
+            return new CrossContextRepositoryFactory(context, path, name);
         } else {
-            factory = new ContextRepositoryFactory(context, name);
+            return new ContextRepositoryFactory(context, name);
         }
-        return new ProxyRepository(factory);
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/JNDIRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/JNDIRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/JNDIRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/JNDIRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -24,7 +24,8 @@
 import javax.naming.NamingException;
 import javax.servlet.ServletException;
 
-import org.apache.jackrabbit.commons.repository.JNDIRepository;
+import org.apache.jackrabbit.commons.repository.JNDIRepositoryFactory;
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
 
 /**
  * Servlet that makes a repository from JNDI available as an attribute
@@ -62,12 +63,12 @@
     private static final long serialVersionUID = 8952525573562952560L;
 
     /**
-     * Creates and returns a JNDI repository proxy based on the configured
+     * Creates and returns a JNDI repository factory based on the configured
      * init parameters.
      *
-     * @return JNDI repository proxy
+     * @return JNDI repository factory
      */
-    protected Repository getRepository() throws ServletException {
+    protected RepositoryFactory getRepositoryFactory() throws ServletException {
         try {
             String location = Repository.class.getName().replace('.', '/');
             Hashtable environment = new Hashtable();
@@ -80,7 +81,7 @@
                     environment.put(name, getInitParameter(name));
                 }
             }
-            return new JNDIRepository(
+            return new JNDIRepositoryFactory(
                     new InitialContext(environment), location);
         } catch (NamingException e) {
             throw new ServletException(

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/jackrabbit/JackrabbitRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/jackrabbit/JackrabbitRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/jackrabbit/JackrabbitRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/jackrabbit/JackrabbitRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -22,11 +22,12 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.servlet.ServletException;
 
 import org.apache.jackrabbit.api.JackrabbitRepository;
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
+import org.apache.jackrabbit.commons.repository.SingletonRepositoryFactory;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.jackrabbit.servlet.AbstractRepositoryServlet;
@@ -118,12 +119,13 @@
     }
 
     /**
-     * Returns the repository instance.
+     * Returns a repository factory that always returns the configured
+     * repository instance.
      *
-     * @return repository instance
+     * @return repository factory
      */
-    protected Repository getRepository() {
-        return repository;
+    protected RepositoryFactory getRepositoryFactory() {
+        return new SingletonRepositoryFactory(repository);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/JNDIRemoteRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/JNDIRemoteRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/JNDIRemoteRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/JNDIRemoteRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -24,10 +24,11 @@
 import javax.naming.NamingException;
 import javax.servlet.ServletException;
 
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
 import org.apache.jackrabbit.rmi.client.LocalAdapterFactory;
 import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory;
 import org.apache.jackrabbit.rmi.remote.RemoteRepository;
-import org.apache.jackrabbit.rmi.repository.JNDIRemoteRepository;
+import org.apache.jackrabbit.rmi.repository.JNDIRemoteRepositoryFactory;
 import org.apache.jackrabbit.servlet.AbstractRepositoryServlet;
 
 /**
@@ -74,12 +75,13 @@
     private static final long serialVersionUID = 9029928193416404478L;
 
     /**
-     * Creates and returns a proxy for the remote repository in the configured
-     * JNDI location.
+     * Creates and returns a factory for retrieving the remote repository
+     * in the configured JNDI location.
      *
-     * @return repository proxy
+     * @return repository factory
+     * @throws ServletException if the factory could not be created
      */
-    protected Repository getRepository() throws ServletException {
+    protected RepositoryFactory getRepositoryFactory() throws ServletException {
         String location =
             "//localhost/" + RemoteRepository.class.getName().replace('.', '/');
         try {
@@ -94,7 +96,7 @@
                     environment.put(name, getInitParameter(name));
                 }
             }
-            return new JNDIRemoteRepository(
+            return new JNDIRemoteRepositoryFactory(
                     getLocalAdapterFactory(),
                     new InitialContext(environment), location);
         } catch (NamingException e) {

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/RMIRemoteRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/RMIRemoteRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/RMIRemoteRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/RMIRemoteRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -16,11 +16,11 @@
  */
 package org.apache.jackrabbit.servlet.remote;
 
-import javax.jcr.Repository;
 import javax.servlet.ServletException;
 
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
 import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory;
-import org.apache.jackrabbit.rmi.repository.RMIRemoteRepository;
+import org.apache.jackrabbit.rmi.repository.RMIRemoteRepositoryFactory;
 import org.apache.jackrabbit.servlet.AbstractRepositoryServlet;
 
 /**
@@ -61,12 +61,13 @@
     private static final long serialVersionUID = 2410543206806054854L;
 
     /**
-     * Creates and returns an RMI repository proxy for the configured RMI URL.
+     * Creates and returns an RMI repository factory for the configured RMI URL.
      *
-     * @return RMI repository proxy
+     * @return RMI repository factory
+     * @throws ServletException if the factory could not be created
      */
-    protected Repository getRepository() throws ServletException {
-        return new RMIRemoteRepository(
+    protected RepositoryFactory getRepositoryFactory() throws ServletException {
+        return new RMIRemoteRepositoryFactory(
                 getLocalAdapterFactory(),
                 getInitParameter("url", "//localhost/javax/jcr/Repository"));
     }

Modified: jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/URLRemoteRepositoryServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/URLRemoteRepositoryServlet.java?rev=606928&r1=606927&r2=606928&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/URLRemoteRepositoryServlet.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-servlet/src/main/java/org/apache/jackrabbit/servlet/remote/URLRemoteRepositoryServlet.java
Wed Dec 26 10:29:53 2007
@@ -19,11 +19,11 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 
-import javax.jcr.Repository;
 import javax.servlet.ServletException;
 
+import org.apache.jackrabbit.commons.repository.RepositoryFactory;
 import org.apache.jackrabbit.rmi.jackrabbit.JackrabbitClientAdapterFactory;
-import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;
+import org.apache.jackrabbit.rmi.repository.URLRemoteRepositoryFactory;
 import org.apache.jackrabbit.servlet.AbstractRepositoryServlet;
 
 /**
@@ -63,18 +63,20 @@
     private static final long serialVersionUID = 6144781813459102448L;
 
     /**
-     * Creates and returns a proxy for the remote repository at the given URL.
+     * Creates and returns a factory for retrieving the remote repository
+     * at the given URL.
      *
-     * @return repository proxy
+     * @return repository factory
+     * @throws ServletException if the factory could not be created
      */
-    protected Repository getRepository() throws ServletException {
+    protected RepositoryFactory getRepositoryFactory() throws ServletException {
         String url = getInitParameter("url");
         if (url == null) {
             throw new ServletException("Missing init parameter: url");
         }
 
         try {
-            return new URLRemoteRepository(
+            return new URLRemoteRepositoryFactory(
                         getLocalAdapterFactory(), new URL(url));
         } catch (MalformedURLException e) {
             throw new ServletException("Invalid repository URL: " + url, e);



Mime
View raw message