cvs commit: spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet AvalonJervletContext.java DefaultJervletMonitor.java JervletConfig.java JervletConfigBean.java JervletMonitor.java PicoJervletContext.java Jervlet.java JervletContext.java

Paul Hammant <[email protected]> Thu, 06 Nov 2003 12:25:47 -0800
Newsgroups gmane.comp.java.spice.cvs
Message-ID <[email protected]>
paul-h      03/11/06 12:25:47

  Modified:    sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet
                        Jervlet.java JervletContext.java
  Added:       sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet
                        AvalonJervletContext.java
                        DefaultJervletMonitor.java JervletConfig.java
                        JervletConfigBean.java JervletMonitor.java
                        PicoJervletContext.java
  Log:
  pico capability for jervlet
  
  Revision  Changes    Path
  1.2       +1 -1      spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/Jervlet.java
  
  Index: Jervlet.java
  ===================================================================
  RCS file: /cvsroot/spice/spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/Jervlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Jervlet.java	28 Oct 2003 05:07:35 -0000	1.1
  +++ Jervlet.java	6 Nov 2003 20:25:46 -0000	1.2
  @@ -75,7 +75,7 @@
        * Deploy the given Web Application
        * @param context Context for the the webapp
        * @param pathToWebAppFolder path can be a war-archive or exploded directory
  -     * @param sevakContext the context that is applied to the servlet on instantiation.
  +     * @param jervletContext the context that is applied to the servlet on instantiation.
        * @throws JervletException Thrown when context already exists
        */
       void deploy( String context, File pathToWebAppFolder, JervletContext jervletContext )
  
  
  
  1.2       +4 -32     spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/JervletContext.java
  
  Index: JervletContext.java
  ===================================================================
  RCS file: /cvsroot/spice/spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/JervletContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JervletContext.java	28 Oct 2003 05:07:35 -0000	1.1
  +++ JervletContext.java	6 Nov 2003 20:25:46 -0000	1.2
  @@ -49,44 +49,16 @@
   */
   package org.jcomponent.jervlet;
   
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.service.ServiceManager;
  +
   
   /**
    * Holder class for objects to be used when creating servlets under Jervlet
    *
  - * If a servlet is LogEnabled then the logger is set on the servlet.
  - * If a servlet is Servicable then the serviceManager is set on the servlet.
  - * If a servlet is Contextualizable then the context is set on the servlet
  - * @author Ben Hogan
  + * @author Paul Hammant
    */
  -public class JervletContext
  +public interface JervletContext
   {
  -    private ServiceManager m_serviceManager;
  -    private Logger m_logger;
  -    private Context m_context;
  -
  -    public JervletContext( Context context, ServiceManager serviceManager, Logger logger )
  -    {
  -        m_context = context;
  -        m_serviceManager = serviceManager;
  -        m_logger = logger;
  -    }
  -
  -    public ServiceManager getServiceManager()
  -    {
  -        return m_serviceManager;
  -    }
  -
  -    public Logger getLogger()
  -    {
  -        return m_logger;
  -    }
  +    Object instantiate(Class servletClass) throws InstantiationException, IllegalAccessException;
   
  -    public Context getContext()
  -    {
  -        return m_context;
  -    }
   }
   
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/AvalonJervletContext.java
  
  Index: AvalonJervletContext.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 2002,2003 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
      [email protected]
  
   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.jcomponent.jervlet;
  
  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.container.ContainerUtil;
  
  /**
   * Holder class for objects to be used when creating servlets under Jervlet
   *
   * If a servlet is LogEnabled then the logger is set on the servlet.
   * If a servlet is Servicable then the serviceManager is set on the servlet.
   * If a servlet is Contextualizable then the context is set on the servlet
   * @author Ben Hogan
   */
  public class AvalonJervletContext implements JervletContext
  {
      private ServiceManager m_serviceManager;
      private Logger m_logger;
      private Context m_context;
  
      public AvalonJervletContext( Context context, ServiceManager serviceManager, Logger logger )
      {
          m_context = context;
          m_serviceManager = serviceManager;
          m_logger = logger;
      }
  
      public ServiceManager getServiceManager()
      {
          return m_serviceManager;
      }
  
      public Logger getLogger()
      {
          return m_logger;
      }
  
      public Context getContext()
      {
          return m_context;
      }
  
      public Object instantiate(Class servletClass) throws InstantiationException, IllegalAccessException {
              final Logger logger = getLogger();
              Object instance = servletClass.newInstance();
  
              try
              {
                  ContainerUtil.enableLogging( instance, logger );
                  ContainerUtil.contextualize( instance, getContext() );
  
                  final ServiceManager manager = getServiceManager();
                  if( null != manager )
                  {
                      ContainerUtil.service( instance, manager );
                  }
  
                  ContainerUtil.initialize( instance );
              }
              catch( Exception e )
              {
                  final String msg = "Exception during lifecycle processing for servlet "
                      + servletClass.getName() + ":" + e.getMessage();
  
                  logger.error( msg, e );
  
                  throw new InstantiationException( msg );
              }
  
              return instance;
      }
  }
  
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/DefaultJervletMonitor.java
  
  Index: DefaultJervletMonitor.java
  ===================================================================
  package org.jcomponent.jervlet;
  
  public class DefaultJervletMonitor implements JervletMonitor {
  
      public void startException(Class reportingClass, String context, Exception e) throws JervletException {
          final String msg = "Unable to start '" + context + "' : " + e.getMessage();
          throw new JervletException(msg, e);
      }
  
      public void stopException(Class reportingClass, String context, Exception e) throws JervletException {
          final String msg = "Unable to stop '" + context + "' : " + e.getMessage();
          throw new JervletException(msg, e);
      }
  
      public void redeployException(Class reportingClass, String context, JervletException e) throws JervletException {
          //getLogger().error( "Exception restarting: " + context, e );
          throw e;
      }
  
      public void deployingContext(Class reportingClass, String context, String webappUrl, String hostName) {
  //        if( getLogger().isInfoEnabled() )
  //            getLogger().info( "deploying context=" + context + ", webapp="
  //                              + holder.getWebappUrl() + " to host="
  //                              + ( m_hostName == null ? "(All Hosts)" : m_hostName ) );
  
      }
  
      public void undeployException(Class reportingClass, String context, Exception e) throws JervletException {
          final String msg = "Problem stopping web application in Jetty for context '" + context + "'";
          throw new JervletException(msg, e);
      }
  
      public void deployingContextException(Class reportingClass, String context, String webappUrl, String hostName, Exception e) throws JervletException {
          final String msg = "Unable to deploy '" + context + "' : " + e.getMessage();
          throw new JervletException(msg, e);
      }
  
      public void undeployWarning(Class reportingClass, String context, String msg) {
          final String emsg = "Unable to deploy '" + context + "' Reason : " + msg;
          // do something with it ?
  
      }
  
  }
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/JervletConfig.java
  
  Index: JervletConfig.java
  ===================================================================
  package org.jcomponent.jervlet;
  
  public interface JervletConfig {
  
      String getHostName();
  
      int getPort();
  
      int getMinThreads();
  
      int getMaxThreads();
  
      boolean getExtractWarFile();
  
  }
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/JervletConfigBean.java
  
  Index: JervletConfigBean.java
  ===================================================================
  package org.jcomponent.jervlet;
  
  
  public class JervletConfigBean implements JervletConfig {
  
      /** Virtual host to bind the Jetty to.  null implies all hosts are in context. */
      private String m_hostName;
  
      private int m_port;
      private int m_minThreads;
      private int m_maxThreads;
      private boolean m_extractWebArchive;
  
      public boolean getExtractWarFile() {
          return m_extractWebArchive;
      }
  
      public void setExtractWarFile(boolean extractWebArchive) {
          this.m_extractWebArchive = extractWebArchive;
      }
  
      public int getMaxThreads() {
          return m_maxThreads;
      }
  
      public void setMaxThreads(int maxThreads) {
          this.m_maxThreads = maxThreads;
      }
  
      public int getMinThreads() {
          return m_minThreads;
      }
  
      public void setMinThreads(int minThreads) {
          this.m_minThreads = minThreads;
      }
  
      public int getPort() {
          return m_port;
      }
  
      public void setPort(int port) {
          this.m_port = port;
      }
  
      public String getHostName() {
          return m_hostName;
      }
  
      public void setHostName(String hostName) {
          this.m_hostName = hostName;
      }
  
  }
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/JervletMonitor.java
  
  Index: JervletMonitor.java
  ===================================================================
  package org.jcomponent.jervlet;
  
  public interface JervletMonitor {
      void startException(Class reportingClass, String context, Exception e) throws JervletException;
  
      void stopException(Class reportingClass, String context, Exception e) throws JervletException;
  
      void redeployException(Class reportingClass, String context, JervletException e) throws JervletException;
  
      void deployingContext(Class reportingClass, String context, String webappUrl, String hostName);
  
      void undeployException(Class reportingClass, String context, Exception e) throws JervletException;
  
      void deployingContextException(Class reportingClass, String context, String webappUrl, String hostName, Exception e) throws JervletException;
  
      void undeployWarning(Class reportingClass, String context, String msg);
  
  }
  
  
  
  1.1                  spice/sandbox/jervlet/jervlet/src/java/org/jcomponent/jervlet/PicoJervletContext.java
  
  Index: PicoJervletContext.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 2002,2003 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
      [email protected]
  
   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.jcomponent.jervlet;
  
  import org.picocontainer.MutablePicoContainer;
  import org.picocontainer.defaults.DefaultPicoContainer;
  
  /**
   * Holder class for objects to be used when creating servlets under Jervlet
   *
   * @author Paul Hammant
   */
  public class PicoJervletContext implements JervletContext
  {
      private final MutablePicoContainer parentContainer;
  
      public PicoJervletContext( MutablePicoContainer mutablePicoContainer )
      {
          this.parentContainer = mutablePicoContainer;
      }
  
      public Object instantiate(Class servletClass) throws InstantiationException, IllegalAccessException {
          MutablePicoContainer picoContainer = new DefaultPicoContainer();
          picoContainer.addParent(parentContainer);
          picoContainer.registerComponentImplementation(servletClass);
          return picoContainer.getComponentInstance(servletClass);
      }
  
  }
  
  
  
  


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/