CVS: Tapestry/framework/src/net/sf/tapestry/pageload PageLoader.java,1.15.2.5,1.15.2.6 PageSource.java,1.13.2.3,1.13.2.4 PageSpecificationResolver.java,1.1.2.1,1.1.2.2

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

Modified Files:
      Tag: hship-2-3
	PageLoader.java PageSource.java PageSpecificationResolver.java 
Log Message:
Finish up code and tests for dynamically locating page specifications and templates.

Index: PageLoader.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/pageload/PageLoader.java,v
retrieving revision 1.15.2.5
retrieving revision 1.15.2.6
diff -C2 -d -r1.15.2.5 -r1.15.2.6
*** PageLoader.java	11 Dec 2002 14:02:27 -0000	1.15.2.5
--- PageLoader.java	12 Dec 2002 12:42:39 -0000	1.15.2.6
***************
*** 137,141 ****
          _pageSource = pageSource;
  
!          RequestContext context = cycle.getRequestContext();
  
          // Need the location of the servlet within the context as the basis
--- 137,147 ----
          _pageSource = pageSource;
  
!         IEngine engine = cycle.getEngine();
! 
!         _specificationSource = engine.getSpecificationSource();
!         _resolver = engine.getResourceResolver();
!         _componentResolver = new ComponentResolver(_specificationSource);
! 
!         RequestContext context = cycle.getRequestContext();
  
          // Need the location of the servlet within the context as the basis
***************
*** 547,553 ****
  
          _locale = _engine.getLocale();
-         _specificationSource = _engine.getSpecificationSource();
-         _resolver = _engine.getResourceResolver();
-         _componentResolver = new ComponentResolver(_specificationSource);
  
          _count = 0;
--- 553,556 ----
***************
*** 571,577 ****
              _locale = null;
              _engine = null;
-             _specificationSource = null;
-             _resolver = null;
-             _componentResolver = null;
              _inheritedBindingQueue.clear();
          }
--- 574,577 ----
***************
*** 641,645 ****
          // whose spec is in the context (not the classpath) will be computed
          // wrong!  In fact, they'll be ContextAssets.
!         
          IResourceLocation assetLocation = baseLocation.getRelativeLocation(path);
  
--- 641,645 ----
          // whose spec is in the context (not the classpath) will be computed
          // wrong!  In fact, they'll be ContextAssets.
! 
          IResourceLocation assetLocation = baseLocation.getRelativeLocation(path);
  

Index: PageSource.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/pageload/PageSource.java,v
retrieving revision 1.13.2.3
retrieving revision 1.13.2.4
diff -C2 -d -r1.13.2.3 -r1.13.2.4
*** PageSource.java	11 Dec 2002 14:02:27 -0000	1.13.2.3
--- PageSource.java	12 Dec 2002 12:42:39 -0000	1.13.2.4
***************
*** 1,34 ****
  package net.sf.tapestry.pageload;
  
- import java.net.URL;
  import java.util.HashMap;
- import java.util.Iterator;
  import java.util.Map;
- import java.util.Set;
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  
- import net.sf.tapestry.ApplicationRuntimeException;
  import net.sf.tapestry.IAsset;
  import net.sf.tapestry.IBinding;
  import net.sf.tapestry.IEngine;
- import net.sf.tapestry.IMarkupWriter;
  import net.sf.tapestry.IMonitor;
- import net.sf.tapestry.INamespace;
  import net.sf.tapestry.IPage;
  import net.sf.tapestry.IPageSource;
- import net.sf.tapestry.IRenderDescription;
  import net.sf.tapestry.IRequestCycle;
  import net.sf.tapestry.IResourceLocation;
  import net.sf.tapestry.IResourceResolver;
- import net.sf.tapestry.ISpecificationSource;
  import net.sf.tapestry.PageLoaderException;
- import net.sf.tapestry.Tapestry;
- import net.sf.tapestry.asset.ContextAsset;
  import net.sf.tapestry.asset.ExternalAsset;
- import net.sf.tapestry.asset.PrivateAsset;
  import net.sf.tapestry.binding.FieldBinding;
  import net.sf.tapestry.binding.StaticBinding;
