CVS: Tapestry/framework/src/net/sf/tapestry/engine AbstractEngine.java,1.34.2.2,1.34.2.3 DefaultSpecificationSource.java,1.15.2.3,1.15.2.4 ResetService.java,1.6,1.6.2.1 PageService.java,1.5,1.5.2.1

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/engine
In directory sc8-pr-cvs1:/tmp/cvs-serv32677/framework/src/net/sf/tapestry/engine

Modified Files:
      Tag: hship-2-3
	AbstractEngine.java DefaultSpecificationSource.java 
	ResetService.java PageService.java 
Log Message:
Finish up code and tests for dynamically locating page specifications and templates.

Index: AbstractEngine.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/AbstractEngine.java,v
retrieving revision 1.34.2.2
retrieving revision 1.34.2.3
diff -C2 -d -r1.34.2.2 -r1.34.2.3
*** AbstractEngine.java	7 Dec 2002 13:26:10 -0000	1.34.2.2
--- AbstractEngine.java	12 Dec 2002 12:42:39 -0000	1.34.2.3
***************
*** 64,67 ****
--- 64,68 ----
  import net.sf.tapestry.util.exception.ExceptionAnalyzer;
  import net.sf.tapestry.util.io.DataSqueezer;
+ import net.sf.tapestry.util.pool.Pool;
  import net.sf.tapestry.util.prop.OgnlUtils;
  
***************
*** 336,339 ****
--- 337,351 ----
  
      /**
+      *  A shared instance of {@link Pool}.
+      * 
+      *  @since 2.4
+      * 
+      **/
+ 
+     private transient Pool _pool;
+ 
+     protected static final String POOL_NAME = "net.sf.tapestry.Pool";
+ 
+     /**
       *  Sets the Exception page's exception property, then renders the Exception page.
       *
***************
*** 873,876 ****
--- 885,889 ----
      public void clearCachedData()
      {
+         _pool.clear();
          _pageSource.reset();
          _specificationSource.reset();
***************
*** 917,920 ****
--- 930,934 ----
       *  <p>In addition, this method locates and/or creates the:
       *  <ul>
+      *  <li>{@link Pool}
       *  <li>{@link ITemplateSource} 
       *  <li>{@link ISpecificationSource}
***************
*** 925,928 ****
--- 939,946 ----
       *  <li>{@link IPropertySource}
       *  </ul>
+      * 
+      *  <p>This order is important, because some of the later shared objects
+      *  depend on some of the earlier shared objects already been located or created
+      *  (especially {@link #getPool() pool}).
       *
       *  <p>Subclasses should invoke this implementation first, then perform their
***************
*** 969,972 ****
--- 987,1004 ----
          String servletName = context.getServlet().getServletName();
  
+         if (_pool == null)
+         {
+             String name = POOL_NAME + "." + servletName;
+ 
+             _pool = (Pool) servletContext.getAttribute(name);
+ 
+             if (_pool == null)
+             {
+                 _pool = createPool(context);
+ 
+                 servletContext.setAttribute(name, _pool);
+             }
+         }
+ 
          if (_templateSource == null)
          {
***************
*** 1123,1127 ****
      protected IPageSource createPageSource(RequestContext context)
      {
!         return new PageSource(getResourceResolver());
      }
  
--- 1155,1159 ----
      protected IPageSource createPageSource(RequestContext context)
      {
!         return new PageSource(this);
      }
  
***************
*** 1138,1142 ****
      protected ISpecificationSource createSpecificationSource(RequestContext context)
      {
!         return new DefaultSpecificationSource(getResourceResolver(), _specification);
      }
  
--- 1170,1174 ----
      protected ISpecificationSource createSpecificationSource(RequestContext context)
      {
!         return new DefaultSpecificationSource(getResourceResolver(), _specification, _pool);
      }
  
***************
*** 1177,1181 ****
  
      public String toString()
!     {        
          StringBuffer buffer;
  
--- 1209,1213 ----
  
      public String toString()
!     {
          StringBuffer buffer;
  
***************
*** 1802,1804 ****
--- 1834,1857 ----
          return result;
      }
+ 
+     /** 
+      *  Returns an new instance of {@link Pool}.  Subclasses may override this
+      *  method to configure the Pool differently.
+      * 
+      *  @since 2.4 
+      * 
+      **/
+ 
+     protected Pool createPool(RequestContext context)
+     {
+         return new Pool();
+     }
+ 
+     /** @since 2.4 **/
+ 
+     public Pool getPool()
+     {
+         return _pool;
+     }
+ 
  }

