ExpandedName element,
Attributes attributes) throws SAXException {
XMLPipelineContext context = dynamicProcess.getPipelineContext();
EndElementAction action = EndElementAction.DO_NOTHING;
final CacheProcessConfiguration cpc =
(CacheProcessConfiguration) context.getPipelineConfiguration().
retrieveConfiguration(CacheProcessConfiguration.class);
final String cacheName = attributes.getValue("name");
final String cacheKeyString = attributes.getValue("key");
// set max wait time
final Period maxWaitTime = calculateMaxWaitTime(attributes.getValue("max-wait-time"));
// set the expiry mode
final String expiryMode = attributes.getValue("expiry-mode");
final boolean fixedExpiryMode;
if (expiryMode == null || expiryMode.length() == 0) {
// get the global expiry mode
fixedExpiryMode = cpc.isFixedExpiryMode();
} else {
fixedExpiryMode = !"auto".equals(expiryMode);
}
if (cacheName == null || cacheName.length() == 0) {
forwardError(dynamicProcess, "Cache name must be specified");
}
final Cache cache = cpc.getCache(cacheName);
if (cache != null) {
if (cacheKeyString != null) {
// <cache name="cacheName" key="cacheKey">...
// cacheInfo element is not expected
// <cacheBody>? is optional
// Need to populate the cache by doing the OperationProcess
// at least once.
CacheBodyOperationProcess operation =
new CacheBodyOperationProcess();
final CacheControl cacheControl = new CacheControl();
cacheControl.setTimeToLive(cpc.getDefaultTimeToLive(cacheName));
operation.setCacheControl(cacheControl);
operation.setCacheName(cacheName);
operation.setCache(cache);
CacheKey cacheKey = new CacheKey();
cacheKey.addKey(cacheKeyString);
operation.setCacheKey(cacheKey);
XMLPipeline pipeline = dynamicProcess.getPipeline();
operation.setPipeline(pipeline);
operation.setFixedExpiryMode(fixedExpiryMode);
operation.setMaxWaitTime(maxWaitTime);
try {
CacheBodyOperationProcessState state =
operation.initializeProcessState();
// If there is a cached recorder to playback from
// then we want to suppress all of the content.
if (state == CacheBodyOperationProcessState.
PLAYBACK_AND_SUPPRESS) {
// supress all content
context.getFlowControlManager().
exitCurrentElement();
}
dynamicProcess.addProcess(operation);
action = new EndElementAction() {
public void doAction(DynamicProcess dynamicProcess)
throws SAXException {
// Remove the process from the head, assume
// that it is the one that we added,
// should probably check.
dynamicProcess.removeProcess();
}
};
} catch (SAXException exc) {
forwardFatalError(dynamicProcess, "A problem was" +
" encountered starting the caching process.");
}
} else {
CacheProperties properties = new CacheProperties();
properties.setCacheName(cacheName);
properties.setFixedExpiryMode(fixedExpiryMode);
properties.setMaxWaitTime(maxWaitTime);
context.pushObject(properties, false);
action = new EndElementAction() {
public void doAction(DynamicProcess dynamicProcess)
throws SAXException {
XMLPipelineContext context = dynamicProcess.
getPipelineContext();