KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > ClearCacheAction


1 /*
2  * Copyright 1999-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.cocoon.acting;
17
18 import org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20 import org.apache.cocoon.caching.Cache;
21 import org.apache.cocoon.environment.Redirector;
22 import org.apache.cocoon.environment.SourceResolver;
23
24 import java.util.Map JavaDoc;
25
26 /**
27  * Simple action which ensures the cache is cleared of all
28  * cached results
29  *
30  * @author <a HREF="mailto:Michael.Melhem@managesoft.com">Michael Melhem</a>
31  * @version CVS $Id: ClearCacheAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
32  */

33 public class ClearCacheAction extends ServiceableAction implements ThreadSafe {
34
35     public Map JavaDoc act(Redirector redirector,
36                     SourceResolver resolver,
37                     Map JavaDoc objectModel,
38                     String JavaDoc src,
39                     Parameters par
40     ) throws Exception JavaDoc {
41         final String JavaDoc cacheRole = par.getParameter("cache-role", Cache.ROLE);
42         Cache cache = null;
43
44         try {
45             cache = (Cache)this.manager.lookup(cacheRole);
46             cache.clear();
47             return EMPTY_MAP;
48         } catch (Exception JavaDoc ex) {
49             if (this.getLogger().isDebugEnabled()) {
50                 getLogger().debug("Exception while trying to clear Cache with role " + cacheRole, ex);
51             }
52             return null;
53         } finally {
54             this.manager.release( cache );
55         }
56     }
57 }
58
Popular Tags