package com.github.bfh.study.slb.imports.job;

import com.github.bfh.study.slb.ImportContext;
import com.github.bfh.study.slb.imports.parser.PartialXmlParser;
import com.github.bfh.study.slb.imports.SecoProvider;

import java.io.Serializable;
import javax.batch.api.chunk.ItemReader;

/**
 * parse a defined xml and get the elements back
 *
 * @author Samuel Ackermann
 */
public class XmlReader extends ReaderWriterBase implements ItemReader {

    private PartialXmlParser parser;

    @Override
    public void open(Serializable checkpoint) throws Exception {
        this.checkpoint = checkpoint;
        ImportContext context = new ImportContext(new SecoProvider());
        parser = new PartialXmlParser(context.getProcessingElements());
        parser.open("");
    }

    @Override
    public void close() throws Exception {
        parser.close();
    }

    @Override
    public Object readItem() throws Exception {
        return parser.parse();
    }

    @Override
    public Serializable checkpointInfo() throws Exception {
        return checkpoint;
    }
}

@@ -72,16 +72,24 @@
 udy.slb.
+imports.
 ImportCo
@@ -95,16 +95,16 @@
 ontext;%0A
-
 import c
@@ -164,63 +164,8 @@
 er;%0A
-import com.github.bfh.study.slb.imports.SecoProvider;%0A%0A
 impo
@@ -229,16 +229,91 @@
 mReader;
+%0Aimport javax.batch.runtime.context.JobContext;%0Aimport javax.inject.Inject;
 %0A%0A/**%0A *
@@ -505,16 +505,64 @@
 arser;%0A%0A
+    @Inject%0A    private JobContext jobContext;%0A%0A
     @Ove
@@ -707,54 +707,247 @@
  = n
-ew ImportContext(new SecoProvider());%0A        
+ull;%0A        try %7B%0A            context = (ImportContext) jobContext.getTransientUserData();%0A        %7D catch (ClassCastException e) %7B%0A            jobContext.setExitStatus(%22No import context found.%22);%0A            return;%0A        %7D%0A        //
 pars
@@ -1010,24 +1010,26 @@
 ));%0A        
+//
 parser.open(
@@ -1105,16 +1105,18 @@
         
+//
 parser.c
@@ -1200,22 +1200,28 @@
         
-return
+//Object o =
  parser.
@@ -1225,24 +1225,88 @@
 er.parse();%0A
+        //checkpoint += (Serializable) 1;%0A        return null ;%0A
     %7D%0A%0A    @

use transient user data for job context