- import net.sf.tapestry.spec.ComponentSpecification;
  import net.sf.tapestry.util.MultiKey;
  import net.sf.tapestry.util.pool.Pool;
--- 1,22 ----
***************
*** 68,73 ****
   **/
  
! public class PageSource implements IPageSource, IRenderDescription
  {
      private Map _fieldBindings = new HashMap();
      private Map _staticBindings = new HashMap();
--- 56,68 ----
   **/
  
! public class PageSource implements IPageSource
  {
+     /**
+      *  Key used to find PageLoader instances in the Pool.
+      * 
+      **/
+ 
+     private static final String PAGE_LOADER_POOL_KEY = "net.sf.tapestry.PageLoader";
+ 
      private Map _fieldBindings = new HashMap();
      private Map _staticBindings = new HashMap();
***************
*** 86,90 ****
      /**
       *  The pool of {@link PooledPage}s.  The key is a {@link MultiKey},
!      *  built from the page name and the page locale.
       *
       **/
--- 81,88 ----
      /**
       *  The pool of {@link PooledPage}s.  The key is a {@link MultiKey},
!      *  built from the page name and the page locale.  This is a reference
!      *  to a shared pool.
!      * 
!      *  @see IEngine#getPool()
       *
       **/
***************
*** 101,109 ****
      private PageSpecificationResolver _pageSpecificationResolver;
  
!     public PageSource(IResourceResolver resolver)
      {
!         _resolver = resolver;
  
!         _pool = new Pool();
      }
  
--- 99,108 ----
      private PageSpecificationResolver _pageSpecificationResolver;
  
!     public PageSource(IEngine engine)
      {
!         _resolver = engine.getResourceResolver();
!         ;
  
!         _pool = engine.getPool();
      }
  
***************
*** 171,183 ****
              // one as needed.  However, they would make an excellent
              // candidate for pooling.
-             
-             PageLoader loader = new PageLoader(this, cycle);
  
!             result =
!                 loader.loadPage(
!                     pageName,
!                     _pageSpecificationResolver.getNamespace(),
!                     cycle,
!                     _pageSpecificationResolver.getSpecification());
  
              if (monitor != null)
--- 170,189 ----
              // one as needed.  However, they would make an excellent
              // candidate for pooling.
  
!             PageLoader loader = getPageLoader(cycle);
! 
!             try
!             {
!                 result =
!                     loader.loadPage(
!                         pageName,
!                         _pageSpecificationResolver.getNamespace(),
!                         cycle,
!                         _pageSpecificationResolver.getSpecification());
!             }
!             finally
!             {
!                 discardPageLoader(loader);
!             }
  
              if (monitor != null)
***************
*** 196,199 ****
--- 202,237 ----
  
      /**
+      *  Invoked to obtain an instance of 
+      *  {@link PageLoader}.  An instance if aquired from the pool or,
+      *  if none are available, created fresh.
+      * 
+      *  @since 2.4
+      * 
+      **/
+ 
+     protected PageLoader getPageLoader(IRequestCycle cycle)
+     {
+         PageLoader result = (PageLoader) _pool.retrieve(PAGE_LOADER_POOL_KEY);
+ 
+         if (result == null)
+             result = new PageLoader(this, cycle);
+ 
+         return result;
+     }
+ 
+     /**
+      *  Invoked once the {@link PageLoader} is not
+      *  longer needed; it is then returned to the pool.
+      * 
+      *  @since 2.4
+      * 
+      **/
+ 
+     protected void discardPageLoader(PageLoader loader)
+     {
+         _pool.store(PAGE_LOADER_POOL_KEY, loader);
+     }
+ 
+     /**
       *  Returns the page to the appropriate pool.  Invokes
       *  {@link IPage#detach()}.
***************
*** 216,221 ****
      public synchronized void reset()
      {
-         _pool.clear();
- 
          _fieldBindings.clear();
          _staticBindings.clear();
--- 254,257 ----
***************
*** 328,393 ****
      }
  
-     /** @since 1.0.6 **/
- 
-     public void renderDescription(IMarkupWriter writer)
-     {
-         writer.print("PageSource");
-         writer.begin("ul");
- 
-         if (_pool != null)
-         {
-             writer.begin("li");
-             writer.print("pool = ");
-             _pool.renderDescription(writer);
-             writer.end();
-         }
- 
-         describe(writer, _fieldBindings, "field bindings");
-         describe(writer, _staticBindings, "static bindings");
-         describe(writer, _assets, "assets");
- 
-         writer.end(); // <ul>
-     }
- 
-     /** @since 1.0.6 **/
- 
-     private void describe(IMarkupWriter writer, Map map, String label)
-     {
-         if (map == null)
-             return;
- 
-         synchronized (map)
-         {
-             Set entrySet = map.entrySet();
-             int count = entrySet.size();
- 
-             if (count > 0)
-             {
-                 writer.begin("li");
-                 writer.print(" ");
- 
-                 writer.print(count);
-                 writer.print(" cached ");
-                 writer.print(label);
- 
-                 writer.begin("ul");
- 
-                 Iterator i = map.entrySet().iterator();
- 
-                 while (i.hasNext())
-                 {
-                     Map.Entry e = (Map.Entry) i.next();
- 
-                     writer.begin("li");
-                     writer.print(e.getKey().toString());
-                     writer.println();
-                     writer.end();
-                 }
- 
-                 writer.end(); // <ul>
-                 writer.end(); // <li>
- 
-             }
-         }
-     }
  }
--- 364,366 ----

Index: PageSpecificationResolver.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/pageload/Attic/PageSpecificationResolver.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** PageSpecificationResolver.java	11 Dec 2002 14:02:27 -0000	1.1.2.1
--- PageSpecificationResolver.java	12 Dec 2002 12:42:39 -0000	1.1.2.2
***************
*** 23,27 ****
   *  <ul>
   *  <li><i>simple-name</i>.page in the same folder as the application specification
!  *  <li><i>simple-name</i>.page in WEB-INF of the context root
   *  <li><i>simple-name</i>.page in the application root (within the context root)
   *  <li><i>simple-name</i>.html as a template, for which an implicit specification is generated
--- 23,28 ----
   *  <ul>
   *  <li><i>simple-name</i>.page in the same folder as the application specification
!  *  <li><i>simple-name</i> page in the WEB-INF/pages/<i>servlet-name</i> directory of the context root
!  *  <li><i>simple-name</i>.page in WEB-INF
   *  <li><i>simple-name</i>.page in the application root (within the context root)
   *  <li><i>simple-name</i>.html as a template, for which an implicit specification is generated
***************
*** 59,68 ****
          _applicationRootLocation = Tapestry.getApplicationRootLocation(cycle);
  
          _webInfLocation = _applicationRootLocation.getRelativeLocation("/WEB-INF/");
!         _webInfPagesLocation = _webInfLocation.getRelativeLocation("pages/");
      }
  
      public void resolve(String pageName)
      {
          int colonx = pageName.indexOf(':');
  
--- 60,82 ----
          _applicationRootLocation = Tapestry.getApplicationRootLocation(cycle);
  
+         String servletName = cycle.getRequestContext().getServlet().getServletConfig().getServletName();
+ 
          _webInfLocation = _applicationRootLocation.getRelativeLocation("/WEB-INF/");
!         _webInfPagesLocation = _webInfLocation.getRelativeLocation("pages/" + servletName + "/");
      }
  
+     /**
+      *  Resolve the name (which may have a library id prefix) to a namespace
+      *  (see {@link #getNamespace()}) and a specification (see {@link #getSpecification()}).
+      * 
+      *  @throws ApplicationRuntimeException if the name cannot be resolved
+      * 
+      **/
+     
      public void resolve(String pageName)
      {
+         _namespace = null;
+         _specification = null;
+         
          int colonx = pageName.indexOf(':');
  
***************
*** 105,113 ****
      {
          return _specification;
-     }
- 
-     public String getSimplePageName()
-     {
-         return _simplePageName;
      }
  
--- 119,122 ----



-------------------------------------------------------
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility 
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/
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.