You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2005/09/22 22:14:02 UTC

svn commit: r291013 - in /jakarta/tapestry/trunk: ./ framework/src/descriptor/META-INF/ framework/src/java/org/apache/tapestry/services/ framework/src/java/org/apache/tapestry/services/impl/ framework/src/test/org/apache/tapestry/services/impl/ portlet...

Author: hlship
Date: Thu Sep 22 13:13:53 2005
New Revision: 291013

URL: http://svn.apache.org/viewcvs?rev=291013&view=rev
Log:
TAPESTRY-639: Expose the ServletContext as service tapestry.globals.ServletContext

Added:
    jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/WebContextInitializerTest.java
Modified:
    jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.globals.xml
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/ApplicationGlobals.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/ApplicationGlobalsImpl.java
    jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/WebContextInitializer.java
    jakarta/tapestry/trunk/portlet/src/java/org/apache/tapestry/portlet/PortletWebContextInitializer.java
    jakarta/tapestry/trunk/status.xml

Modified: jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.globals.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.globals.xml?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.globals.xml (original)
+++ jakarta/tapestry/trunk/framework/src/descriptor/META-INF/tapestry.globals.xml Thu Sep 22 13:13:53 2005
@@ -85,6 +85,16 @@
     
   </service-point>
   
+  <service-point id="ServletContext" interface="javax.servlet.ServletContext">
+    
+    Exposes the global ServletContext s a service.
+    
+    <invoke-factory service-id="hivemind.lib.ServicePropertyFactory">
+      <construct service-id="ApplicationGlobals" property="servletContext"/>
+    </invoke-factory>
+    
+  </service-point>  
+  
  <service-point id="SetupServletApplicationGlobals" interface="ApplicationInitializer">
   
   Contributed into the tapestry.init.ApplicationInitializers configuration point

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/ApplicationGlobals.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/ApplicationGlobals.java?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/ApplicationGlobals.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/ApplicationGlobals.java Thu Sep 22 13:13:53 2005
@@ -16,6 +16,8 @@
 
 import java.util.List;
 
+import javax.servlet.ServletContext;
+
 import org.apache.tapestry.spec.IApplicationSpecification;
 import org.apache.tapestry.web.WebActivator;
 import org.apache.tapestry.web.WebContext;
@@ -39,10 +41,15 @@
     public void storeSpecification(IApplicationSpecification applicationSpecification);
 
     /**
-     * Invoked by the (indirectly) by the servlet at init().
+     * Invoked (indirectly) by the servlet at init().
      */
+    public void storeServletContext(ServletContext context);
 
-    public void storeContext(WebContext context);
+    /**
+     * Invoked (indirectly) by the servlet at init().
+     */
+
+    public void storeWebContext(WebContext context);
 
     /**
      * Returns the previously stored context.
@@ -51,6 +58,13 @@
      */
 
     public WebContext getWebContext();
+
+    /**
+     * Returns the previously stored context.
+     * 
+     * @see #storeServletContext(ServletContext)
+     */
+    public ServletContext getServletContext();
 
     public WebActivator getActivator();
 

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/ApplicationGlobalsImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/ApplicationGlobalsImpl.java?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/ApplicationGlobalsImpl.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/ApplicationGlobalsImpl.java Thu Sep 22 13:13:53 2005
@@ -16,6 +16,8 @@
 
 import java.util.List;
 
+import javax.servlet.ServletContext;
+
 import org.apache.tapestry.services.ApplicationGlobals;
 import org.apache.tapestry.spec.IApplicationSpecification;
 import org.apache.tapestry.web.WebActivator;
@@ -37,6 +39,8 @@
 
     private List _factoryServices;
 
+    private ServletContext _servletContext;
+
     public void storeActivator(WebActivator activator)
     {
         _activator = activator;
@@ -67,7 +71,7 @@
         return _webContext;
     }
 
-    public void storeContext(WebContext context)
+    public void storeWebContext(WebContext context)
     {
         _webContext = context;
     }
