cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r497249 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main: java/org/apache/cocoon/servletservice/ java/org/apache/cocoon/servletservice/spring/ resources/META-INF/ resources/org/apache/cocoon/servletservice...
Date Wed, 17 Jan 2007 23:46:05 GMT
Author: danielf
Date: Wed Jan 17 15:46:04 2007
New Revision: 497249

URL: http://svn.apache.org/viewvc?view=rev&rev=497249
Log:
More work on creating servlet services from a custom scheme. Still work left the code doesn't
work yet.

Added:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
  (with props)
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
  (with props)
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
  (with props)
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.handlers
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.schemas
Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd
  (contents, props changed)

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java?view=diff&rev=497249&r1=497248&r2=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletService.java
Wed Jan 17 15:46:04 2007
@@ -162,7 +162,7 @@
     // FIXME: would like to throw an exeption if the form of the url is faulty,
     // what is the prefered way of handling faulty properties in Spring?
     public void setBlockContextURL(String blockContextURL) {
-        this.blockContext.setBlockContextURL(blockContextURL);
+        this.blockContext.setContextPath(blockContextURL);
     }
 
     public void setServletClass(String servletClass) {
@@ -170,7 +170,7 @@
     }
 
     public void setProperties(Map properties) {
-        this.blockContext.setProperties(properties);
+        this.blockContext.setInitParams(properties);
     }
     
     public void setConnections(Map connections) {

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java?view=diff&rev=497249&r1=497248&r2=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java
Wed Jan 17 15:46:04 2007
@@ -54,10 +54,10 @@
     
     public static final String SUPER = "super";
 
-    private Hashtable attributes = new Hashtable();
+    private Map attributes = new Hashtable();
     private Servlet servlet;
     private String mountPath;
-    private String blockContextURL;
+    private String contextPath;
     private Map properties;
     private Map connections;
 
@@ -102,7 +102,14 @@
      * @see javax.servlet.ServletContext#getAttributeNames()
      */
     public Enumeration getAttributeNames() {
-        return this.attributes.keys();
+        return Collections.enumeration(this.attributes.keySet());
+    }
+
+    /**
+     * @param map the attributes to set
+     */
+    public void setAttributes(Map map) {
+        this.attributes = map;
     }
 
     /*
@@ -113,17 +120,17 @@
     public URL getResource(String path) throws MalformedURLException {
         // hack for getting a file protocol or other protocols that can be used as context
         // path in the getResource method in the servlet context
-        if (!(blockContextURL.startsWith("file:") || blockContextURL.startsWith("/")
-                || blockContextURL.indexOf(':') == -1)) {
+        if (!(contextPath.startsWith("file:") || contextPath.startsWith("/")
+                || contextPath.indexOf(':') == -1)) {
             SourceResolver resolver = null;
             Source source = null;
             try {
                 BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(this);
                 resolver = (SourceResolver) factory.getBean(SourceResolver.ROLE);
-                source = resolver.resolveURI(blockContextURL);
-                blockContextURL = source.getURI();
+                source = resolver.resolveURI(contextPath);
+                contextPath = source.getURI();
             } catch (IOException e) {
-                throw new MalformedURLException("Could not resolve " + blockContextURL);
+                throw new MalformedURLException("Could not resolve " + contextPath);
             } finally {
                 if (resolver != null)
                     resolver.release(source);
@@ -131,16 +138,16 @@
         }
 
         // HACK: allow file:/ URLs for reloading of sitemaps during development
-        if (this.blockContextURL.startsWith("file:")) {
-            return new URL("file", null, this.blockContextURL.substring("file:".length())
+ path);
+        if (this.contextPath.startsWith("file:")) {
+            return new URL("file", null, this.contextPath.substring("file:".length()) + path);
         } else {
-            if (this.blockContextURL.length() != 0 && this.blockContextURL.charAt(0)
!= '/')
-                throw new MalformedURLException("The blockContextURL must be empty or start
with '/' "
-                        + this.blockContextURL);
+            if (this.contextPath.length() != 0 && this.contextPath.charAt(0) != '/')
+                throw new MalformedURLException("The contextPath must be empty or start with
'/' "
+                        + this.contextPath);
             
-            // prefix the path with the block context resolve and resolve in the embeding
+            // prefix the path with the servlet context resolve and resolve in the embeding
             // servlet context
-            return super.getResource(this.blockContextURL + path);
+            return super.getResource(this.contextPath + path);
         }
     }
 
@@ -164,7 +171,7 @@
         if (this.properties == null)
             return null;
         String value = (String) this.properties.get(name);
-        // Ask the super block for the property
+        // Ask the super servlet for the property
         if (value == null) {
             ServletContext superContext = this.getNamedContext(SUPER);
             if (superContext != null)
@@ -191,7 +198,7 @@
             names.add(enumeration.nextElement());
         }
         
-        // add names of the super block
+        // add names of the super servlet
         ServletContext superContext = this.getNamedContext(SUPER);
         if (superContext != null) {
             enumeration = superContext.getInitParameterNames();
@@ -200,7 +207,7 @@
             }
         }
 
-        // add property names of this block
+        // add property names of this servlet
         if (this.properties != null) {
             names.addAll(this.properties.keySet());
         }
@@ -275,10 +282,10 @@
      */
     public Set getResourcePaths(String path) {
         String pathPrefix;
-        if (this.blockContextURL.startsWith("file:")) {
-            pathPrefix = this.blockContextURL.substring("file:".length());
+        if (this.contextPath.startsWith("file:")) {
+            pathPrefix = this.contextPath.substring("file:".length());
         } else {
-            pathPrefix = this.blockContextURL;
+            pathPrefix = this.contextPath;
         }
         
         path = pathPrefix + path;
@@ -339,10 +346,10 @@
         return null;
     }
 
-    // Block specific methods
+    // Servlet service specific methods
     
     /**
-     * Set the servlet of the block
+     * Set the servlet of the context
      * @param servlet
      */
     public void setServlet(Servlet servlet) {
@@ -350,24 +357,24 @@
     }
 
     /**
-     * Takes the scheme specific part of a block URI (the scheme is the
+     * Takes the scheme specific part of a servlet service URI (the scheme is the
      * responsibilty of the ServletSource) and resolve it with respect to the
-     * blocks mount point.
+     * servlets mount point.
      */
     public URI absolutizeURI(URI uri) throws URISyntaxException {
-        String blockName = uri.getScheme();
-        ServletServiceContext blockContext;
-        if (blockName == null) {
-            // this block
-            blockContext = this;
+        String servletServiceName = uri.getScheme();
+        ServletServiceContext servletServiceContext;
+        if (servletServiceName == null) {
+            // this servlet service
+            servletServiceContext = this;
         } else {
-            // another block
-            blockContext = (ServletServiceContext) this.getNamedContext(blockName);
-            if (blockContext == null)
-                throw new URISyntaxException(uri.toString(), "Unknown block name");
+            // another servlet service
+            servletServiceContext = (ServletServiceContext) this.getNamedContext(servletServiceName);
+            if (servletServiceContext == null)
+                throw new URISyntaxException(uri.toString(), "Unknown servlet service name");
         }
 
-        String mountPath = blockContext.getMountPath();
+        String mountPath = servletServiceContext.getMountPath();
         if (mountPath == null)
             throw new URISyntaxException(uri.toString(),
                     "No mount point for this URI");
@@ -379,7 +386,7 @@
     }
     
     /**
-     * Get the context of a block with a given name.
+     * Get the context of a servlet service with a given name.
      */
     // FIXME implement NPE handling
     public ServletContext getNamedContext(String name) {
@@ -387,9 +394,9 @@
             return null;
         }
         
-        ServletService blockServlet =
+        ServletService servletService =
             (ServletService) this.connections.get(name);
-        return blockServlet != null ? blockServlet.getBlockContext() : null;
+        return servletService != null ? servletService.getBlockContext() : null;
     }
         
     /**
@@ -400,23 +407,23 @@
     }
 
     /**
-     * Get the mount path of the block context
+     * Get the mount path of the servlet service context
      */
     public String getMountPath() {
         return this.mountPath;
     }
     
     /**
-     * @param blockContextURL the blockContextURL to set
+     * @param contextPath
      */
-    public void setBlockContextURL(String blockContextURL) {
-        this.blockContextURL = blockContextURL;
+    public void setContextPath(String contextPath) {
+        this.contextPath = contextPath;
     }
 
     /**
      * @param properties The properties to set.
      */
-    public void setProperties(Map properties) {
+    public void setInitParams(Map properties) {
         this.properties = properties;
     }
 
@@ -429,23 +436,23 @@
 
     protected class NamedDispatcher implements RequestDispatcher {
 
-        private String blockName;
+        private String servletServiceName;
         private boolean superCall = false;
         private ServletContext context;
 
-        public NamedDispatcher(String blockName) {
-            this.blockName = blockName;
-            this.superCall = SUPER.equals(this.blockName);
+        public NamedDispatcher(String servletServiceName) {
+            this.servletServiceName = servletServiceName;
+            this.superCall = SUPER.equals(this.servletServiceName);
 
-            // Call to a named block that exists in the current context
-            this.context = ServletServiceContext.this.getNamedContext(this.blockName);
+            // Call to a named servlet service that exists in the current context
+            this.context = ServletServiceContext.this.getNamedContext(this.servletServiceName);
             if (this.context == null) {
-                // If there is a super block, the connection might
+                // If there is a super servlet service, the connection might
                 // be defined there instead.
                 ServletServiceContext superContext =
                     (ServletServiceContext) ServletServiceContext.this.getNamedContext(SUPER);
                 if (superContext != null) {
-                    this.context = superContext.getNamedContext(this.blockName);
+                    this.context = superContext.getNamedContext(this.servletServiceName);
                     this.superCall = true;
                 }
             }
@@ -463,9 +470,9 @@
          */
         public void forward(ServletRequest request, ServletResponse response)
                 throws ServletException, IOException {
-            // Call to named block
+            // Call to named servlet service
 
-            ServletServiceContext.this.log("Enter processing in block " + this.blockName);
+            ServletServiceContext.this.log("Enter processing in servlet service " + this.servletServiceName);
             RequestDispatcher dispatcher =
                 this.context.getRequestDispatcher(((HttpServletRequest)request).getPathInfo());
             if (dispatcher != null && dispatcher instanceof PathDispatcher) {
@@ -474,7 +481,7 @@
                 // Cannot happen
                 throw new IllegalStateException();
             }
-            ServletServiceContext.this.log("Leaving processing in block " + this.blockName);
+            ServletServiceContext.this.log("Leaving processing in servlet service " + this.servletServiceName);
         }
 
         /*
@@ -490,11 +497,11 @@
     }
     
     /**
-     *  Limited functionality, assumes that there is at most one servlet in the block
+     *  Limited functionality, assumes that there is at most one servlet in the context
      */
     private class PathDispatcher implements RequestDispatcher {
         
-        // Ignores path, as the assumed only servlet within the block is
+        // Ignores path, as the assumed only servlet within the context is
         // implicitly mounted on '/*'
         private PathDispatcher(String path) {
         }
@@ -515,13 +522,13 @@
         throws ServletException, IOException {
             try {
                 if (!superCall) {
-                    // It is important to set the current block each time
-                    // a new block is entered, this is used for the block
+                    // It is important to set the current context each time
+                    // a new context is entered, this is used for the servlet
                     // protocol
                     CallStack.enterBlock(ServletServiceContext.this);
                 } else {
-                    // A super block should be called in the context of
-                    // the called block to get polymorphic calls resolved
+                    // A super servlet service should be called in the context of
+                    // the called servlet service to get polymorphic calls resolved
                     // in the right way. We still need to register the
                     // current context for resolving super calls relative it.
                     CallStack.enterSuperBlock(ServletServiceContext.this);

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java?view=auto&rev=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
Wed Jan 17 15:46:04 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.servletservice.spring;
+
+import java.util.Map;
+
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Id$
+ * @since 2.2
+ */
+public class ServletDecorator implements
+        BeanDefinitionDecorator {
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.xml.BeanDefinitionDecorator#decorate(org.w3c.dom.Node,
org.springframework.beans.factory.config.BeanDefinitionHolder, org.springframework.beans.factory.xml.ParserContext)
+     */
+    public BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder holder, ParserContext
ctx) {
+        String embeddedServletBeanName = registerEmbeddedServletBean(holder, ctx);
+        registerServletFactoryBean((Element) source, holder, ctx, embeddedServletBeanName);
+        return holder;
+    }
+
+    private String registerEmbeddedServletBean(BeanDefinitionHolder holder, ParserContext
ctx) {
+        String beanName = holder.getBeanName() + "/embedded";
+
+        AbstractBeanDefinition definition = ((AbstractBeanDefinition) holder.getBeanDefinition());
+        ctx.getRegistry().registerBeanDefinition(beanName, definition);
+        
+        return beanName;
+    }
+
+    private void registerServletFactoryBean(Element source, BeanDefinitionHolder holder,
ParserContext ctx, String embeddedServletBeanName) {
+        String mountPath = source.hasAttribute("mount-path") ? source.getAttribute("mount-path")
: null;
+        String contextPath = source.hasAttribute("context-path") ? source.getAttribute("context-path")
: null;
+        
+        Element initParamsElem = (Element) source.getElementsByTagName("init-params").item(0);
+        Element contextParamsElem = (Element) source.getElementsByTagName("context-params").item(0);
+        Element connectionsElem = (Element) source.getElementsByTagName("connections").item(0);
+        
+        BeanDefinitionBuilder servletFactoryDefBuilder = BeanDefinitionBuilder.rootBeanDefinition(ServletFactoryBean.class);
+        servletFactoryDefBuilder.setSource(ctx.extractSource(source));
+        servletFactoryDefBuilder.addPropertyReference("embeddedServlet", embeddedServletBeanName);
+        servletFactoryDefBuilder.setInitMethodName("init");
+        servletFactoryDefBuilder.setDestroyMethodName("destroy");
+        if (mountPath != null)
+            servletFactoryDefBuilder.addPropertyValue("mountPath", mountPath);
+        if (contextPath != null)
+            servletFactoryDefBuilder.addPropertyValue("contextPath", contextPath);
+        if (initParamsElem != null) {
+            Map initParams = ctx.getDelegate().parseMapElement(initParamsElem, null);
+            servletFactoryDefBuilder.addPropertyValue("initParams", initParams);
+        }
+        if (contextParamsElem != null) {
+            Map contextParams = ctx.getDelegate().parseMapElement(contextParamsElem, null);
+            servletFactoryDefBuilder.addPropertyValue("contextParams", contextParams);
+        }
+        if (connectionsElem != null) {
+            Map connections = ctx.getDelegate().parseMapElement(connectionsElem, null);
+            servletFactoryDefBuilder.addPropertyValue("connections", connections);
+        }
+
+        ctx.getRegistry().registerBeanDefinition(holder.getBeanName(), servletFactoryDefBuilder.getBeanDefinition());
+    }
+}

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletDecorator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java?view=auto&rev=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
Wed Jan 17 15:46:04 2007
@@ -0,0 +1,249 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.servletservice.spring;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.cocoon.servletservice.ServletServiceContext;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.aop.support.DelegatingIntroductionInterceptor;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanNameAware;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.web.context.ServletContextAware;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.GenericWebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+/**
+ * @version $Id$
+ */
+public class ServletFactoryBean
+    implements FactoryBean, ApplicationContextAware, ServletContextAware, BeanNameAware {
+    
+    private ApplicationContext parentContainer;
+    private ServletContext servletContext;
+    private String beanName;
+
+    private Servlet embeddedServlet;
+    
+    private String mountPath;
+    private String contextPath;
+
+    private Map initParams;
+    private Map contextParams;
+    private Map connections;
+    
+    private ServletServiceContext servletServiceContext;
+
+    public ServletFactoryBean() {
+    }
+    
+    public void init() throws Exception {
+    
+        this.servletServiceContext = new ServletServiceContext();
+        this.servletServiceContext.setServletContext(this.servletContext);
+    
+        this.servletServiceContext.setMountPath(this.mountPath);        
+        this.servletServiceContext.setContextPath(this.contextPath);
+
+        this.servletServiceContext.setInitParams(this.initParams);
+        this.servletServiceContext.setAttributes(this.contextParams);
+        this.servletServiceContext.setConnections(connections);
+
+        // create a sub container that resolves paths relative to the block
+        // context rather than the parent context and make it available in
+        // a context attribute
+        if (this.parentContainer == null)
+            this.parentContainer =
+                WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext);
+        GenericWebApplicationContext container = new GenericWebApplicationContext();
+        container.setParent(this.parentContainer);
+        container.setServletContext(this.servletServiceContext);
+        container.refresh();
+        this.servletServiceContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
container);
+
+        // create a servlet config based on the block servlet context
+        ServletConfig blockServletConfig =
+            new ServletConfig() {
+    
+                public String getInitParameter(String name) {
+                    return ServletFactoryBean.this.servletServiceContext.getInitParameter(name);
+                }
+    
+                public Enumeration getInitParameterNames() {
+                    return ServletFactoryBean.this.servletServiceContext.getInitParameterNames();
+                }
+
+                public ServletContext getServletContext() {
+                    return ServletFactoryBean.this.servletServiceContext;
+                }
+        
+                public String getServletName() {
+                    return ServletFactoryBean.this.beanName;
+                }
+        };
+    
+        // create and initialize the embeded servlet
+        this.embeddedServlet.init(blockServletConfig);
+        this.servletServiceContext.setServlet(this.embeddedServlet);
+    }
+
+    public void destroy() {
+        this.embeddedServlet.destroy();        
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+     */
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
+        this.parentContainer = applicationContext;
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
+     */
+    public void setServletContext(ServletContext servletContext) {
+        this.servletContext = servletContext;
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
+     */
+    public void setBeanName(String beanName) {
+        this.beanName = beanName;
+    }
+
+    /**
+     * @param embeddedServlet the embeddedServlet to set
+     */
+    public void setEmbeddedServlet(Servlet embeddedServlet) {
+        this.embeddedServlet = embeddedServlet;
+    }
+
+    /**
+     * @param mountPath
+     */
+    public void setMountPath(String mountPath) {
+        this.mountPath = mountPath;
+    }
+    
+    /**
+     * The path to the blocks resources relative to the servlet context URL,
+     * must start with an '/'.
+     * @param contextPath
+     */
+    public void setContextPath(String contextPath) {
+        this.contextPath = contextPath;
+    }
+
+    /**
+     * @param initParams
+     */
+    public void setInitParams(Map initParams) {
+        this.initParams = initParams;
+    }
+
+    /**
+     * @param contextParams the contextParams to set
+     */
+    public void setContextParams(Map contextParams) {
+        this.contextParams = contextParams;
+    }
+
+    /**
+     * @param connections
+     */
+    public void setConnections(Map connections) {
+        this.connections = connections;
+    }
+
+    /**
+     * @return the blockContext
+     */
+    public ServletServiceContext getServletServiceContext() {
+        return this.servletServiceContext;
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.FactoryBean#getObject()
+     */
+    public Object getObject() throws Exception {
+        ProxyFactory proxyFactory = new ProxyFactory(this.embeddedServlet);
+        proxyFactory.addAdvice(new ServiceInterceptor());
+        if (this.mountPath != null)
+            proxyFactory.addAdvice(new MountableIntroducer());
+        return proxyFactory.getProxy();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+     */
+    public Class getObjectType() {
+        return this.embeddedServlet.getClass();
+    }
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+     */
+    public boolean isSingleton() {
+        return true;
+    }
+    
+    private class ServiceInterceptor implements MethodInterceptor {
+
+        /* (non-Javadoc)
+         * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
+         */
+        public Object invoke(MethodInvocation invocation) throws Throwable {
+            if ("service".equals(invocation.getMethod().getName())) {
+                Object[] arguments = invocation.getArguments();
+                HttpServletRequest request = (HttpServletRequest) arguments[0];
+                HttpServletResponse response = (HttpServletResponse) arguments[1];
+                RequestDispatcher dispatcher =
+                    ServletFactoryBean.this.servletServiceContext.getRequestDispatcher(request.getPathInfo());
+                dispatcher.forward(request, response);
+                return null;
+            } else
+                return invocation.proceed();
+        }
+        
+    }
+    
+    public interface Mountable {
+        public String getMountPath();
+    }
+    
+    private class MountableIntroducer extends DelegatingIntroductionInterceptor implements
Mountable {
+
+        public String getMountPath() {
+            return ServletFactoryBean.this.mountPath;
+        }
+    }
+}

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java?view=auto&rev=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
Wed Jan 17 15:46:04 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.servletservice.spring;
+
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ * Spring namespace handler for the cocoon servlet namespace.
+ * Currently this namespace defines the following elements
+ * (in the namespace "http://cocoon.apache.org/schema/servlet"):
+ * "context" : with optional attributes "mountPath" and "contextPath".
+ * With optional sub elements "init-params", "context-params" and
+ * "connections".  
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class ServletNamespaceHandler extends NamespaceHandlerSupport {
+
+    /* (non-Javadoc)
+     * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
+     */
+    public void init() {
+        this.registerBeanDefinitionDecorator("servlet", new ServletDecorator());
+    }
+
+}

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/spring/ServletNamespaceHandler.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.handlers
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.handlers?view=auto&rev=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.handlers
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.handlers
Wed Jan 17 15:46:04 2007
@@ -0,0 +1,16 @@
+#  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.
+#
+http\://cocoon.apache.org/schema/servlet=org.apache.cocoon.servletservice.spring.ServletNamespaceHandler

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.schemas
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.schemas?view=auto&rev=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.schemas
(added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/spring.schemas
Wed Jan 17 15:46:04 2007
@@ -0,0 +1,16 @@
+#  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.
+#
+http\://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd=org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd?view=diff&rev=497249&r1=497248&r2=497249
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd
Wed Jan 17 15:46:04 2007
@@ -15,143 +15,102 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<!-- @version $Id: cocoon-configurator-1.0.xsd 492166 2007-01-03 14:48:23Z cziegeler $
-->
+<!-- @version $Id$ -->
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-            targetNamespace="http://cocoon.apache.org/schema/servlet"
-            xmlns:tns="http://cocoon.apache.org/schema/servlet"
-            xmlns="http://cocoon.apache.org/schema/servlet">
-
-    <xsd:annotation>
-      <xsd:documentation>
-        Schema for decorating servlet beans so that they are managed by Spring and
-        used in the servlet context configured by the elements in this scheme.
-      </xsd:documentation>
-    </xsd:annotation>
-
-    <xsd:element name="context">
-      <xsd:annotation>
-        <xsd:documentation>
-          The top level element. 
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-    	<xsd:sequence>
-    	    <xsd:element ref="init-params" minOccurs="0" maxOccurs="1"/>
-    	    <xsd:element ref="context-params" minOccurs="0" maxOccurs="1"/>
-    	    <xsd:element ref="connections" minOccurs="0" maxOccurs="1"/>
-    	</xsd:sequence>
-    	<xsd:attribute name="mountPath" type="xsd:string" use="optional">
-    	  <xsd:annotation>
-    	    <xsd:documentation>
-    	      Where the servlet should be mounted relative to the context
-    	      path of the embeding servlet container. Use an empty string
-    	      for mounting directly at the context path. Non empty mount paths
-    	      must start with '/'.
-    	      If the mountPath attribute not is used, the servlet will not be
-    	      available though an URI, it will only be avaliable through its
-    	      bean name for servlet beans connected to this servlet.
-    	    </xsd:documentation>
-    	  </xsd:annotation>
-    	</xsd:attribute>
-    	<xsd:attribute name="contextPath" type="xsd:string" use="optional">
-    	  <xsd:annotation>
-    	    <xsd:documentation>
-    	      The root path for the servlet context.
-    	    </xsd:documentation>
-    	  </xsd:annotation>
-    	</xsd:attribute>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="init-params">
-      <xsd:annotation>
-        <xsd:documentation>
-          The init params for the servlet configuration used for the servlet.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:sequence>
-      	  <xsd:element ref="init-param" maxOccurs="unbounded" minOccurs="0"/>
-      	</xsd:sequence>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="init-param">
-      <xsd:annotation>
-        <xsd:documentation>
-          An init param for the servlet configuration.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:attribute name="name" type="xsd:string" use="required"/>
-      	<xsd:attribute name="value" type="xsd:string" use="required"/>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="context-params">
-      <xsd:annotation>
-        <xsd:documentation>
-          Context parameters for the servlet context.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:sequence>
-      	  <xsd:element ref="context-param" maxOccurs="unbounded" minOccurs="0"/>
-      	</xsd:sequence>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="context-param">
-      <xsd:annotation>
-        <xsd:documentation>
-          A context parameter for the servlet context. Either a string value
-          or a reference to another bean can be used as argument.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:attribute name="name" type="xsd:string" use="required"/>
-        <xsd:attribute name="value" type="xsd:string" use="optional"/>
-        <xsd:attribute name="ref" type="xsd:string" use="optional"/>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="connections">
-      <xsd:annotation>
-        <xsd:documentation>
-          Connections to other servlet services that are made available
-          through the named dispatcher of the servlet context.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:sequence>
-      	  <xsd:element ref="connection" maxOccurs="unbounded" minOccurs="0"/>
-      	</xsd:sequence>
-      </xsd:complexType>
-    </xsd:element>
-
-    <xsd:element name="connection">
-      <xsd:annotation>
-        <xsd:documentation>
-          A named connection to another servlet.
-        </xsd:documentation>
-      </xsd:annotation>
-      <xsd:complexType>
-      	<xsd:attribute name="name" type="xsd:string" use="required">
-      	  <xsd:annotation>
-      	    <xsd:documentation>
-      	      The local name of the servlet. Can be used through the named
-      	      dispatcher of the servlet context.
-      	    </xsd:documentation>
-      	  </xsd:annotation>
-      	</xsd:attribute>
-        <xsd:attribute name="ref" type="xsd:string" use="required">
-      	  <xsd:annotation>
-      	    <xsd:documentation>
-      	      A reference to another servlet service.
-      	    </xsd:documentation>
-      	  </xsd:annotation>
-        </xsd:attribute>
-      </xsd:complexType>
-    </xsd:element>
-    
+	xmlns:beans="http://www.springframework.org/schema/beans"
+	targetNamespace="http://cocoon.apache.org/schema/servlet"
+	xmlns:tns="http://cocoon.apache.org/schema/servlet"
+	xmlns="http://cocoon.apache.org/schema/servlet">
+
+	<xsd:import namespace="http://www.springframework.org/schema/beans"
+	            schemaLocation="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"/>
+
+	<xsd:annotation>
+		<xsd:documentation>
+			Schema for decorating servlet beans so that they are managed
+			by Spring and used in the servlet context configured by the
+			elements in this scheme.
+		</xsd:documentation>
+	</xsd:annotation>
+
+	<xsd:element name="context">
+		<xsd:annotation>
+			<xsd:documentation>
+				The top level element.
+			</xsd:documentation>
+		</xsd:annotation>
+		<xsd:complexType>
+			<xsd:sequence>
+				<xsd:element ref="init-params" minOccurs="0" maxOccurs="1" />
+				<xsd:element ref="context-params" minOccurs="0" maxOccurs="1" />
+				<xsd:element ref="connections" minOccurs="0" maxOccurs="1" />
+			</xsd:sequence>
+			<xsd:attribute name="mount-path" type="xsd:string" use="optional">
+				<xsd:annotation>
+					<xsd:documentation>
+						Where the servlet should be mounted relative to
+						the context path of the embeding servlet
+						container. Use an empty string for mounting
+						directly at the context path. Non empty mount
+						paths must start with '/'. If the mountPath
+						attribute not is used, the servlet will not be
+						available though an URI, it will only be
+						avaliable through its bean name for servlet
+						beans connected to this servlet.
+					</xsd:documentation>
+				</xsd:annotation>
+			</xsd:attribute>
+			<xsd:attribute name="context-path" type="xsd:string" use="optional">
+				<xsd:annotation>
+					<xsd:documentation>
+						The root path for the servlet context.
+					</xsd:documentation>
+				</xsd:annotation>
+			</xsd:attribute>
+		</xsd:complexType>
+	</xsd:element>
+
+	<xsd:element name="init-params">
+		<xsd:annotation>
+			<xsd:documentation>
+				The init params for the servlet configuration used for
+				the servlet.
+			</xsd:documentation>
+		</xsd:annotation>
+		<xsd:complexType>
+			<xsd:complexContent>
+				<xsd:extension base="beans:mapType" />
+			</xsd:complexContent>
+		</xsd:complexType>
+	</xsd:element>
+
+	<xsd:element name="context-params">
+		<xsd:annotation>
+			<xsd:documentation>
+				Context parameters for the servlet context.
+			</xsd:documentation>
+		</xsd:annotation>
+		<xsd:complexType>
+			<xsd:complexContent>
+				<xsd:extension base="beans:mapType" />
+			</xsd:complexContent>
+		</xsd:complexType>
+	</xsd:element>
+
+	<xsd:element name="connections">
+		<xsd:annotation>
+			<xsd:documentation>
+				Connections to other servlet services that are made
+				available through the named dispatcher of the servlet
+				context. Consist of mappings between a named connection
+				to another servlet and a reference to it.
+			</xsd:documentation>
+		</xsd:annotation>
+		<xsd:complexType>
+			<xsd:complexContent>
+				<xsd:extension base="beans:mapType" />
+			</xsd:complexContent>
+		</xsd:complexType>
+	</xsd:element>
+
 </xsd:schema>

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/org/apache/cocoon/servletservice/schema/cocoon-servlet-1.0.xsd
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message