CVS: Tapestry/framework/src/net/sf/tapestry ApplicationServlet.java,1.16,1.17 RequestContext.java,1.18,1.19 AbstractPage.java,1.11,1.12 IEngine.java,1.11,1.12 IPage.java,1.12,1.13

Malcolm Edgar <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry
In directory sc8-pr-cvs1:/tmp/cvs-serv9921/framework/src/net/sf/tapestry

Modified Files:
	ApplicationServlet.java RequestContext.java AbstractPage.java 
	IEngine.java IPage.java 
Log Message:
[660372] Add Global object

Index: ApplicationServlet.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/ApplicationServlet.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** ApplicationServlet.java	27 Nov 2002 17:58:45 -0000	1.16
--- ApplicationServlet.java	2 Jan 2003 11:34:43 -0000	1.17
***************
*** 72,75 ****
--- 72,85 ----
  public class ApplicationServlet extends HttpServlet
  {
+     /**
+      *  The name of the application specification property used to specify the
+      *  class of the global object: <code>net.sf.tapestry.global-class</code>
+      *
+      *  @since 2.3
+      *
+      **/
+ 
+     public static final String GLOBAL_CLASS_PROPERTY_NAME = "net.sf.tapestry.global-class";
+ 
      private static final Log LOG = LogFactory.getLog(ApplicationServlet.class);
  
***************
*** 378,381 ****
--- 388,392 ----
       *  @see #constructApplicationSpecification()
       *  @see #createResourceResolver()
+      *  @see #initializeGlobalObject()
       *
       **/
***************
*** 390,393 ****
--- 401,406 ----
  
          _attributeName = "net.sf.tapestry.engine." + config.getServletName();
+         
+         initializeGlobalObject();
      }
  
***************
*** 565,568 ****
--- 578,621 ----
          {
              throw new ServletException(ex);
+         }
+     }
+     
+     /**
+      *  Invoked by {@link #init(ServletConfig)} to instantiate the global object 
+      *  and store it in {@link ServletContext} as the attribute named 
+      *  {@link RequestContext#GLOBAL_OBJECT_NAME}.
+      *
+      *  <p>The global object class name is defined an parameter 
+      *  {@link #GLOBAL_CLASS_PROPERTY_NAME} in the application 
+      *  specification.
+      *
+      *  @since 2.3
+      */
+     protected void initializeGlobalObject()
+     {
+         String globalClassName = _specification.getProperty(GLOBAL_CLASS_PROPERTY_NAME);
+         
+         if (globalClassName != null) {
+             if (LOG.isDebugEnabled())
+                 LOG.debug("Creating global object as instance of " + globalClassName);
+ 
+             Class globalClass = _resolver.findClass(globalClassName);
+     
+             try
+             {
+                 Object global = globalClass.newInstance();
+ 
+                 getServletContext().setAttribute(RequestContext.GLOBAL_OBJECT_NAME, global);
+             }
+             catch (Throwable t)
+             {
+                 throw new ApplicationRuntimeException(
+                     Tapestry.getString("ApplicationEngine.unable-to-instantiate-global", globalClassName),
+                     t);
+             }
+ 
+         } else {
+             if (LOG.isDebugEnabled())
+                 LOG.debug("No global object defined in application specification");
          }
      }

Index: RequestContext.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/RequestContext.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** RequestContext.java	27 Nov 2002 17:58:45 -0000	1.18
--- RequestContext.java	2 Jan 2003 11:34:43 -0000	1.19
***************
*** 43,46 ****
--- 43,47 ----
   *  <li>Retrieving the request parameters (even if a file upload is involved)
   *  <li>Getting, setting and removing request attributes
+  *  <li>Getting the global object from the servlet context
   *  <li>Forwarding requests
   *  <li>Redirecting requests
***************
*** 109,112 ****
--- 110,123 ----
      public static final String REQUEST_DECODER_EXTENSION_NAME = "net.sf.tapestry.request-decoder";
  
+     /**
+      *  Servlet context attribute name used to store the global object:
+      *  <code>net.sf.tapestry.global</code>
+      *
+      *  @since 2.3
+      *
+      **/
+ 
+     public static final String GLOBAL_OBJECT_NAME = "net.sf.tapestry.global";
+ 
      private HttpSession _session;
      private HttpServletRequest _request;
***************
*** 568,571 ****
--- 579,597 ----
  
          return _decoder.getUploadFile(name);
+     }
+ 
+     /**
+      *  Returns the global object stored in the servlet context as the
+      *  attribute named {@link #GLOBAL_OBJECT_NAME}.
+      *
+      *  <p>Returns the global object, if it exists, or null if not defined.
+      *
+      *  @since 2.3
+      *
+      **/
+ 
+     public Object getGlobal()
+     {
+         return _servlet.getServletContext().getAttribute(GLOBAL_OBJECT_NAME);
      }
  

Index: AbstractPage.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/AbstractPage.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** AbstractPage.java	23 Dec 2002 12:47:48 -0000	1.11
--- AbstractPage.java	2 Jan 2003 11:34:43 -0000	1.12
***************
*** 369,372 ****
--- 369,377 ----
      }
  
+     public Object getGlobal()
+     {
+         return _engine.getGlobal();
+     }
+ 
      public void addPageDetachListener(PageDetachListener listener)
      {

Index: IEngine.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/IEngine.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** IEngine.java	27 Nov 2002 17:58:45 -0000	1.11
--- IEngine.java	2 Jan 2003 11:34:43 -0000	1.12
***************
*** 222,225 ****
--- 222,237 ----
  
      /**
+      *  Returns the globally shared application object. The global object is
+      *  stored in the servlet context.
+      *
+      *  <p>Returns the global object, if it exists, or null if not defined.
+      *
+      *  @since 2.3
+      * 
+      **/
+ 
+     public Object getGlobal();
+ 
+     /**
       *  Returns true if the application allows the reset service.
       *

Index: IPage.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/IPage.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** IPage.java	23 Dec 2002 12:47:48 -0000	1.12
--- IPage.java	2 Jan 2003 11:34:43 -0000	1.13
***************
*** 250,253 ****
--- 250,265 ----
  	public Object getVisit();
  
+     /**
+      *  Returns the globally shared application object. The global object is
+      *  stored in the servlet context.
+      *
+      *  <p>Returns the global object, if it exists, or null if not defined.
+      *
+      *  @since 2.3
+      * 
+      **/
+ 
+     public Object getGlobal();
+ 
  	/**
  	 *  @since 1.0.5



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.