cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r504299 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/ cocoon-servlet-servi...
Date Tue, 06 Feb 2007 21:27:52 GMT
Author: danielf
Date: Tue Feb  6 13:27:51 2007
New Revision: 504299

URL: http://svn.apache.org/viewvc?view=rev&rev=504299
Log:
Some renaming to get rid of a couple of references to blocks. And rewrote (and renamed) the
call stack of the servletservice package to be based on the more general call stack.

Added:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStackHelper.java
  (contents, props changed)
      - copied, changed from r503800, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java
Removed:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java
Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallStack.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletServiceContext.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java?view=diff&rev=504299&r1=504298&r2=504299
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPathModule.java
Tue Feb  6 13:27:51 2007
@@ -27,7 +27,7 @@
 import org.apache.cocoon.components.modules.input.InputModule;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
-import org.apache.cocoon.servletservice.CallStack;
+import org.apache.cocoon.servletservice.CallStackHelper;
 import org.apache.cocoon.servletservice.ServletServiceContext;
 
 /**
@@ -40,7 +40,7 @@
     public Object getAttribute( String name, Configuration modeConf, Map objectModel )
     throws ConfigurationException {
         Environment env = EnvironmentHelper.getCurrentEnvironment();
-        ServletServiceContext blockContext = (ServletServiceContext) CallStack.getBaseBlockContext();
+        ServletServiceContext blockContext = (ServletServiceContext) CallStackHelper.getBaseServletContext();
         String absoluteURI = null;
         /* No relative block paths yet
         String baseURI = env.getURIPrefix();

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java?view=diff&rev=504299&r1=504298&r2=504299
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/BlockPropertyModule.java
Tue Feb  6 13:27:51 2007
@@ -23,7 +23,7 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.components.modules.input.InputModule;
-import org.apache.cocoon.servletservice.CallStack;
+import org.apache.cocoon.servletservice.CallStackHelper;
 
 /**
  * BlockPropertyModule provides access to the properties of the current block.
@@ -34,7 +34,7 @@
 
     public Object getAttribute( String name, Configuration modeConf, Map objectModel )
     throws ConfigurationException {
-        return CallStack.getBaseBlockContext().getInitParameter(name);
+        return CallStackHelper.getBaseServletContext().getInitParameter(name);
     }
 
     public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)

Modified: 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=diff&rev=504299&r1=504298&r2=504299
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/callstack/CallFrame.java
Tue Feb  6 13:27:51 2007
@@ -30,6 +30,10 @@
 public class CallFrame {
     private Map attributes;
     private Map destructionCallbacks;
+    
+    public boolean hasAttribute(String name) {
+        return this.attributes != null ? this.attributes.containsKey(name) : false;
+    }
 
     public Object getAttribute(String name) {
         return this.attributes != null ? this.attributes.get(name) : null;

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=504299&r1=504298&r2=504299
==============================================================================
--- 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
Tue Feb  6 13:27:51 2007
@@ -65,4 +65,23 @@
         }
         return null;
     }
+    
+    /**
+     * @return the size of the call stack
+     */
+    public static int size() {
+        final Stack stack = (Stack)callStack.get();
+        return stack != null ? stack.size() : 0;
+    }
+    
+    /**
+     * Get the frame at the i:th position in the call stack
+     * @param i
+     * @return
+     */
+    public static CallFrame frameAt(int i) {
+        final Stack stack = (Stack)callStack.get();
+        return (CallFrame) (stack != null ? stack.elementAt(i) : null);
+    }
+
 }

