KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > pipeline > impl > BaseCachingProcessingPipeline


1 /*
2  * Copyright 1999-2005 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.components.pipeline.impl;
17
18 import org.apache.avalon.framework.activity.Disposable;
19 import org.apache.avalon.framework.component.ComponentException;
20 import org.apache.avalon.framework.parameters.ParameterException;
21 import org.apache.avalon.framework.parameters.Parameters;
22 import org.apache.cocoon.caching.Cache;
23 import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline;
24 import org.apache.cocoon.components.sax.XMLDeserializer;
25 import org.apache.cocoon.components.sax.XMLSerializer;
26
27 /**
28  * This is the base class for all caching pipeline implementations.
29  * The pipeline can be configured with the {@link Cache} to use
30  * by specifying the <code>cache-role</code> parameter.
31  *
32  * @since 2.1
33  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
34  * @version $Id: BaseCachingProcessingPipeline.java 157159 2005-03-11 21:13:35Z vgritsenko $
35  */

36 public abstract class BaseCachingProcessingPipeline extends AbstractProcessingPipeline
37                                                     implements Disposable {
38
39     /** This is the Cache holding cached responses */
40     protected Cache cache;
41
42     /** The XML Deserializer */
43     protected XMLDeserializer xmlDeserializer;
44
45     /** The XML Serializer */
46     protected XMLSerializer xmlSerializer;
47
48     /**
49      * Parameterizable Interface - Configuration
50      */

51     public void parameterize(Parameters params)
52     throws ParameterException {
53         super.parameterize(params);
54
55         String JavaDoc cacheRole = params.getParameter("cache-role", Cache.ROLE);
56         if (getLogger().isDebugEnabled()) {
57             getLogger().debug("Using cache " + cacheRole);
58         }
59
60         try {
61             this.cache = (Cache) this.manager.lookup(cacheRole);
62         } catch (ComponentException ce) {
63             throw new ParameterException("Unable to lookup cache: " + cacheRole, ce);
64         }
65     }
66
67     /**
68      * Recyclable Interface
69      */

70     public void recycle() {
71         this.manager.release(this.xmlDeserializer);
72         this.xmlDeserializer = null;
73
74         this.manager.release(this.xmlSerializer);
75         this.xmlSerializer = null;
76
77         super.recycle();
78     }
79
80     /**
81      * Disposable Interface
82      */

83     public void dispose() {
84         if (null != this.manager) {
85             this.manager.release(this.cache);
86         }
87         this.cache = null;
88         this.manager = null;
89     }
90 }
91
Popular Tags