Index: DefaultSpecificationSource.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/DefaultSpecificationSource.java,v
retrieving revision 1.15.2.3
retrieving revision 1.15.2.4
diff -C2 -d -r1.15.2.3 -r1.15.2.4
*** DefaultSpecificationSource.java	11 Dec 2002 14:02:26 -0000	1.15.2.3
--- DefaultSpecificationSource.java	12 Dec 2002 12:42:39 -0000	1.15.2.4
***************
*** 14,17 ****
--- 14,18 ----
  
  import net.sf.tapestry.ApplicationRuntimeException;
+ import net.sf.tapestry.IEngine;
  import net.sf.tapestry.IMarkupWriter;
  import net.sf.tapestry.INamespace;
***************
*** 29,32 ****
--- 30,34 ----
  import net.sf.tapestry.spec.LibrarySpecification;
  import net.sf.tapestry.util.StringSplitter;
+ import net.sf.tapestry.util.pool.Pool;
  import net.sf.tapestry.util.xml.DocumentParseException;
  
***************
*** 50,53 ****
--- 52,65 ----
      private static final Log LOG = LogFactory.getLog(DefaultSpecificationSource.class);
  
+     /**
+      *  Key used to get and store {@link SpecificationParser} instances
+      *  from the Pool.
+      * 
+      *  @since 2.4
+      * 
+      **/
+ 
+     private static final String PARSER_POOL_KEY = "net.sf.tapestry.SpecificationParser";
+ 
      private IResourceResolver _resolver;
      private IApplicationSpecification _specification;
***************
*** 90,97 ****
      private Map _namespaceCache = new HashMap();
  
!     public DefaultSpecificationSource(IResourceResolver resolver, IApplicationSpecification specification)
      {
          _resolver = resolver;
          _specification = specification;
      }
  
--- 102,121 ----
      private Map _namespaceCache = new HashMap();
  
!     /**
!      *  Reference to the shared {@link net.sf.tapestry.util.pool.Pool}.
!      * 
!      *  @see IEngine#getPool()
!      * 
!      *  @since 2.4
!      * 
!      **/
! 
!     private Pool _pool;
! 
!     public DefaultSpecificationSource(IResourceResolver resolver, IApplicationSpecification specification, Pool pool)
      {
          _resolver = resolver;
          _specification = specification;
+         _pool = pool;
      }
  
***************
*** 134,137 ****
--- 158,165 ----
                  ex);
          }
+         finally
+         {
+             discardParser(parser);
+         }
  
          return result;
***************
*** 198,209 ****
      {
          ToStringBuilder builder = new ToStringBuilder(this);
!         
          builder.append("applicationNamespace", _applicationNamespace);
          builder.append("frameworkNamespace", _frameworkNamespace);
          builder.append("specification", _specification);
!         
          return builder.toString();
      }
!     
      /** @since 1.0.6 **/
  
--- 226,237 ----
      {
          ToStringBuilder builder = new ToStringBuilder(this);
! 
          builder.append("applicationNamespace", _applicationNamespace);
          builder.append("frameworkNamespace", _frameworkNamespace);
          builder.append("specification", _specification);
! 
          return builder.toString();
      }
! 
      /** @since 1.0.6 **/
  
