001    /*
002     * Copyright 2001-2004 The Apache Software Foundation
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.commons.cache.tagext;
017    
018    import javax.servlet.jsp.JspTagException;
019    import javax.servlet.jsp.JspException;
020    import javax.servlet.jsp.tagext.TagSupport;
021    import java.io.Serializable;
022    
023    /**
024     * tk.
025     * @version $Id: ClearCacheTag.java 155435 2005-02-26 13:17:27Z dirkv $
026     * @author Rodney Waldhoff
027     */
028    public class ClearCacheTag extends TagSupport {
029    
030      protected Serializable _key = null;
031      protected Serializable _group = null;
032      protected String _name = null;
033    
034      public void setName(String name) {
035         _name = name;
036      }
037    
038      public void setKey(String key) {
039        _key = key;
040      }
041    
042    // weblogic reflection doesn't work very well
043    /*
044      public void setKey(Serializable key) {
045        _key = key;
046      }
047    */
048      public void setGroup(String group) {
049        _group = group;
050      }
051    
052    // weblogic reflection doesn't work very well
053    /*
054      public void setGroup(Serializable group) {
055        _group = group;
056      }
057    */
058      public ClearCacheTag() {
059        _group = null;
060        _key = null;
061      }
062    
063      public int doStartTag() {
064        return SKIP_BODY;
065      }
066    
067      public int doEndTag() throws JspException {
068        if(null != _key) {
069          CacheTag.getCache(_name).clear(_key);
070        } else if(null != _group) {
071          CacheTag.getCache(_name).clearGroup(_group);
072        } else {
073          CacheTag.getCache(_name).clear();
074        }
075        return EVAL_PAGE;
076      }
077    
078      public void release() {
079        _group = null;
080        _key = null;
081        _name = null;
082      }
083    }