avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject cvs commit: avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty SevakServletHolder.java
Date Thu, 13 Feb 2003 14:17:56 GMT
proyal      2003/02/13 06:17:56

  Modified:    sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty
                        SevakServletHolder.java
  Log:
  * Add full apache license
  * Reduce visiblity to package
  * Add SevakContext support
  * Add Initializable lifecycle support
  * Use ContainerUtil to do lifecycle processing
  
  Revision  Changes    Path
  1.3       +98 -30    avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/SevakServletHolder.java
  
  Index: SevakServletHolder.java
  ===================================================================
  RCS file: /home/cvs/avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/SevakServletHolder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SevakServletHolder.java	10 Jan 2003 00:33:32 -0000	1.2
  +++ SevakServletHolder.java	13 Feb 2003 14:17:56 -0000	1.3
  @@ -1,16 +1,61 @@
   /*
  - * Copyright (C) The Apache Software Foundation. All rights reserved.
  - *
  - * This software is published under the terms of the Apache Software License
  - * version 1.1, a copy of which has been included with this distribution in
  - * the LICENSE file.
  - */
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
  +    must not be used to endorse or promote products derived from this  software
  +    without  prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation. For more  information on the
  + Apache Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
   package org.apache.avalon.apps.sevak.blocks.jetty;
   
  -import org.mortbay.jetty.servlet.ServletHolder;
  -import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.avalon.apps.sevak.SevakContext;
  +import org.apache.avalon.framework.container.ContainerUtil;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.avalon.framework.service.ServiceException;
  +
  +import org.mortbay.jetty.servlet.ServletHolder;
   
   /**
    *
  @@ -22,50 +67,73 @@
    * @author  Paul Hammant
    * @version 1.0
    */
  -public class SevakServletHolder extends ServletHolder
  +class SevakServletHolder extends ServletHolder
   {
  -    private ServiceManager m_serviceManager;
  +    private SevakContext m_sevakContext;
   
       /**
        * Construct a Servlet Holder
  -     * @param serviceManager the service manager
  +     * @param sevakContext the context that is applied to the servlet on instantiation.
        * @param handler the handler
        * @param name the name
        * @param className the class name
        * @param forcedPath the forced path
        */
  -    public SevakServletHolder(ServiceManager serviceManager, SevakWebApplicationHandler
handler, String name, String className, String forcedPath)
  +    public SevakServletHolder( SevakContext sevakContext,
  +                               SevakWebApplicationHandler handler,
  +                               String name,
  +                               String className,
  +                               String forcedPath )
       {
           // this constructor public or protected...
  -        super(handler, name, className, forcedPath);
  -        m_serviceManager = serviceManager;
  +        super( handler, name, className, forcedPath );
  +        m_sevakContext = sevakContext;
       }
   
       /**
  -     * Create a new instance
  +     * Create a new instance of a servlet, currently applying the following lifecycle:
  +     * If a servlet is Servicable then the serviceManager is set on the servlet.
  +     * If a servlet is LogEnabled then the logger is set on the servlet.
  +     * If a servlet is Initializable then the initialize method is invoked.
        * @return the instance
        * @throws InstantiationException if a prob
        * @throws IllegalAccessException if a prob
        */
  -    public synchronized Object newInstance() throws InstantiationException, IllegalAccessException
{
  -        if(_class == null)
  -            throw new InstantiationException("No class for " + this);
  -        else {
  +    public synchronized Object newInstance() throws InstantiationException, IllegalAccessException
  +    {
  +        if( _class == null )
  +        {
  +            throw new InstantiationException( "No class for " + this );
  +        }
  +        else
  +        {
  +            final Logger logger = m_sevakContext.getLogger();
               Object instance = _class.newInstance();
  -            if (instance instanceof Serviceable) {
  -                try
  -                {
  -                    ((Serviceable) instance).service(m_serviceManager);
  -                }
  -                catch (ServiceException e)
  +
  +            try
  +            {
  +                ContainerUtil.enableLogging( instance, logger );
  +                ContainerUtil.contextualize( instance, m_sevakContext.getContext() );
  +
  +                final ServiceManager manager = m_sevakContext.getServiceManager();
  +                if( null != manager )
                   {
  -                    throw new InstantiationException("Service Exception for servlet "
  -                            + _class.getName() + ":" + e.getMessage());
  +                    ContainerUtil.service( instance, manager );
                   }
  +
  +                ContainerUtil.initialize( instance );
  +            }
  +            catch( Exception e )
  +            {
  +                final String msg = "Exception during lifecycle processing for servlet "
  +                    + _class.getName() + ":" + e.getMessage();
  +
  +                logger.error( msg, e );
  +
  +                throw new InstantiationException( msg );
               }
  +
               return instance;
           }
       }
  -
  -
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message