File Source: CacheInfo.java

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  
    19  package org.apache.roller.weblogger.ui.struts2.admin;
    20  
    21  import java.util.Collections;
    22  import java.util.Map;
    23  import org.apache.commons.logging.Log;
    24  import org.apache.commons.logging.LogFactory;
    25  import org.apache.roller.weblogger.ui.struts2.util.UIAction;
    26  import org.apache.roller.weblogger.util.cache.CacheManager;
    27  
    28  
    29  /**
    30   * Action for displaying rendering cache info.
    31   */
    32  public class CacheInfo extends UIAction {
    33      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.ui.struts2.admin.CacheInfo__static_init
              * 
              *  Postconditions:
              *    init'ed(log)
              */
    34      private static Log log = LogFactory.getLog(CacheInfo.class);
    35      
    36      // map of stats to display
    37      private Map stats = Collections.EMPTY_MAP;
    38      
    39      // cache which we would clear when clear() is called
    40      private String cache = null;
    41      
    42      
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.ui.struts2.admin.CacheInfo()
              * 
              *  Presumptions:
              *    init'ed(java.util.Collections.EMPTY_MAP)
              * 
              *  Postconditions:
              *    this.actionName == &"cacheInfo"
              *    this.cache == null
              *    this.desiredMenu == &"admin"
              *    this.pageTitle == &"cacheInfo.title"
              *    this.stats == java.util.Collections.EMPTY_MAP
              *    (soft) init'ed(this.stats)
              */
    43      public CacheInfo() {
    44          this.actionName = "cacheInfo";
    45          this.desiredMenu = "admin";
    46          this.pageTitle = "cacheInfo.title";
    47      }
    48      
    49      
    50      public String requiredUserRole() {
                 /* 
    P/P           *  Method: String requiredUserRole()
                  * 
                  *  Postconditions:
                  *    return_value == &"admin"
                  */
    51          return "admin";
    52      }
    53      
    54      public boolean isWeblogRequired() {
                 /* 
    P/P           *  Method: bool isWeblogRequired()
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
    55          return false;
    56      }
    57      
    58      
    59      public void myPrepare() {
                 /* 
    P/P           *  Method: void myPrepare()
                  * 
                  *  Postconditions:
                  *    init'ed(this.stats)
                  */
    60          Map cacheStats = CacheManager.getStats();
    61          setStats(cacheStats);
    62      }
    63      
    64      
    65      public String execute() {
                 /* 
    P/P           *  Method: String execute()
                  * 
                  *  Postconditions:
                  *    return_value == &"success"
                  */
    66          return SUCCESS;
    67      }
    68  
    69      
    70      /**
    71       * clear action.
    72       *
    73       * this is triggered when someone has indicated that they want to clear
    74       * one or all of the caches.
    75       */
    76      public String clear() {
    77          
    78          // see if a specific cache was specified
                 /* 
    P/P           *  Method: String clear()
                  * 
                  *  Preconditions:
                  *    init'ed(this.cache)
                  * 
                  *  Postconditions:
                  *    return_value == &"success"
                  *    init'ed(this.stats)
                  * 
                  *  Test Vectors:
                  *    this.cache: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:length(...)@80: {0}, {1..232-1}
                  */
    79          String handlerClass = getCache();
    80          if(handlerClass != null && handlerClass.length() > 0) {
    81              CacheManager.clear(handlerClass);
    82          } else {
    83              CacheManager.clear();
    84          }
    85          
    86          // update stats after clear
    87          myPrepare();
    88          
    89          return SUCCESS;
    90      }
    91  
    92      
    93      public Map getStats() {
                 /* 
    P/P           *  Method: Map getStats()
                  * 
                  *  Preconditions:
                  *    init'ed(this.stats)
                  * 
                  *  Postconditions:
                  *    return_value == this.stats
                  *    init'ed(return_value)
                  */
    94          return stats;
    95      }
    96  
    97      public void setStats(Map stats) {
                 /* 
    P/P           *  Method: void setStats(Map)
                  * 
                  *  Postconditions:
                  *    this.stats == stats
                  *    init'ed(this.stats)
                  */
    98          this.stats = stats;
    99      }
   100  
   101      public String getCache() {
                 /* 
    P/P           *  Method: String getCache()
                  * 
                  *  Preconditions:
                  *    init'ed(this.cache)
                  * 
                  *  Postconditions:
                  *    return_value == this.cache
                  *    init'ed(return_value)
                  */
   102          return cache;
   103      }
   104  
   105      public void setCache(String cache) {
                 /* 
    P/P           *  Method: void setCache(String)
                  * 
                  *  Postconditions:
                  *    this.cache == cache
                  *    init'ed(this.cache)
                  */
   106          this.cache = cache;
   107      }
   108  
   109  }








SofCheck Inspector Build Version : 2.18479
CacheInfo.java 2009-Jan-02 14:25:08
CacheInfo.class 2009-Sep-04 03:12:45