01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.pipeline.impl;
18:
19: import org.apache.avalon.framework.activity.Disposable;
20: import org.apache.avalon.framework.component.ComponentException;
21: import org.apache.avalon.framework.parameters.ParameterException;
22: import org.apache.avalon.framework.parameters.Parameters;
23: import org.apache.cocoon.caching.Cache;
24: import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline;
25: import org.apache.cocoon.components.sax.XMLDeserializer;
26: import org.apache.cocoon.components.sax.XMLSerializer;
27:
28: /**
29: * This is the base class for all caching pipeline implementations.
30: * The pipeline can be configured with the {@link Cache} to use
31: * by specifying the <code>cache-role</code> parameter.
32: *
33: * @since 2.1
34: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35: * @version $Id: BaseCachingProcessingPipeline.java 433543 2006-08-22 06:22:54Z crossley $
36: */
37: public abstract class BaseCachingProcessingPipeline extends
38: AbstractProcessingPipeline implements Disposable {
39:
40: /** This is the Cache holding cached responses */
41: protected Cache cache;
42:
43: /** The XML Deserializer */
44: protected XMLDeserializer xmlDeserializer;
45:
46: /** The XML Serializer */
47: protected XMLSerializer xmlSerializer;
48:
49: /**
50: * Parameterizable Interface - Configuration
51: */
52: public void parameterize(Parameters params)
53: throws ParameterException {
54: super .parameterize(params);
55:
56: String cacheRole = params
57: .getParameter("cache-role", Cache.ROLE);
58: if (getLogger().isDebugEnabled()) {
59: getLogger().debug("Using cache " + cacheRole);
60: }
61:
62: try {
63: this .cache = (Cache) this .manager.lookup(cacheRole);
64: } catch (ComponentException ce) {
65: throw new ParameterException("Unable to lookup cache: "
66: + cacheRole, ce);
67: }
68: }
69:
70: /**
71: * Recyclable Interface
72: */
73: public void recycle() {
74: this .manager.release(this .xmlDeserializer);
75: this .xmlDeserializer = null;
76:
77: this .manager.release(this .xmlSerializer);
78: this .xmlSerializer = null;
79:
80: super .recycle();
81: }
82:
83: /**
84: * Disposable Interface
85: */
86: public void dispose() {
87: if (null != this.manager) {
88: this.manager.release(this.cache);
89: }
90: this.cache = null;
91: this.manager = null;
92: }
93: }
|