Copied: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStackHelper.java
(from r503800, cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java)
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStackHelper.java?view=diff&rev=504299&p1=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java&r1=503800&p2=cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStackHelper.java&r2=504299
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStack.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/CallStackHelper.java
Tue Feb  6 13:27:51 2007
@@ -1,126 +1,106 @@
-/*
- * 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;
-
-import java.util.Stack;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-
-/**
- * Stack used for geting hold on the current block servlet
- *
- * @version $Id: BlockCallStack.java 496060 2007-01-14 11:03:06Z danielf $
- * @since 2.2 
- */
-public class CallStack {
-
-    /** The block stack */
-    private static final ThreadLocal blockStack = new ThreadLocal();
-    
-    /** Keep track on if it is an ordinary or a super call */
-    private static class BlockCallStackInfo {
-        public BlockCallStackInfo(ServletContext servletContext, boolean superCall) {
-            this.servletContext = servletContext;
-            this.superCall = superCall;
-        }
-        public ServletContext servletContext;
-        public boolean superCall;
-    };
-
-    /**
-     * This hook must be called each time a block 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 enterBlock(ServletContext context)
-    throws ServletException {
-        enterBlock(context, false);
-    }
-
-    /**
-     * This hook must be called each time a super block 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 enterSuperBlock(ServletContext context)
-    throws ServletException {
-        enterBlock(context, true);
-    }
-
-    private static void enterBlock(ServletContext context, boolean superCall)
-    throws ServletException {
-        if (null == context) {
-            throw new ServletException("Block is not set.");
-        }
-
-        Stack stack = (Stack)blockStack.get();
-        if (stack == null) {
-            stack = new Stack();
-            blockStack.set(stack);
-        }
-        BlockCallStackInfo info = new BlockCallStackInfo(context, superCall);
-        stack.push(info);
-    }
-
-    /**
-     * This hook must be called each time a block is left.
-     *
-     * <p>It's the counterpart to the {@link #enterBlock(Block)}
-     * method.</p>
-     */
-    public static void leaveBlock() {
-        final Stack stack = (Stack)blockStack.get();
-        stack.pop();
-    }
-
-    /**
-     * Use this method for getting the context that should be used for
-     * resolving a polymorphic block protocol call 
-     * @return a servlet context
-     */
-    public static ServletContext getBaseBlockContext() {
-        final Stack stack = (Stack)blockStack.get();
-        if (stack != null) {
-            for(int i = stack.size() - 1; i >= 0; i--) {
-                BlockCallStackInfo info = (BlockCallStackInfo) stack.elementAt(i);
-                if (!info.superCall)
-                    return info.servletContext;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * 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
-     */
-    public static ServletContext getCurrentBlockContext() {
-        final Stack stack = (Stack)blockStack.get();
-        if (stack != null && !stack.isEmpty()) {
-            return ((BlockCallStackInfo)stack.peek()).servletContext;
-        }
-        return null;
-    }
-}
+/*
+ * 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;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.cocoon.callstack.CallFrame;
+import org.apache.cocoon.callstack.CallStack;
+import org.apache.cocoon.callstack.environment.CallFrameHelper;
+
+/**
+ * Helper class used for geting hold on the current servlet service
+ *
+ * @version $Id$
+ * @since 2.2 
+ */
+public class CallStackHelper {
+
+    /** Key for a value determing wether a call frame contains a super call or not */
+    public final static String SUPER_CALL = "super";
+
+    /**
+     * This hook must be called each time a servlet service 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 enterServlet(ServletContext context)
+    throws ServletException {
+        enterServlet(context, false);
+    }
+
+    /**
+     * This hook must be called each time a super servlet service is entered.
+     *
+     * <p>This method should never raise an exception, except when the
+     * parameters are not set!</p>
+     *
+     * @throws ServletException if the context is null
+     */
+    public static void enterSuperServlet(ServletContext context)
+    throws ServletException {
+        enterServlet(context, true);
+    }
+
+    private static void enterServlet(ServletContext context, boolean superCall)
+    throws ServletException {
+        if (null == context) {
+            throw new ServletException("The context is not set.");
+        }
+
+        CallStack.enter();
+        CallStack.getCurrentFrame().setAttribute(SUPER_CALL, new Boolean(superCall));
+        CallFrameHelper.setContext(context);
+    }
+
+    /**
+     * This hook must be called each time a servlet service is left.
+     *
+     * <p>It's the counterpart to the {@link #enterServlet(ServletContext)}
+     * method.</p>
+     */
+    public static void leaveServlet() {
+        CallStack.leave();
+    }
+
+    /**
+     * Use this method for getting the context that should be used for
+     * resolving a polymorphic servlet protocol call 
+     * @return a servlet context
+     */
+    public static ServletContext getBaseServletContext() {
+        for(int i = CallStack.size() - 1; i >= 0; i--) {
+            CallFrame frame = CallStack.frameAt(i);
+            if (frame.hasAttribute(SUPER_CALL) && !((Boolean)frame.getAttribute(SUPER_CALL)).booleanValue())
+                return (ServletContext) frame.getAttribute(CallFrameHelper.CONTEXT_OBJECT);
+        }
+        return null;
+    }
+
+    /**
+     * Use this method for getting the context that should be used for
+     * resolving a servlet protocol call to a super servlet service 
+     * @return a servlet context
+     */
+    public static ServletContext getCurrentServletContext() {
+        return CallFrameHelper.getContext();
+    }
+}

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

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

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java?view=diff&rev=504299&r1=504298&r2=504299
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
Tue Feb  6 13:27:51 2007
@@ -79,9 +79,9 @@
         // Super calls are resolved relative the current context and ordinary
         // calls relative the last non super call in the call chain
         if (ServletServiceContext.SUPER.equals(this.blockName))
-            this.context = CallStack.getCurrentBlockContext();
+            this.context = CallStackHelper.getCurrentServletContext();
         else
-            this.context = CallStack.getBaseBlockContext();
+            this.context = CallStackHelper.getBaseServletContext();
         
         if (this.context == null)
             throw new MalformedURLException("Must be used in a block context " + url);

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=504299&r1=504298&r2=504299
==============================================================================
--- 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
Tue Feb  6 13:27:51 2007
@@ -526,17 +526,17 @@
                     // 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);
+                    CallStackHelper.enterServlet(ServletServiceContext.this);
                 } else {
                     // 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);
+                    CallStackHelper.enterSuperServlet(ServletServiceContext.this);
                 }                        
                 ServletServiceContext.this.servlet.service(request, response);
             } finally {
-                CallStack.leaveBlock();
+                CallStackHelper.leaveServlet();
             }
         }
 



Mime
View raw message