org.springframework.rules.closure
Interface ElementGenerator

Show UML class diagram
All Superinterfaces:
ClosureTemplate
All Known Implementing Classes:
AbstractElementGenerator, AbstractElementGeneratorWorkflow, IteratorTemplate

public interface ElementGenerator
extends ClosureTemplate

A interface to be implemented by objects which encapsulate a workflow process template that generates elements for processing. For example, a template process might produce records from a file for processing.

A user-provided closure call back is passed in on process execution and is called to insert custom processing within the template.

For example, the following code snippet demonstrates a generator that produces parsed csv records from an underlying file resource. In this case, this recordGenerator encapsulates required resource management (opening/closing resources) and the algorithm to parse / iterate over records. The results (a single parsed record) are passed to the callback for processing.

 ElementGenerator recordGenerator = new CsvRecordGenerator(new FileSystemResource(file));
 recordGenerator.run(new Block() {
        protected void handle(Object csvRecord) {
                // process each record
        }
 });
 
This is a generic equivalent to approaches used throughout The Spring Framework, including Spring's JDBC Template for processing DB query result sets. In addition to providing a common callback interface, it is intended for convenience in situations where defining a separate callback hierarchy to support a template callback approach is overkill.

Author:
Keith Donald

Method Summary
 boolean allTrue(Constraint constraint)
          Does this process produce all elements matching the given criteria?
 boolean anyTrue(Constraint constraint)
          Does this process produce an element matching the given criteria?
 ElementGenerator findAll(Constraint constraint)
          Find all elements produced by ths template that match the specified criteria.
 Object findFirst(Constraint constraint)
          Find the first element that matches the given criteria.
 Object findFirst(Constraint constraint, Object defaultIfNoneFound)
          Find the first element that matches the given criteria, return defaultIfNoneFound if none found.
 void runUntil(Closure templateCallback, Constraint constraint)
          Execute the template until the specified condition is true
 void stop()
          Stop this process after it has started.
 
Methods inherited from interface org.springframework.rules.closure.ClosureTemplate
run
 

Method Detail

anyTrue

boolean anyTrue(Constraint constraint)
Does this process produce an element matching the given criteria?

Parameters:
constraint - the criteria
Returns:
true if yes, false otherwise

allTrue

boolean allTrue(Constraint constraint)
Does this process produce all elements matching the given criteria?

Parameters:
constraint - the criteria
Returns:
true if yes, false otherwise

findFirst

Object findFirst(Constraint constraint)
Find the first element that matches the given criteria.

Parameters:
constraint - the criteria
Returns:
the first element, or null if none found.

findFirst

Object findFirst(Constraint constraint,
                 Object defaultIfNoneFound)
Find the first element that matches the given criteria, return defaultIfNoneFound if none found.

Parameters:
constraint - the constraint
defaultIfNoneFound - none found object
Returns:
the first match, or defaultIfNoneFound if no match found

findAll

ElementGenerator findAll(Constraint constraint)
Find all elements produced by ths template that match the specified criteria.

Parameters:
constraint - the criteria
Returns:
the elements

runUntil

void runUntil(Closure templateCallback,
              Constraint constraint)
Execute the template until the specified condition is true

Parameters:
templateCallback - the callback
constraint - the constraint condition

stop

void stop()
          throws IllegalStateException
Stop this process after it has started.

Throws:
IllegalStateException


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.