I'm doing some work with Spring Batch (2.x M3) and had questions regarding the Tasklet interface. Within my implementation of Tasklet, I'd like to get one of the job parameters. The interface for Tasklet defines:
public void execute(StepContribution contrib, AttributeAccessor attrs);
It turns out that even when specifying timePeriod=20081220 from the command line (using CommandLineJobRunner) the result of attrs.attributeNames() is empty. After stepping through this with a debugger I found that attrs is really an instance of StepContext with a getJobParameters() method which makes sense. I'm now casting attrs to StepContext (after checking instanceof to guard myself against changes in Batch and failing the step if it's different) but this is ugly.
Is AttributeAccessor really the proper definition for Tasklet? It seems to me that Tasklets would expect easy access to context information and that there's actually very little gain for this far an abstraction in the interface. I could see attrs being defined as something in the middle, like an interface that is used to represent all context information (i.e. for job context, step context, tasklet context, execution context, etc.).
The way it stands now, there's no access to job parameters without a cast which just seems wrong.