Announcement Announcement Module
Collapse
No announcement yet.
ValidationEventHandler via Jaxb2Marshaller via StaxEventItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ValidationEventHandler via Jaxb2Marshaller via StaxEventItemReader

    What I need is a suggestion for how to pass a List between a StaxEventItemReader and the "handleEvent(ValidationEvent event)" of a Jaxb2Marshaller. The only solution I can think of is to use a ThreadLocal (I'm using SimpleAsyncTaskExecutor). Does that seem like the best way to do this?.

    The step is in a job I configured that is reading XML via org.springframework.batch.item.xml.StaxEventItemRe ader.

    I configured the "SetUnmarshaller " method of StaxEventItemReader to unmarshall via org.springframework.oxm.jaxb.Jaxb2Marshaller, and I configured that Jaxb2Marshaller to use an implementation of the javax.xml.bind.ValidationEventHandler interface that I wrote.

    When there is an XML schema violation in an xml input fragment, the "handleEvent(ValidationEvent event)" method is invoked by org.springframework.oxm.jaxb.Jaxb2Marshaller.

    Within that "handleEvent(...)" I accumulate information about the XML errors into a List.

    I want to make that List accessible to the StaxEventItemReader so that the StaxEventItemReader can put the List into the Execution context.

    Is a ThreadLocal the best way to do this?
    Last edited by RobertGloverJr; Jan 9th, 2010, 03:54 PM.

  • #2
    ThreadLocal is a last resort I would say. When you say the StaxEventItemReader is going to stash the list in the ExecutionContext, I assume you mean your custom item reader is going to do that? Can't you just inject the ValidationEventHandler (or a common component between the two) into the reader?

    Comment


    • #3
      Originally posted by Dave Syer View Post
      Can't you just inject the ValidationEventHandler (or a common component between the two) into the reader?
      Wow! I never thought of the approach you suggested. It sounds perfect. I will try doing it that way.

      I wonder though if my plan to use "scope=step" on both "myCustomReader" as well as on "myCustCommonComponent"
      is the right way to use the "step" scope. (see proposed code example below)

      Code:
      <bean id="myCustomReader" scope="step"
      class="foo.MyCustomReader">
          <property name="myCustCommonComponent"  ref="myCustCommonComponent" />
          ...other configs...
      </bean>
      
      <bean id="myCustCommonComponent" class="foo.MyCustCommonComponent" scope="step"
          ... configs ....
      </bean>

      Comment


      • #4
        Anything stateful should be step-scoped. You can do that by explicitly declaring scope="step" as in your example, or by declaring a component as an inner bean of a step-scoped component which is not relevant here.

        Comment

        Working...
        X