jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/config/plugins JCSStrutsPlugin.java
Date Wed, 28 Apr 2004 03:59:58 GMT
asmuts      2004/04/27 20:59:58

  Added:       src/java/org/apache/jcs/config/plugins JCSStrutsPlugin.java
  Log:
  Added a simple plugin for struts.  It might be better to put plugins elsewhere, but this
will do.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-jcs/src/java/org/apache/jcs/config/plugins/JCSStrutsPlugin.java
  
  Index: JCSStrutsPlugin.java
  ===================================================================
  package org.apache.jcs.config.plugins;
  
  /*
   * Copyright 2001-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.
   */
  
  
  import javax.servlet.ServletException;
  
  import org.apache.jcs.JCS;
  import org.apache.jcs.engine.control.CompositeCacheManager;
  
  import org.apache.struts.action.ActionServlet;
  import org.apache.struts.action.PlugIn;
  import org.apache.struts.config.ModuleConfig;
  
  /**
   *   This plugin provides a simple way to integrate with Struts.
   *   It allows you to specify the configuration file for JCS in
   *   the struts-config.xml file.
   *   JCS will initialize and be destroyed at applicatiohn shutdown.
   *
   *   Add these lines to your struts-config.xml
   *
   *   <plug-in className="org.apache.jcs.config.plugins.JCSStrutsPlugin">
   *    <set-property property="config-file-name" value="cache.ccf" />
   *   </plug-in>
   *
   *
   */
  public class JCSStrutsPlugin implements PlugIn
  {
  
    private static CompositeCacheManager cacheMgr;
  
    /**
     * Initialize JCS with config-file-name param.
     * If no file is specified, cache.ccf will be used.
     *
     * @param servlet ActionServlet
     * @param config ModuleConfig
     * @throws ServletException
     */
    public void init( ActionServlet servlet, ModuleConfig config )
      throws ServletException
    {
  
      String configFileName = servlet.getInitParameter( "config-file-name" );
      if ( configFileName == null )
      {
        configFileName = "cache.ccf";
      }
  
      if ( cacheMgr == null )
      {
          if ( configFileName == null )
          {
              cacheMgr = CompositeCacheManager.getInstance();
          }
          else
          {
              cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
  
              cacheMgr.configure( configFileName );
          }
      }
  
    }
  
    /**
     * Destroys all the regions.
     */
    public void destroy()
    {
      cacheMgr.release();
    }
  
  }
  
  
  

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


Mime
View raw message