View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not 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.
15   */
16  package org.apache.commons.cache.tagext;
17  
18  import javax.servlet.jsp.JspTagException;
19  import javax.servlet.jsp.JspException;
20  import javax.servlet.jsp.tagext.TagSupport;
21  import java.io.Serializable;
22  
23  /**
24   * tk.
25   * @version $Id: ClearCacheTag.java 155435 2005-02-26 13:17:27Z dirkv $
26   * @author Rodney Waldhoff
27   */
28  public class ClearCacheTag extends TagSupport {
29  
30    protected Serializable _key = null;
31    protected Serializable _group = null;
32    protected String _name = null;
33  
34    public void setName(String name) {
35       _name = name;
36    }
37  
38    public void setKey(String key) {
39      _key = key;
40    }
41  
42  // weblogic reflection doesn't work very well
43  /*
44    public void setKey(Serializable key) {
45      _key = key;
46    }
47  */
48    public void setGroup(String group) {
49      _group = group;
50    }
51  
52  // weblogic reflection doesn't work very well
53  /*
54    public void setGroup(Serializable group) {
55      _group = group;
56    }
57  */
58    public ClearCacheTag() {
59      _group = null;
60      _key = null;
61    }
62  
63    public int doStartTag() {
64      return SKIP_BODY;
65    }
66  
67    public int doEndTag() throws JspException {
68      if(null != _key) {
69        CacheTag.getCache(_name).clear(_key);
70      } else if(null != _group) {
71        CacheTag.getCache(_name).clearGroup(_group);
72      } else {
73        CacheTag.getCache(_name).clear();
74      }
75      return EVAL_PAGE;
76    }
77  
78    public void release() {
79      _group = null;
80      _key = null;
81      _name = null;
82    }
83  }