You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2007/02/06 00:36:35 UTC
svn commit: r503923 - in
/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl: ./
src/main/java/org/apache/cocoon/callstack/
src/main/java/org/apache/cocoon/callstack/environment/
src/main/resources/META-INF/cocoon/ src/main/resources/...
Author: danielf
Date: Mon Feb 5 15:36:34 2007
New Revision: 503923
URL: http://svn.apache.org/viewvc?view=rev&rev=503923
Log:
Refactored the scope and stack implementation and added handling of destruction callbacks. Added a utility class for putting servlet request, response and context objects into the current frame. And added bean factories for accessing the current servlet objects as beans. There is also a configuration file that make the servlet objects available as call scoped beans. Nothing is tested yet.
Added:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java (with props)
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.xml (with props)
Modified:
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/pom.xml
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java
cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/pom.xml?view=diff&rev=503923&r1=503922&r2=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/pom.xml (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/pom.xml Mon Feb 5 15:36:34 2007
@@ -87,6 +87,11 @@
<artifactId>spring-web</artifactId>
<version>2.0.2</version>
</dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.1_3</version>
+ </dependency>
<dependency>
<groupId>javax.servlet</groupId>
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java Mon Feb 5 15:36:34 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.callstack;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Attributes in the call frame and destruction callbacks that should be
+ * executed when the call frame is left.
+ *
+ * @version $Id$
+ * @since 2.2
+ */
+public class CallFrame {
+ private Map attributes;
+ private Map destructionCallbacks;
+
+ public Object getAttribute(String name) {
+ return this.attributes != null ? this.attributes.get(name) : null;
+ }
+
+ public void setAttribute(String name, Object value) {
+ if (this.attributes == null)
+ this.attributes = new HashMap();
+ this.attributes.put(name, value);
+ }
+
+ public Object removeAttribute(String name) {
+ return this.attributes != null ? this.attributes.remove(name) : null;
+ }
+
+ public void registerDestructionCallback(String name, Runnable callback) {
+ if (this.destructionCallbacks == null)
+ this.destructionCallbacks = new HashMap();
+ this.destructionCallbacks.put(name, callback);
+ }
+
+ void executeDestructionCallbacks() {
+ if (this.destructionCallbacks == null)
+ return;
+ Iterator it = this.destructionCallbacks.values().iterator();
+ while (it.hasNext())
+ ((Runnable)it.next()).run();
+ }
+}
\ No newline at end of file
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java?view=diff&rev=503923&r1=503922&r2=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallScope.java Mon Feb 5 15:36:34 2007
@@ -16,8 +16,6 @@
*/
package org.apache.cocoon.callstack;
-import java.util.Map;
-
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
@@ -35,11 +33,11 @@
* @see org.springframework.beans.factory.config.Scope#get(java.lang.String, org.springframework.beans.factory.ObjectFactory)
*/
public Object get(String name, ObjectFactory objectFactory) {
- Map attributes = CallStack.getCurrentFrame();
- Object scopedObject = attributes.get(name);
+ CallFrame frame = CallStack.getCurrentFrame();
+ Object scopedObject = frame.getAttribute(name);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
- attributes.put(name, scopedObject);
+ frame.setAttribute(name, scopedObject);
}
return scopedObject;
}
@@ -48,10 +46,10 @@
* @see org.springframework.beans.factory.config.Scope#remove(java.lang.String)
*/
public Object remove(String name) {
- Map attributes = CallStack.getCurrentFrame();
- Object scopedObject = attributes.get(name);
+ CallFrame frame = CallStack.getCurrentFrame();
+ Object scopedObject = frame.getAttribute(name);
if (scopedObject != null)
- attributes.remove(name);
+ frame.removeAttribute(name);
return scopedObject;
}
@@ -67,8 +65,7 @@
* @see org.springframework.beans.factory.config.Scope#registerDestructionCallback(java.lang.String, java.lang.Runnable)
*/
public void registerDestructionCallback(String name, Runnable callback) {
- // TODO Auto-generated method stub
-
+ CallStack.getCurrentFrame().registerDestructionCallback(name, callback);
}
}
Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java?view=diff&rev=503923&r1=503922&r2=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java Mon Feb 5 15:36:34 2007
@@ -16,12 +16,8 @@
*/
package org.apache.cocoon.callstack;
-import java.util.Map;
import java.util.Stack;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
/**
* Stack used for storing objects in the current call frame.
*
@@ -33,59 +29,39 @@
/** The call stack */
private static final ThreadLocal callStack = new ThreadLocal();
- /** Content map and objects that should be desctructed when the call frame is left */
- private static class CallStackInfo {
- public CallStackInfo(Map attributes, Map destructionCallbacks) {
- this.attributes = attributes;
- this.destructionCallbacks = destructionCallbacks;
- }
- public Map attributes;
- public Map destructionCallbacks;
- };
-
/**
* This hook must be called each time a call frame is entered.
- *
- * <p>This method should never raise an exception, except when the
- * parameters are not set!</p>
- *
- * @throws ServletException if block is null
*/
- public static void enter(Map attributes)
- throws ServletException {
- if (null == attributes) {
- throw new ServletException("Block is not set.");
- }
-
+ public static void enter() {
Stack stack = (Stack)callStack.get();
if (stack == null) {
stack = new Stack();
callStack.set(stack);
}
- CallStackInfo info = new CallStackInfo(attributes, null);
+ CallFrame info = new CallFrame();
stack.push(info);
}
/**
- * This hook must be called each time a block is left.
+ * This hook must be called each time a call frame is left.
*
- * <p>It's the counterpart to the {@link #enterBlock(Block)}
+ * <p>It's the counterpart to the {@link #enter()}
* method.</p>
*/
public static void leave() {
final Stack stack = (Stack)callStack.get();
- stack.pop();
+ CallFrame info = (CallFrame) stack.pop();
+ info.executeDestructionCallbacks();
}
/**
- * Use this method for getting the context that should be used for
- * resolving a block protocol call to a super block
- * @return a servlet context
+ * Use this method for getting the current call frame
+ * @return a call frame
*/
- public static Map getCurrentFrame() {
+ public static CallFrame getCurrentFrame() {
final Stack stack = (Stack)callStack.get();
if (stack != null && !stack.isEmpty()) {
- return ((CallStackInfo)stack.peek()).attributes;
+ return (CallFrame)stack.peek();
}
return null;
}
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java Mon Feb 5 15:36:34 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.callstack.environment;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cocoon.callstack.CallFrame;
+import org.apache.cocoon.callstack.CallStack;
+
+/**
+ * A set of constants and methods to access the content of the call frame.
+ * <p>
+ * The call frame is used to pass information about the Request, Response and
+ * Context of the calling environment to components used while the call frame
+ * is active.
+ * <p>
+ *
+ * @version $Id$
+ */
+public final class CallFrameHelper {
+
+ /** Key for the environment {@link HttpServletRequest} in the call frame. */
+ public final static String REQUEST_OBJECT = "request";
+
+ /** Key for the environment {@link HttpServletResponse} in the call frame. */
+ public final static String RESPONSE_OBJECT = "response";
+
+ /** Key for the environment {@link ServletContext} in the call frame. */
+ public final static String CONTEXT_OBJECT = "context";
+
+ private CallFrameHelper() {
+ // Forbid instantiation
+ }
+
+ public static final void setEnvironment(HttpServletRequest request, HttpServletResponse response, ServletContext context) {
+ CallFrame frame = CallStack.getCurrentFrame();
+ frame.setAttribute(REQUEST_OBJECT, request);
+ frame.setAttribute(RESPONSE_OBJECT, response);
+ frame.setAttribute(CONTEXT_OBJECT, context);
+ }
+
+ public static final HttpServletRequest getRequest() {
+ return (HttpServletRequest) CallStack.getCurrentFrame().getAttribute(REQUEST_OBJECT);
+ }
+
+ public static final void setRequest(HttpServletRequest request) {
+ CallStack.getCurrentFrame().setAttribute(REQUEST_OBJECT, request);
+ }
+
+ public static final HttpServletResponse getResponse() {
+ return (HttpServletResponse) CallStack.getCurrentFrame().getAttribute(RESPONSE_OBJECT);
+ }
+
+ public static final void setResponse(HttpServletResponse response) {
+ CallStack.getCurrentFrame().setAttribute(RESPONSE_OBJECT, response);
+ }
+
+ public static final ServletContext getContext() {
+ return (ServletContext) CallStack.getCurrentFrame().getAttribute(CONTEXT_OBJECT);
+ }
+
+ public static final void setContext(ServletContext context) {
+ CallStack.getCurrentFrame().setAttribute(CONTEXT_OBJECT, context);
+ }
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/CallFrameHelper.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java Mon Feb 5 15:36:34 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.callstack.environment;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.beans.factory.FactoryBean;
+
+/**
+ * Factorybean that exposes the HttpServletRequest in the current call frame.
+ * It will typically be used together with the call scope.
+ * @version $Id$
+ */
+public final class HttpServletRequestFactoryBean implements FactoryBean {
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+ return CallFrameHelper.getRequest();
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ public Class getObjectType() {
+ return HttpServletRequest.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletRequestFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java Mon Feb 5 15:36:34 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.callstack.environment;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.FactoryBean;
+
+/**
+ * Factorybean that exposes the HttpServletResponse in the current call frame.
+ * It will typically be used together with the call scope.
+ * @version $Id$
+ */
+public final class HttpServletResponseFactoryBean implements FactoryBean {
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+ return CallFrameHelper.getResponse();
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ public Class getObjectType() {
+ return HttpServletResponse.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/HttpServletResponseFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java Mon Feb 5 15:36:34 2007
@@ -0,0 +1,51 @@
+/*
+ * 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.callstack.environment;
+
+import javax.servlet.ServletContext;
+
+import org.springframework.beans.factory.FactoryBean;
+
+/**
+ * Factorybean that exposes the ServletContext in the current call frame.
+ * It will typically be used together with the call scope.
+ * @version $Id$
+ */
+public final class ServletContextFactoryBean implements FactoryBean {
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObject()
+ */
+ public Object getObject() throws Exception {
+ return CallFrameHelper.getContext();
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#getObjectType()
+ */
+ public Class getObjectType() {
+ return ServletContext.class;
+ }
+
+ /* (non-Javadoc)
+ * @see org.springframework.beans.factory.FactoryBean#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/environment/ServletContextFactoryBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.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-callstack-environment.xml?view=auto&rev=503923
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.xml (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.xml Mon Feb 5 15:36:34 2007
@@ -0,0 +1,57 @@
+<?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$ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
+
+ <!-- Install the call stack custom scope -->
+ <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
+ <property name="scopes">
+ <map>
+ <entry key="call">
+ <bean class="org.apache.cocoon.callstack.CallScope"/>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <!-- The request object of the current call frame -->
+ <bean name="javax.servlet.http.HttpServletRequest/callstack"
+ class="org.apache.cocoon.callstack.environment.HttpServletRequestFactoryBean"
+ scope="call">
+ <aop:scoped-proxy/>
+ </bean>
+
+ <!-- The response object of the current call frame -->
+ <bean name="javax.servlet.http.HttpServletResponse/callstack"
+ class="org.apache.cocoon.callstack.environment.HttpServletResponseFactoryBean"
+ scope="call">
+ <aop:scoped-proxy/>
+ </bean>
+
+ <!-- The context object of the current call frame -->
+ <bean name="javax.servlet.ServletContext/callstack"
+ class="org.apache.cocoon.callstack.environment.ServletContextFactoryBean"
+ scope="call">
+ <aop:scoped-proxy/>
+ </bean>
+
+</beans>
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/resources/META-INF/cocoon/spring/cocoon-callstack-environment.xml
------------------------------------------------------------------------------
svn:keywords = Id