// Get a new event recorder to be populated with the required
// events. This is needed because we only want to preprocess
// the events once, on first use of this value, in DEFERRED mode,
// thereafter simply replaying these preprocessed events
XMLPipelineFactory factory = context.getPipelineFactory();
PipelineRecorder processedEventRecorder =
factory.createPipelineRecorder();
processedEventRecorder.startRecording(target);
// The following process collects the preprocessed events
// without permitting the events to be replayed to the rest
// of the pipeline. This allows the preprocessing to be
// performed before checking the complexity of the SAX
// events
XMLProcess process = processedEventRecorder.getRecordingProcess();
// Make sure that the pipeline will direct all preprocessed
// SAX events to the new event recorder
target.addHeadProcess(process);
// This will cause the original event recorder to send the
// original SAX events to the target pipeline which will
// then preprocess them (we assume) and send them to the
// event collection process
try {
PipelinePlayer player = recording.createPlayer();
player.play(target.getPipelineProcess());
recording = processedEventRecorder.stopRecording();
} finally {
// Must always remove the collection process so that the
// pipeline isn't messed up
target.removeHeadProcess();
}