You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2009/05/08 22:42:28 UTC

svn commit: r773092 - /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java

Author: fguillaume
Date: Fri May  8 20:42:27 2009
New Revision: 773092

URL: http://svn.apache.org/viewvc?rev=773092&view=rev
Log:
reapply r770672: CMIS-13 Add empty constructor to CMISServlet

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java?rev=773092&r1=773091&r2=773092&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java Fri May  8 20:42:27 2009
@@ -18,25 +18,75 @@
  */
 package org.apache.chemistry.atompub.server;
 
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.server.Provider;
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.apache.chemistry.Repository;
+import org.apache.chemistry.RepositoryFactory;
 
 public class CMISServlet extends AbderaServlet {
 
     private static final long serialVersionUID = 1L;
 
-    private final Repository repository;
+    private Repository repository;
+
+    public CMISServlet() {
+    }
 
     public CMISServlet(Repository repository) {
         this.repository = repository;
     }
 
     @Override
+    public void init() throws ServletException {
+        if (repository == null) {
+            Map<String, String> params = new HashMap<String, String>();
+            @SuppressWarnings("unchecked")
+            Enumeration<String> names = getInitParameterNames();
+            while (names.hasMoreElements()) {
+                String name = names.nextElement();
+                params.put(name, getInitParameter(name));
+            }
+            repository = createRepository(getServletContext(), params);
+        }
+        super.init();
+    }
+
+    private Repository createRepository(ServletContext context,
+            Map<String, String> params) throws ServletException {
+
+        String className = params.get("class");
+        if (className == null) {
+            String msg = "Repository factory expected in 'class' parameter.";
+            throw new ServletException(msg);
+        }
+        RepositoryFactory factory = null;
+
+        try {
+            Class<?> c = Class.forName(className);
+            factory = (RepositoryFactory) c.newInstance();
+        } catch (Exception e) {
+            String msg = "Unable to create repository factory class: "
+                    + className;
+            throw new ServletException(msg, e);
+        }
+
+        try {
+            return factory.create(context, params);
+        } catch (Exception e) {
+            String msg = "Unable to create repository.";
+            throw new ServletException(msg, e);
+        }
+    }
+
+    @Override
     protected Provider createProvider() {
         Provider provider = new CMISProvider(repository);
         Abdera abdera = new Abdera();