cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry ApplicationServlet.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cvs commit: jakarta-tapestry/framework/src/java/org/apache/tapestry ApplicationServlet.java

hlship
hlship      2005/05/11 10:07:20

  Modified:    .        status.xml
               framework/src/java/org/apache/tapestry/pageload
                        PageLoader.java PageloadMessages.java
               framework/src/java/org/apache/tapestry
                        ApplicationServlet.java
  Log:
  TAPESTRY-323: Allow control over the ErrorHandler used when building the HiveMind Registry.
 
  Revision  Changes    Path
  1.103     +1 -1      jakarta-tapestry/status.xml
 
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- status.xml 11 May 2005 06:10:40 -0000 1.102
  +++ status.xml 11 May 2005 17:07:20 -0000 1.103
  @@ -58,7 +58,7 @@
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-166">Allow Submits to defer invoking their listener.</action>
         <action type="fix" dev="HLS" fixes-bug="TAPESTRY-320"> Property seperate data from different users stored using the tapestry.persist.ClientPropertyPersistenceStrategy service.</action>
         <action type="add" dev="HLS"> Store the Registry as a ServletContext attribute, so that it may be accessed from other servlets. </action>
  -      <action type="fix" dev="PF" fixes-bug="TAPESTRY-322">Fixed bug in RestartService where redirected url did not include the servlet context path.</action>
  +      <action type="add" dev="HLS" fixes-bug="TAPESTRY-323"> Allow control over the ErrorHandler used when building the HiveMind Registry. </action>
       </release>
       <release version="4.0-alpha-2" date="May 5 2005">
         <action type="update" dev="HLS"> Coordinate Locale changes with the hivemind.ThreadLocale service. </action>
 
 
 
  1.24      +37 -32    jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageLoader.java
 
  Index: PageLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageLoader.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- PageLoader.java 18 Apr 2005 17:06:40 -0000 1.23
  +++ PageLoader.java 11 May 2005 17:07:20 -0000 1.24
  @@ -21,6 +21,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.hivemind.ApplicationRuntimeException;
  +import org.apache.hivemind.ClassResolver;
   import org.apache.hivemind.HiveMind;
   import org.apache.hivemind.Location;
   import org.apache.tapestry.AbstractComponent;
  @@ -137,6 +138,10 @@
   
       private int _maxDepth;
   
  +    /** @since 4.0 */
  +
  +    private ClassResolver _classResolver;
  +
       public void initializeService()
       {
   
  @@ -463,30 +468,28 @@
       private IComponent instantiateComponent(IPage page, IComponent container, String id,
               IComponentSpecification spec, INamespace namespace, Location location)
       {
  -        IComponent result = null;
           String className = spec.getComponentClassName();
   
           if (HiveMind.isBlank(className))
               className = BaseComponent.class.getName();
  +        else
  +        {
  +            Class componentClass = _classResolver.findClass(className);
  +
  +            if (!IComponent.class.isAssignableFrom(componentClass))
  +                throw new ApplicationRuntimeException(PageloadMessages
  +                        .classNotComponent(componentClass), container, spec.getLocation(), null);
  +
  +            if (IPage.class.isAssignableFrom(componentClass))
  +                throw new ApplicationRuntimeException(PageloadMessages.pageNotAllowed(id),
  +                        container, spec.getLocation(), null);
  +        }
   
           ComponentConstructor cc = _componentConstructorFactory.getComponentConstructor(
                   spec,
                   className);
   
  -        try
  -        {
  -            result = (IComponent) cc.newInstance();
  -
  -        }
  -        catch (ClassCastException ex)
  -        {
  -            throw new ApplicationRuntimeException(PageloadMessages.classNotComponent(cc
  -                    .getComponentClass()), container, spec.getLocation(), ex);
  -        }
  -
  -        if (result instanceof IPage)
  -            throw new ApplicationRuntimeException(PageloadMessages.pageNotAllowed(result), result,
  -                    null, null);
  +        IComponent result = (IComponent) cc.newInstance();
   
           result.setNamespace(namespace);
           result.setPage(page);
  @@ -515,33 +518,29 @@
   
       private IPage instantiatePage(String name, INamespace namespace, IComponentSpecification spec)
       {
  -        IPage result = null;
  -
  +        Location location = spec.getLocation();
           PageClassProviderContext context = new PageClassProviderContext(name, spec, namespace);
           String className = _pageClassProvider.providePageClassName(context);
   
  +        Class pageClass = _classResolver.findClass(className);
  +
  +        if (!IPage.class.isAssignableFrom(pageClass))
  +            throw new ApplicationRuntimeException(PageloadMessages.classNotPage(pageClass),
  +                    location, null);
  +
           String pageName = namespace.constructQualifiedName(name);
  -        Location location = spec.getLocation();
   
           ComponentConstructor cc = _componentConstructorFactory.getComponentConstructor(
                   spec,
                   className);
   
  -        try
  -        {
  -            result = (IPage) cc.newInstance();
  +        IPage result = (IPage) cc.newInstance();
   
  -            result.setNamespace(namespace);
  -            result.setPageName(pageName);
  -            result.setPage(result);
  -            result.setLocale(_locale);
  -            result.setLocation(location);
  -        }
  -        catch (ClassCastException ex)
  -        {
  -            throw new ApplicationRuntimeException(PageloadMessages.classNotPage(cc
  -                    .getComponentClass()), location, ex);
  -        }
  +        result.setNamespace(namespace);
  +        result.setPageName(pageName);
  +        result.setPage(result);
  +        result.setLocale(_locale);
  +        result.setLocation(location);
   
           return result;
       }
  @@ -718,4 +717,10 @@
       {
           _pageClassProvider = pageClassProvider;
       }
  +
  +    /** @since 4.0 */
  +    public void setClassResolver(ClassResolver classResolver)
  +    {
  +        _classResolver = classResolver;
  +    }
   }
  \ No newline at end of file
 
 
 
  1.7       +2 -2      jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageloadMessages.java
 
  Index: PageloadMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/pageload/PageloadMessages.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PageloadMessages.java 18 Apr 2005 17:06:40 -0000 1.6
  +++ PageloadMessages.java 11 May 2005 17:07:20 -0000 1.7
  @@ -84,9 +84,9 @@
           return _formatter.format("unable-to-instantiate", className, cause);
       }
   
  -    public static String pageNotAllowed(IComponent component)
  +    public static String pageNotAllowed(String componentId)
       {
  -        return _formatter.format("page-not-allowed", component.getExtendedId());
  +        return _formatter.format("page-not-allowed", componentId);
       }
   
       public static String classNotPage(Class componentClass)
 
 
 
  1.17      +18 -1     jakarta-tapestry/framework/src/java/org/apache/tapestry/ApplicationServlet.java
 
  Index: ApplicationServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/ApplicationServlet.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ApplicationServlet.java 10 May 2005 14:07:14 -0000 1.16
  +++ ApplicationServlet.java 11 May 2005 17:07:20 -0000 1.17
  @@ -30,10 +30,12 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.hivemind.ClassResolver;
  +import org.apache.hivemind.ErrorHandler;
   import org.apache.hivemind.Registry;
   import org.apache.hivemind.Resource;
   import org.apache.hivemind.impl.DefaultClassResolver;
   import org.apache.hivemind.impl.RegistryBuilder;
  +import org.apache.hivemind.impl.StrictErrorHandler;
   import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
   import org.apache.hivemind.util.ContextResource;
   import org.apache.tapestry.services.ApplicationInitializer;
  @@ -258,7 +260,9 @@
        */
       protected Registry constructRegistry(ServletConfig config)
       {
  -        RegistryBuilder builder = new RegistryBuilder();
  +        ErrorHandler errorHandler = constructErrorHandler(config);
  +
  +        RegistryBuilder builder = new RegistryBuilder(errorHandler);
   
           builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(_resolver));
   
  @@ -272,6 +276,19 @@
       }
   
       /**
  +     * Invoked by {@link #constructRegistry(ServletConfig)} to create and return an
  +     * {@link ErrorHandler} instance to be used when constructing the Registry (and then to handle
  +     * any runtime exceptions). This implementation returns a new instance of
  +     * {@link org.apache.hivemind.impl.StrictErrorHandler}.
  +     *
  +     * @since 4.0
  +     */
  +    protected ErrorHandler constructErrorHandler(ServletConfig config)
  +    {
  +        return new StrictErrorHandler();
  +    }
  +
  +    /**
        * Looks for a file in the servlet context; if it exists, it is expected to be a HiveMind module
        * descriptor, and is added to the builder.
        *
 
 
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]