chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r770672 - /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISServlet.java
Date Fri, 01 May 2009 13:31:24 GMT
Author: dpfister
Date: Fri May  1 13:31:23 2009
New Revision: 770672

URL: http://svn.apache.org/viewvc?rev=770672&view=rev
Log:
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=770672&r1=770671&r2=770672&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  1 13:31:23 2009
@@ -18,25 +18,74 @@
  */
 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.Repository;
+import org.apache.chemistry.repository.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();



Mime
View raw message