1 package com.kodexa.client.pipeline; 2 3 import com.kodexa.client.Document; 4 import com.kodexa.client.KodexaException; 5 import com.kodexa.client.steps.PipelineStep; 6 7 public class ClassBasedStep implements PipelineStep, OptionDrivenStep { 8 9 private final Class stepClass; 10 private Options options; 11 12 public ClassBasedStep(Class stepClass) { 13 this.stepClass = stepClass; 14 } 15 16 @Override 17 public Document../../../../com/kodexa/client/Document.html#Document">Document process(Document document, PipelineContext context) { 18 19 Object classInstance = null; 20 try { 21 classInstance = this.stepClass.newInstance(); 22 if (classInstance instanceof OptionDrivenStep) { 23 ((OptionDrivenStep) classInstance).setOptions(this.options); 24 } 25 if (classInstance instanceof PipelineStep) { 26 return ((PipelineStep) classInstance).process(document, context); 27 } else { 28 throw new KodexaException("Class is not an instance of PipelineStep?"); 29 } 30 } catch (Exception e) { 31 throw new KodexaException("Unable to create instance of class for step", e); 32 } 33 34 35 } 36 37 @Override 38 public String getName() { 39 return "Step for class " + stepClass.getName(); 40 } 41 42 @Override 43 public void setOptions(Options options) { 44 this.options = options; 45 } 46 }