***************
*** 236,240 ****
          {
              // The keys are now IResourceLocation instances
!             
              Object key = i.next();
  
--- 264,268 ----
          {
              // The keys are now IResourceLocation instances
! 
              Object key = i.next();
  
***************
*** 319,330 ****
      /** @since 2.2 **/
  
!     private SpecificationParser getParser()
      {
!         // It would be good if this could get resused.  SpecificationParser
!         // is not threadsafe, so it would have to be pooled.
          
!         return new SpecificationParser();
      }
  
      public synchronized INamespace getApplicationNamespace()
      {
--- 347,367 ----
      /** @since 2.2 **/
  
!     protected SpecificationParser getParser()
      {
!         SpecificationParser result = (SpecificationParser) _pool.retrieve(PARSER_POOL_KEY);
          
!         if (result == null)
!             result = new SpecificationParser();
!             
!         return result;            
      }
  
+     /** @since 2.4 **/
+     
+     protected void discardParser(SpecificationParser parser)
+     {
+         _pool.store(PARSER_POOL_KEY, parser);
+     }
+     
      public synchronized INamespace getApplicationNamespace()
      {
***************
*** 341,345 ****
              IResourceLocation frameworkLocation =
                  new ClasspathResourceLocation(_resolver, "/net/sf/tapestry/Framework.library");
!                 
              ILibrarySpecification ls = getLibrarySpecification(frameworkLocation);
  
--- 378,382 ----
              IResourceLocation frameworkLocation =
                  new ClasspathResourceLocation(_resolver, "/net/sf/tapestry/Framework.library");
! 
              ILibrarySpecification ls = getLibrarySpecification(frameworkLocation);
  

Index: ResetService.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/ResetService.java,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -d -r1.6 -r1.6.2.1
*** ResetService.java	27 Nov 2002 17:58:51 -0000	1.6
--- ResetService.java	12 Dec 2002 12:42:39 -0000	1.6.2.1
***************
*** 5,8 ****
--- 5,9 ----
  import javax.servlet.ServletException;
  
+ import net.sf.tapestry.ApplicationRuntimeException;
  import net.sf.tapestry.Gesture;
  import net.sf.tapestry.IComponent;
***************
*** 51,54 ****
--- 52,59 ----
      {
          String[] context = getServiceContext(cycle.getRequestContext());
+ 
+         if (Tapestry.size(context) != 1)
+             throw new ApplicationRuntimeException(Tapestry.getString("service-single-parameter", RESET_SERVICE));
+ 
          String pageName = context[0];
  

Index: PageService.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/engine/PageService.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -C2 -d -r1.5 -r1.5.2.1
*** PageService.java	27 Nov 2002 17:58:51 -0000	1.5
--- PageService.java	12 Dec 2002 12:42:39 -0000	1.5.2.1
***************
*** 34,38 ****
              throw new IllegalArgumentException(Tapestry.getString("service-single-parameter", PAGE_SERVICE));
  
!         return assembleGesture(cycle, PAGE_SERVICE, (String[])parameters, null, true);
  
      }
--- 34,38 ----
              throw new IllegalArgumentException(Tapestry.getString("service-single-parameter", PAGE_SERVICE));
  
!         return assembleGesture(cycle, PAGE_SERVICE, (String[]) parameters, null, true);
  
      }
***************
*** 44,50 ****
          String[] serviceContext = getServiceContext(context);
  
!         if (serviceContext == null || serviceContext.length != 1)
!             throw new ApplicationRuntimeException(
!                 Tapestry.getString("service-single-parameter", IEngineService.PAGE_SERVICE));
  
          String pageName = serviceContext[0];
--- 44,49 ----
          String[] serviceContext = getServiceContext(context);
  
!         if (Tapestry.size(serviceContext) != 1)
!             throw new ApplicationRuntimeException(Tapestry.getString("service-single-parameter", PAGE_SERVICE));
  
          String pageName = serviceContext[0];



-------------------------------------------------------
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.