incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r610441 - /incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Date Wed, 09 Jan 2008 16:32:56 GMT
Author: cziegeler
Date: Wed Jan  9 08:32:52 2008
New Revision: 610441

URL: http://svn.apache.org/viewvc?rev=610441&view=rev
Log:
Use simplified servlet registration taken from Felix sandbox.

Modified:
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java?rev=610441&r1=610440&r2=610441&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
(original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Wed Jan  9 08:32:52 2008
@@ -107,6 +107,9 @@
 
     // ---------- ServletResolver interface -----------------------------------
 
+    /**
+     * @see org.apache.sling.api.servlets.ServletResolver#resolveServlet(org.apache.sling.api.SlingHttpServletRequest)
+     */
     public Servlet resolveServlet(SlingHttpServletRequest request) {
 
         // resolve a servlet or script based on the request
@@ -140,6 +143,9 @@
 
     // ---------- ErrorHandler interface --------------------------------------
 
+    /**
+     * @see org.apache.sling.core.servlets.ErrorHandler#handleError(int, java.lang.String,
javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
     public void handleError(int status, String message,
             HttpServletRequest request, HttpServletResponse response)
             throws IOException {
@@ -178,6 +184,9 @@
         response.sendError(status, message);
     }
 
+    /**
+     * @see org.apache.sling.core.servlets.ErrorHandler#handleError(java.lang.Throwable,
javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
     public void handleError(Throwable throwable, HttpServletRequest request,
             HttpServletResponse response) throws ServletException, IOException {
 
@@ -343,90 +352,50 @@
                 }
             }
         }
-        List<ServiceReference> refs = null;
-        synchronized (this) {
-            if ( this.servletContext != null ) {
-                refs = this.pendingServlets;
-                this.pendingServlets = new ArrayList<ServiceReference>();
-            }
-        }
-        if ( refs != null ) {
-            this.createAllServlets(this.servletContext, refs);
-        }
-    }
 
-    protected synchronized void bindServlet(ServiceReference reference) {
-        if (context == null || servletContext == null) {
-            pendingServlets.add(reference);
-        } else {
-            createServlet(servletContext, reference);
-        }
-    }
-
-    protected synchronized void unbindServlet(ServiceReference reference) {
-        if (context == null || servletContext == null) {
-            pendingServlets.remove(reference);
-        } else {
-            destroyServlet(reference);
-        }
-    }
-
-    protected void bindServletContext(ServletContext newServletContext) {
-
-        boolean destroy;
         Collection<ServiceReference> refs;
-
         synchronized (this) {
 
-            if (this.servletContext == null) {
+            refs = pendingServlets;
+            pendingServlets = new ArrayList<ServiceReference>();
 
-                if ( this.context != null ) {
-                    refs = pendingServlets;
-                    pendingServlets = new ArrayList<ServiceReference>();
-                } else {
-                    refs = null;
-                }
-                destroy = false;
+            // register servlets immediately from now on
+            this.context = context;
 
-            } else {
+        }
 
-                refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
-                destroy = true;
+        createAllServlets(refs);
+    }
 
-            }
+    protected void deactivate(ComponentContext context) {
 
-            this.servletContext = newServletContext;
+        // destroy all active servlets
+        Collection<ServiceReference> refs;
+        synchronized (this) {
+            refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
+            this.context = null;
         }
 
-        if (destroy) {
-            destroyAllServlets(refs);
-        }
+        // destroy all servlets
+        destroyAllServlets(refs);
+    }
 
-        if ( refs != null ) {
-            createAllServlets(this.servletContext, refs);
+    protected synchronized void bindServlet(ServiceReference reference) {
+        if (context == null) {
+            pendingServlets.add(reference);
+        } else {
+            createServlet(servletContext, reference);
         }
     }
 
-    protected void unbindServletContext(ServletContext oldServletContext) {
-
-        if (this.servletContext == oldServletContext) {
-
-            Collection<ServiceReference> refs;
-            synchronized (this) {
-                refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
-                pendingServlets.addAll(refs);
-                this.servletContext = null;
-            }
-
-            // destroy all servlets
-            destroyAllServlets(refs);
-        }
+    protected synchronized void unbindServlet(ServiceReference reference) {
+        pendingServlets.remove(reference);
+        destroyServlet(reference);
     }
 
     // ---------- Servlet Management -------------------------------------------
 
-    private void createAllServlets(ServletContext servletContext,
-            Collection<ServiceReference> pendingServlets) {
+    private void createAllServlets(Collection<ServiceReference> pendingServlets) {
         for (ServiceReference serviceReference : pendingServlets) {
             createServlet(servletContext, serviceReference);
         }



Mime
View raw message