cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject svn commit: r540145 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main: java/org/apache/cocoon/servletservice/DispatcherServlet.java resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
Date Mon, 21 May 2007 13:53:17 GMT
Author: giacomo
Date: Mon May 21 06:53:17 2007
New Revision: 540145

URL: http://svn.apache.org/viewvc?view=rev&rev=540145
Log:
make use of collected map of block servlets

Added:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
  (with props)
Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java?view=diff&rev=540145&r1=540144&r2=540145
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/DispatcherServlet.java
Mon May 21 06:53:17 2007
@@ -19,8 +19,6 @@
 import java.io.IOException;
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
@@ -33,8 +31,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.BeanWrapperImpl;
-import org.springframework.beans.factory.BeanFactoryUtils;
 import org.springframework.context.ApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
@@ -52,37 +48,27 @@
 public class DispatcherServlet
     extends HttpServlet {
 
-    private static final String MOUNT_PATH = "mountPath";
-
-    /** All registered mountable servlets. */
-    private Map mountableServlets;
-    
-    /** The startup date of the Spring application context used to setup the  mountable servlets.
*/
-    private long applicationContextStartDate;
-    
     /** By default we use the logger for this class. */
     private Log logger = LogFactory.getLog(getClass());
+    
+    /** The servlet collector bean */
+    private Map blockServletCollector;
 
     public void init() throws ServletException {
-        createMountableServletsMap();
         this.log("Block dispatcher was initialized successfully.");        
     }
 
     protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
-        ApplicationContext appContext =
-            WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
-        if (appContext.getStartupDate() != this.applicationContextStartDate) {
-            createMountableServletsMap(); 
-        }
-        
+        final Map mountableServlets = getBlockServletMap();
         String path = req.getPathInfo();
         path = path == null ? "" : path;
+
         // find the servlet which mount path is the longest prefix of the path info
         int index = path.length();
         Servlet servlet = null;
         while (servlet == null && index != -1) {
             path = path.substring(0, index);
-            servlet = (Servlet)this.mountableServlets.get(path);
+            servlet = (Servlet)mountableServlets.get(path);
             index = path.lastIndexOf('/');
         }
         if (servlet == null) {
@@ -106,36 +92,6 @@
         servlet.service(request, res);
     }
     
-    private void createMountableServletsMap() {
-        Map mServlets = new HashMap();
-        // get the beanFactory from the web application context
-        ApplicationContext appContext =
-            WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
-
-        // the returned map contains the bean names as key and the beans as values
-        final Map servlets = 
-            BeanFactoryUtils.beansOfTypeIncludingAncestors(appContext, Servlet.class);
-        
-        // register and initialize the servlets that have a mount path property
-        final Iterator i = servlets.values().iterator();
-        while ( i.hasNext() ) {
-            final Servlet servlet = (Servlet) i.next();
-            BeanWrapperImpl wrapper = new BeanWrapperImpl(servlet);
-            if (wrapper.isReadableProperty(MOUNT_PATH)) {
-                String mountPath = (String) wrapper.getPropertyValue(MOUNT_PATH);
-                this.logger.debug("DispatcherServlet: initializing servlet " + servlet +
" at " 
-                        + mountPath);
-                mServlets.put(mountPath, servlet);
-            }
-        }
-        this.mountableServlets = mServlets;
-        
-        // set the application context start date
-        this.applicationContextStartDate =  appContext.getStartupDate();
-        
-        this.logger.info("DispatcherServlet is (re)set the table of mountable servlets based
on " + appContext);        
-    }
-    
     private void getInterfaces(Set interfaces, Class clazz) {
 		Class[] clazzInterfaces = clazz.getInterfaces();
 		for (int i = 0; i < clazzInterfaces.length; i++) {
@@ -158,4 +114,14 @@
 		getInterfaces(interfaces, clazz);
 		return (Class[]) interfaces.toArray(new Class[interfaces.size()]);
 	}
+
+    public Map getBlockServletMap()
+    {
+        if(this.blockServletCollector == null) {
+            final ApplicationContext applicationContext =
+                WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
+            this.blockServletCollector = (Map)applicationContext.getBean( "org.apache.cocoon.servletservice.spring.BlockServletMap"
);
+        }
+        return blockServletCollector;
+    }
 }

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml?view=auto&rev=540145
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
Mon May 21 06:53:17 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<!-- SVN $Id: cocoon-servlet-service-block-path-module.xml 504719 2007-02-07 22:17:36Z
danielf $ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:configurator="http://cocoon.apache.org/schema/configurator"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+                           http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.2.xsd">
+
+    <configurator:bean-map id="org.apache.cocoon.servletservice.spring.BlockServletMap"
+                           type="javax.servlet.Servlet"
+                           has-properties="mountPath"
+                           key-property="mountPath"/>
+</beans>

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-servlet-service-block-servlet-map.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message