@@ -80,5 +84,15 @@
     public List getFactoryServices()
     {
         return _factoryServices;
+    }
+
+    public ServletContext getServletContext()
+    {
+        return _servletContext;
+    }
+
+    public void storeServletContext(ServletContext context)
+    {
+        _servletContext = context;
     }
 }

Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/WebContextInitializer.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/WebContextInitializer.java?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/WebContextInitializer.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/services/impl/WebContextInitializer.java Thu Sep 22 13:13:53 2005
@@ -23,9 +23,8 @@
 import org.apache.tapestry.web.WebContext;
 
 /**
- * Gets the context from the servlet, creates a
- * {@link org.apache.tapestry.web.ServletWebContext}, and stores that into the
- * {@link org.apache.tapestry.services.ApplicationGlobals}.
+ * Gets the context from the servlet, creates a {@link org.apache.tapestry.web.ServletWebContext},
+ * and stores that into the {@link org.apache.tapestry.services.ApplicationGlobals}.
  * 
  * @author Howard M. Lewis Ship
  * @since 4.0
@@ -39,7 +38,8 @@
         ServletContext servletContext = servlet.getServletContext();
         WebContext context = new ServletWebContext(servletContext);
 
-        _globals.storeContext(context);
+        _globals.storeServletContext(servletContext);
+        _globals.storeWebContext(context);
     }
 
     public void setGlobals(ApplicationGlobals globals)

Added: jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/WebContextInitializerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/WebContextInitializerTest.java?rev=291013&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/WebContextInitializerTest.java (added)
+++ jakarta/tapestry/trunk/framework/src/test/org/apache/tapestry/services/impl/WebContextInitializerTest.java Thu Sep 22 13:13:53 2005
@@ -0,0 +1,56 @@
+// Copyright 2005 The Apache Software Foundation
+//
+// Licensed 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.tapestry.services.impl;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.hivemind.test.HiveMindTestCase;
+import org.apache.tapestry.services.ApplicationGlobals;
+
+/**
+ * Tests for {@link org.apache.tapestry.services.impl.WebContextInitializer}.
+ * 
+ * @author Howard M. Lewis Ship
+ * @since 4.0
+ */
+public class WebContextInitializerTest extends HiveMindTestCase
+{
+
+    public void testInitializer()
+    {
+        HttpServlet servlet = (HttpServlet) newMock(HttpServlet.class);
+        ServletContext servletContext = (ServletContext) newMock(ServletContext.class);
+
+        servlet.getServletContext();
+        getControl(servlet).setReturnValue(servletContext);
+
+        replayControls();
+
+        ApplicationGlobals globals = new ApplicationGlobalsImpl();
+
+        WebContextInitializer initializer = new WebContextInitializer();
+
+        initializer.setGlobals(globals);
+
+        initializer.initialize(servlet);
+
+        verifyControls();
+
+        assertSame(servletContext, globals.getServletContext());
+        assertNotNull(globals.getWebContext());
+    }
+
+}

Modified: jakarta/tapestry/trunk/portlet/src/java/org/apache/tapestry/portlet/PortletWebContextInitializer.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/portlet/src/java/org/apache/tapestry/portlet/PortletWebContextInitializer.java?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/portlet/src/java/org/apache/tapestry/portlet/PortletWebContextInitializer.java (original)
+++ jakarta/tapestry/trunk/portlet/src/java/org/apache/tapestry/portlet/PortletWebContextInitializer.java Thu Sep 22 13:13:53 2005
@@ -38,7 +38,7 @@
         WebContext context = new PortletWebContext(portletConfig.getPortletContext());
 
         _applicationGlobals.storeActivator(activator);
-        _applicationGlobals.storeContext(context);
+        _applicationGlobals.storeWebContext(context);
     }
 
     public void setApplicationGlobals(ApplicationGlobals applicationGlobals)

Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=291013&r1=291012&r2=291013&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Thu Sep 22 13:13:53 2005
@@ -65,6 +65,7 @@
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-485" due-to="Pierre-Yves Nicolas">Document Upload component</action>
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-660">Injecting meta data generates incorrect code for boolean properties</action>
       <action type="update" dev="HLS">Improve exception reporting of certain objects, including object arrays</action>
+      <action type="update" dev="HLS" fixes-bug="TAPESTRY-639">Expose the ServletContext as service tapestry.globals.ServletContext</action>
     </release>
     <release version="4.0-beta-7" date="Sep 17 2005">
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-341">Need better line-precise reporting for listener method</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org