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 2004/06/22 15:26:01 UTC

cvs commit: jakarta-tapestry/config log4j.properties

hlship      2004/06/22 06:26:01

  Modified:    framework/src/org/apache/tapestry TapestryStrings.properties
                        ApplicationServlet.java
               framework/conf/META-INF hivemodule.sdl
               config   log4j.properties
  Added:       framework/src/org/apache/tapestry
                        TapestryStrings2.properties TapestryMessages.java
  Log:
  Begin splitting messages off of TapestryStrings.properties.
  
  Revision  Changes    Path
  1.43      +0 -3      jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties
  
  Index: TapestryStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings.properties,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- TapestryStrings.properties	17 Jun 2004 18:53:42 -0000	1.42
  +++ TapestryStrings.properties	22 Jun 2004 13:26:01 -0000	1.43
  @@ -56,9 +56,6 @@
   AbstractMarkupWriter.tag-not-open=A tag must be open before attributes may be set in an IMarkupWriter.
   
   ApplicationServlet.could-not-locate-engine=Could not locate an engine to service this request.
  -ApplicationServlet.could-not-parse-spec=Unable to parse application specification {0}.
  -ApplicationServlet.get-app-path-not-overriden=Application servlet {0} does not provide an implementation of method getApplicationServletPath().
  -ApplicationServlet.no-application-specification=Running application without an application specification.
   ApplicationServlet.engine-stateful-without-session=Engine {0} is stateful even though there is no HttpSession.  Discarding the engine. 
   
   BaseComponent.multiple-component-references=Template for component {0} contains multiple references to embedded component {1}.
  
  
  
  1.11      +115 -216  jakarta-tapestry/framework/src/org/apache/tapestry/ApplicationServlet.java
  
  Index: ApplicationServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/ApplicationServlet.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ApplicationServlet.java	21 Jun 2004 19:11:53 -0000	1.10
  +++ ApplicationServlet.java	22 Jun 2004 13:26:01 -0000	1.11
  @@ -19,7 +19,6 @@
   import java.util.Locale;
   
   import javax.servlet.ServletConfig;
  -import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.http.Cookie;
   import javax.servlet.http.HttpServlet;
  @@ -30,15 +29,14 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.ClassResolver;
  -import org.apache.hivemind.Resource;
  +import org.apache.hivemind.Registry;
   import org.apache.hivemind.impl.DefaultClassResolver;
  -import org.apache.hivemind.util.ClasspathResource;
  +import org.apache.hivemind.impl.RegistryBuilder;
   import org.apache.tapestry.engine.BaseEngine;
   import org.apache.tapestry.engine.IPropertySource;
  -import org.apache.tapestry.parse.SpecificationParser;
   import org.apache.tapestry.request.RequestContext;
  -import org.apache.tapestry.resource.ContextResource;
  -import org.apache.tapestry.spec.ApplicationSpecification;
  +import org.apache.tapestry.services.ApplicationGlobals;
  +import org.apache.tapestry.services.ApplicationInitializer;
   import org.apache.tapestry.spec.IApplicationSpecification;
   import org.apache.tapestry.util.DelegatingPropertySource;
   import org.apache.tapestry.util.ServletContextPropertySource;
  @@ -46,7 +44,6 @@
   import org.apache.tapestry.util.SystemPropertiesPropertySource;
   import org.apache.tapestry.util.exception.ExceptionAnalyzer;
   import org.apache.tapestry.util.pool.Pool;
  -import org.apache.tapestry.util.xml.DocumentParseException;
   
   /**
    *  Links a servlet container with a Tapestry application.  The servlet has some
  @@ -82,25 +79,22 @@
    *  the creation of a session; this involves the servlet and the engine storing
    *  locale information in a {@link Cookie}.
    * 
  - *  @version $Id$
  + * <p>
  + * As of release 3.1, this servlet will also create a HiveMind Registry and manage it.
  + * 
    *  @author Howard Lewis Ship
    * 
  - **/
  + */
   
   public class ApplicationServlet extends HttpServlet
   {
       private static final Log LOG = LogFactory.getLog(ApplicationServlet.class);
   
  -    /** @since 2.3 **/
  -
  -    private static final String APP_SPEC_PATH_PARAM =
  -        "org.apache.tapestry.application-specification";
  -
       /**
        *  Name of the cookie written to the client web browser to
        *  identify the locale.
        *
  -     **/
  +     */
   
       private static final String LOCALE_COOKIE_NAME = "org.apache.tapestry.locale";
   
  @@ -108,7 +102,7 @@
        *  A {@link Pool} used to store {@link IEngine engine}s that are not currently
        *  in use.  The key is on {@link Locale}.
        *
  -     **/
  +     */
   
       private Pool _enginePool = new Pool();
   
  @@ -116,7 +110,7 @@
        *  The application specification, which is read once and kept in memory
        *  thereafter.
        *
  -     **/
  +     */
   
       private IApplicationSpecification _specification;
   
  @@ -124,7 +118,7 @@
        * The name under which the {@link IEngine engine} is stored within the
        * {@link HttpSession}.
        *
  -     **/
  +     */
   
       private String _attributeName;
   
  @@ -133,7 +127,7 @@
        * 
        *  @since 3.0
        * 
  -     **/
  +     */
   
       private String _engineClassName;
   
  @@ -143,7 +137,7 @@
        *  
        *  @since 3.0
        * 
  -     **/
  +     */
   
       private IPropertySource _propertySource;
   
  @@ -152,7 +146,7 @@
        *
        *  @since 1.0.6
        *
  -     **/
  +     */
   
       public void doGet(HttpServletRequest request, HttpServletResponse response)
           throws IOException, ServletException
  @@ -163,18 +157,24 @@
       /**
        *  @since 2.3
        * 
  -     **/
  +     */
   
       private ClassResolver _resolver;
   
       /**
  +     * @since 3.1
  +     */
  +
  +    private Registry _registry;
  +
  +    /**
        * Handles the GET and POST requests. Performs the following:
        * <ul>
        * <li>Construct a {@link RequestContext}
        * <li>Invoke {@link #getEngine(RequestContext)} to get or create the {@link IEngine}
        * <li>Invoke {@link IEngine#service(RequestContext)} on the application
        * </ul>
  -     **/
  +     */
   
       protected void doService(HttpServletRequest request, HttpServletResponse response)
           throws IOException, ServletException
  @@ -244,9 +244,7 @@
               if (engine.isStateful())
               {
                   LOG.error(
  -                    Tapestry.format(
  -                        "ApplicationServlet.engine-stateful-without-session",
  -                        engine));
  +                    Tapestry.format("ApplicationServlet.engine-stateful-without-session", engine));
                   return;
               }
   
  @@ -296,7 +294,7 @@
        * 
        *  @since 2.3
        * 
  -     **/
  +     */
   
       protected RequestContext createRequestContext(
           HttpServletRequest request,
  @@ -320,7 +318,7 @@
        *  Invokes {@link #doService(HttpServletRequest, HttpServletResponse)}.
        *
        *
  -     **/
  +     */
   
       public void doPost(HttpServletRequest request, HttpServletResponse response)
           throws IOException, ServletException
  @@ -332,7 +330,7 @@
        *  Returns the application specification, which is read
        *  by the {@link #init(ServletConfig)} method.
        *
  -     **/
  +     */
   
       public IApplicationSpecification getApplicationSpecification()
       {
  @@ -348,7 +346,7 @@
        *  <li>Freshly created
        *  </ul>
        *
  -     **/
  +     */
   
       protected IEngine getEngine(RequestContext context) throws ServletException
       {
  @@ -396,7 +394,7 @@
        *  from the request itself.  This may return null
        *  if no locale is determined.
        *
  -     **/
  +     */
   
       protected Locale getLocaleFromRequest(RequestContext context) throws ServletException
       {
  @@ -417,7 +415,7 @@
        *  @see #constructApplicationSpecification()
        *  @see #createResourceResolver()
        *
  -     **/
  +     */
   
       public void init(ServletConfig config) throws ServletException
       {
  @@ -425,7 +423,19 @@
   
           _resolver = createClassResolver();
   
  -        _specification = constructApplicationSpecification();
  +        try
  +        {
  +
  +            constructRegistry();
  +
  +            initializeApplication();
  +        }
  +        catch (Exception ex)
  +        {
  +            show(ex);
  +
  +            throw new ServletException(TapestryMessages.servletInitFailure(ex), ex);
  +        }
   
           _attributeName = "org.apache.tapestry.engine:" + config.getServletName();
       }
  @@ -441,7 +451,7 @@
        *  @see #getResourceResolver()
        *  @since 2.3
        * 
  -     **/
  +     */
   
       protected ClassResolver createClassResolver() throws ServletException
       {
  @@ -449,165 +459,9 @@
       }
   
       /**
  -     *  Invoked from {@link #init(ServletConfig)} to read and construct
  -     *  the {@link ApplicationSpecification} for this servlet.
  -     *  Invokes {@link #getApplicationSpecificationPath()}, opens
  -     *  the resource as a stream, then invokes
  -     *  {@link #parseApplicationSpecification(IResourceLocation)}.
  -     * 
  -     *  <p>
  -     *  This method exists to be overriden in
  -     *  applications where the application specification cannot be
  -     *  loaded from the classpath.  Alternately, a subclass
  -     *  could override this method, invoke this implementation,
  -     *  and then add additional data to it (for example, an application
  -     *  where some of the pages are defined in an external source
  -     *  such as a database).
  -     *  
  -     *  @since 2.2
  -     * 
  -     **/
  -
  -    protected IApplicationSpecification constructApplicationSpecification() throws ServletException
  -    {
  -        Resource specLocation = getApplicationSpecificationLocation();
  -
  -        if (specLocation == null)
  -        {
  -            if (LOG.isDebugEnabled())
  -                LOG.debug(Tapestry.getMessage("ApplicationServlet.no-application-specification"));
  -
  -            return constructStandinSpecification();
  -        }
  -
  -        if (LOG.isDebugEnabled())
  -            LOG.debug("Loading application specification from " + specLocation);
  -
  -        return parseApplicationSpecification(specLocation);
  -    }
  -
  -    /**
  -     *  Gets the location of the application specification, if there is one.
  -     *  
  -     *  <ul>
  -     *  <li>Invokes {@link #getApplicationSpecificationPath()} to get the
  -     *  location of the application specification on the classpath.
  -     *  <li>If that return null, search for the application specification:
  -     *  <ul>
  -     *  <li><i>name</i>.application in /WEB-INF/<i>name</i>/
  -     *  <li><i>name</i>.application in /WEB-INF/
  -     *  </ul>
  -     *  </ul>
  -     * 
  -     *  <p>Returns the location of the application specification, or null
  -     *  if not found.
  -     * 
  -     *  @since 3.0
  -     * 
  -     **/
  -
  -    protected Resource getApplicationSpecificationLocation() throws ServletException
  -    {
  -        String path = getApplicationSpecificationPath();
  -
  -        if (path != null)
  -            return new ClasspathResource(_resolver, path);
  -
  -        ServletContext context = getServletContext();
  -        String servletName = getServletName();
  -        String expectedName = servletName + ".application";
  -
  -        Resource webInfLocation = new ContextResource(context, "/WEB-INF/");
  -        Resource webInfAppLocation = webInfLocation.getRelativeResource(servletName + "/");
  -
  -        Resource result = check(webInfAppLocation, expectedName);
  -        if (result != null)
  -            return result;
  -
  -        return check(webInfLocation, expectedName);
  -    }
  -
  -    /**
  -     *  Checks for the application specification relative to the specified
  -     *  location.
  -     * 
  -     *  @since 3.0
  -     * 
  -     **/
  -
  -    private Resource check(Resource location, String name)
  -    {
  -        Resource result = location.getRelativeResource(name);
  -
  -        if (LOG.isDebugEnabled())
  -            LOG.debug("Checking for existence of " + result);
  -
  -        if (result.getResourceURL() != null)
  -        {
  -            LOG.debug("Found.");
  -            return result;
  -        }
  -
  -        return null;
  -    }
  -
  -    /**
  -     *  Invoked from {@link #constructApplicationSpecification()} when
  -     *  the application doesn't have an explicit specification.  A
  -     *  simple specification is constructed and returned.  This is useful
  -     *  for minimal applications and prototypes.
  -     * 
  -     *  @since 3.0
  -     * 
  -     **/
  -
  -    protected IApplicationSpecification constructStandinSpecification()
  -    {
  -        ApplicationSpecification result = new ApplicationSpecification();
  -
  -        Resource virtualLocation =
  -            new ContextResource(getServletContext(), "/WEB-INF/");
  -
  -        result.setSpecificationLocation(virtualLocation);
  -
  -        result.setName(getServletName());
  -        result.setResourceResolver(_resolver);
  -
  -        return result;
  -    }
  -
  -    /**
  -     *  Invoked from {@link #constructApplicationSpecification()} to
  -     *  actually parse the stream (with content provided from the path)
  -     *  and convert it into an {@link ApplicationSpecification}.
  -     * 
  -     *  @since 2.2
  -     * 
  -     **/
  -
  -    protected IApplicationSpecification parseApplicationSpecification(Resource location)
  -        throws ServletException
  -    {
  -        try
  -        {
  -            SpecificationParser parser = new SpecificationParser(_resolver);
  -
  -            return parser.parseApplicationSpecification(location);
  -        }
  -        catch (DocumentParseException ex)
  -        {
  -            show(ex);
  -
  -            throw new ServletException(
  -                Tapestry.format("ApplicationServlet.could-not-parse-spec", location),
  -                ex);
  -        }
  -    }
  -
  -    /**
        *  Closes the stream, ignoring any exceptions.
        * 
  -     **/
  +     */
   
       protected void close(InputStream stream)
       {
  @@ -623,25 +477,6 @@
       }
   
       /**
  -     *  Reads the servlet init parameter
  -     *  <code>org.apache.tapestry.application-specification</code>, which
  -     *  is the location, on the classpath, of the application specification.
  -     *
  -     *  <p>
  -     *  If the parameter is not set, this method returns null, and a search
  -     *  for the application specification within the servlet context
  -     *  will begin.
  -     * 
  -     *  @see #getApplicationSpecificationLocation()
  -     * 
  -     **/
  -
  -    protected String getApplicationSpecificationPath() throws ServletException
  -    {
  -        return getInitParameter(APP_SPEC_PATH_PARAM);
  -    }
  -
  -    /**
        *  Invoked by {@link #getEngine(RequestContext)} to create
        *  the {@link IEngine} instance specific to the
        *  application, if not already in the
  @@ -652,7 +487,7 @@
        *
        *  @see #getEngineClassName()    
        *
  -     **/
  +     */
   
       protected IEngine createEngine(RequestContext context) throws ServletException
       {
  @@ -691,7 +526,7 @@
        *  <p>If the search is still unsuccessful, then
        *  {@link org.apache.tapestry.engine.BaseEngine} is used.
        * 
  -     **/
  +     */
   
       protected String getEngineClassName()
       {
  @@ -720,7 +555,7 @@
        *  @see #createPropertySource()
        *  @since 3.0
        * 
  -     **/
  +     */
   
       protected String searchConfiguration(String propertyName)
       {
  @@ -738,7 +573,7 @@
        * 
        *  @since 3.0
        * 
  -     **/
  +     */
   
       protected IPropertySource createPropertySource()
       {
  @@ -761,7 +596,7 @@
        *  change in subsequent releases.
        *
        *  @since 1.0.1
  -     **/
  +     */
   
       public void writeLocaleCookie(Locale locale, IEngine engine, RequestContext cycle)
       {
  @@ -782,11 +617,75 @@
        * 
        *  @since 2.3
        *
  -     **/
  +     */
   
       public ClassResolver getClassResolver()
       {
           return _resolver;
  +    }
  +
  +    /**
  +     * Invoked from {@link #init(ServletConfig)} to construct the Registry to
  +     * be used by the application.
  +     * 
  +     * @since 3.1
  +     */
  +    protected void constructRegistry()
  +    {
  +        // This will expand in the future.
  +
  +        _registry = RegistryBuilder.constructDefaultRegistry();
  +    }
  +
  +    /**
  +     * Invoked from {@link #init(ServletConfig)}, after the registry has
  +     * been constructed, to bootstrap the application via the
  +     * <code>tapestry.MasterApplicationInitializer</code> service.
  +     */
  +    protected void initializeApplication()
  +    {
  +        ApplicationInitializer ai =
  +            (ApplicationInitializer) _registry.getService(
  +                "tapestry.MasterInitializer",
  +                ApplicationInitializer.class);
  +
  +        ai.initialize(this);
  +
  +        _registry.cleanupThread();
  +
  +        // This is temporary, since most of the code still gets the
  +        // specification from the servlet.
  +
  +        ApplicationGlobals ag =
  +            (ApplicationGlobals) _registry.getService(
  +                "tapestry.ApplicationGlobals",
  +                ApplicationGlobals.class);
  +
  +        _specification = ag.getSpecification();
  +    }
  +
  +    /**
  +     * Returns the Registry used by the application.
  +     * 
  +     * @since 3.1
  +     */
  +    public Registry getRegistry()
  +    {
  +        return _registry;
  +    }
  +
  +    /**
  +     * Shuts down the registry (if it exists).
  +     * 
  +     * @since 3.1
  +     */
  +    public void destroy()
  +    {
  +        if (_registry != null)
  +        {
  +            _registry.shutdown();
  +            _registry = null;
  +        }
       }
   
   }
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/TapestryStrings2.properties
  
  Index: TapestryStrings2.properties
  ===================================================================
  # Copyright 2004 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.
  #
  # Contains String contants used throughout the Tapestry framework.
  # To keep things organized, each key is in two parts:  the simple class name
  # and a subkey within the class name.
  
  # Temporary file used to store messages for the org.apache.tapestry package, while we refactor
  # TapestryStrings.properties
  
  servlet-init-failure=Unable to initialize application servlet: {0}
  
  
  
  1.1                  jakarta-tapestry/framework/src/org/apache/tapestry/TapestryMessages.java
  
  Index: TapestryMessages.java
  ===================================================================
  // Copyright 2004 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;
  
  import org.apache.hivemind.impl.MessageFormatter;
  
  /**
   * 
   *
   * @author Howard Lewis Ship
   * @since 3.1
   */
  final class TapestryMessages
  {
      private static final MessageFormatter _formatter =
          new MessageFormatter(TapestryMessages.class, "TapestryStrings2");
  
      public static String servletInitFailure(Throwable cause)
      {
          return _formatter.format("servlet-init-failure", cause);
      }
  }
  
  
  
  1.2       +19 -11    jakarta-tapestry/framework/conf/META-INF/hivemodule.sdl
  
  Index: hivemodule.sdl
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/conf/META-INF/hivemodule.sdl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- hivemodule.sdl	21 Jun 2004 19:11:53 -0000	1.1
  +++ hivemodule.sdl	22 Jun 2004 13:26:01 -0000	1.2
  @@ -16,14 +16,14 @@
   {
     "The master module for the Tapestry web application framework."
     
  -  service-point (id=MasterApplicationInitializer interface=org.apache.tapestry.services.ApplicationInitializer)
  +  service-point (id=MasterInitializer interface=org.apache.tapestry.services.ApplicationInitializer)
     {
       "Master startup for the application; invokes an ordered series of other ApplicationInitializer instances contributed to "
       "the ApplicationInitializers configuration point."
       
       invoke-factory (service-id=hivemind.BuilderFactory)
       {
  -      construct (class=org.apache.tapestry.services.impl.MasterApplicationInitializer)
  +      construct (class=org.apache.tapestry.services.impl.MasterInitializer)
         {
           set-configuration (property=initializers configuration-id=ApplicationInitializers)
         }
  @@ -38,9 +38,9 @@
       {
         element (name=initializer)
         {
  -        attribute (name=name required=true translator=qualified-id)
  +       attribute (name=service-id required=true translator=service)
           {
  -          "The name of the initializer, used to set an explicit execution order."
  +          "The service, which must implement the ApplicationInitializer interface."
           }
         
           attribute (name=before translator=id-list)
  @@ -53,14 +53,17 @@
             "A comma-seperated list of the names of initializers that should execute before this initializer."
           }
         
  -        attribute (name=service-id required=true translator=service)
  -        {
  -          "The service, which must implement the ApplicationInitializer interface."
  -        }
  -      
  -        conversion (class=org.apache.tapestry.services.impl.InitializerContribution)
  +      	// Have to use the more cumbersome rules(), rather than conversion(), because we
  +      	// map service-id to two different properties.
  +      	
  +        rules
           {
  -          map (attribute=service-id property=initializer)
  +          create-object (class=org.apache.tapestry.services.impl.InitializerContribution)
  +          read-attribute (attribute=service-id property=initializer)
  +          read-attribute (attribute=service-id property=name translator=qualified-id)
  +          read-attribute (attribute=before property=before)
  +          read-attribute (attribute=after property=after)
  +          invoke-parent (method=addElement)
           }
           
         }  // element initializer
  @@ -104,5 +107,10 @@
     service-point (id=ApplicationGlobals interface=org.apache.tapestry.services.ApplicationGlobals)
     {
       create-instance (class=org.apache.tapestry.services.impl.ApplicationGlobalsImpl)
  +  }
  +  
  +  contribution (configuration-id=ApplicationInitializers)
  +  {
  +    initializer (service-id=ApplicationSpecificationInitializer)
     }
   }
  
  
  
  1.6       +2 -2      jakarta-tapestry/config/log4j.properties
  
  Index: log4j.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/config/log4j.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- log4j.properties	15 Mar 2003 21:22:08 -0000	1.5
  +++ log4j.properties	22 Jun 2004 13:26:01 -0000	1.6
  @@ -7,6 +7,6 @@
   
   # A1 uses PatternLayout.
   log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  -log4j.appender.A1.layout.ConversionPattern=%r %c{1} [%p] %m%n
  +log4j.appender.A1.layout.ConversionPattern=%c{1} [%p] %m%n
   
   log4j.category.org.apache.commons.digester.Digester=FATAL
  
  
  

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