public boolean process(Environment environment) throws Exception {
this.setup(environment);
// we cache if the pipelinecachekey is available
XMLSerializer xmlSerializer = null;
try {
if (this.pipelineCacheKey != null) {
// now we have the key to get the cached object
CachedEventObject cachedObject = (CachedEventObject)this.eventCache.get(this.pipelineCacheKey);
if (cachedObject != null) {
getLogger().debug("Found cached content for '" + environment.getURI() + "'.");
Iterator validityIterator = validityObjects.keySet().iterator();
ComponentCacheKey validityKey;
boolean valid = true;
while (validityIterator.hasNext() && valid) {
validityKey = (ComponentCacheKey)validityIterator.next();
valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
if (getLogger().isDebugEnabled()) {
CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
getLogger().debug("Compared cached validity '" + cachedValidity +
"' with new validity '" + validityObjects.get(validityKey) +
"' : " + (valid ? "valid" : "changed"));
}
}
if (valid) {
getLogger().debug("Using valid cached content for '" + environment.getURI() + "'.");
// get all transformers which are not cacheable
int transformerSize = this.transformers.size();
while (this.firstNotCacheableTransformerIndex < transformerSize) {
this.notCacheableTransformers.add(this.transformers.get(this.firstNotCacheableTransformerIndex));
this.firstNotCacheableTransformerIndex++;
}
XMLDeserializer deserializer = null;
try {
deserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
// connect the pipeline:
this.producer = deserializer;
this.connectPipeline(environment,
notCacheableTransformers,
null);
// execute the pipeline:
deserializer.deserialize(cachedObject.getSAXFragment());
} catch ( ProcessingException e ) {
throw e;
} catch ( Exception e ) {
throw new ProcessingException(
"Failed to execute pipeline.",
e
);
} finally {
if (deserializer != null)
this.manager.release((Component)deserializer);
}
} else {
getLogger().debug("Cached content is invalid for '" + environment.getURI() + "'.");
// remove invalid cached object
this.eventCache.remove(this.pipelineCacheKey);
cachedObject = null;
}
}
if (cachedObject == null) {
getLogger().debug("Caching content for further requests of '" + environment.getURI() + "'.");
xmlSerializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
}
}
if (this.producer == null) {
// the content was not cached/or is invalid
this.producer = this.generator;
this.connectPipeline(environment,
this.transformers,
xmlSerializer);
// execute the pipeline:
this.generator.generate();
// did we have cacheable components?
if (xmlSerializer != null) {
this.eventCache.store(this.pipelineCacheKey,
new CachedEventObject(this.validityObjects,
xmlSerializer.getSAXFragment()));
}
}
} finally {
if (xmlSerializer != null)
this.manager.release((Component)xmlSerializer);