com.github.fge.jsonschema.core.processing
Class ProcessorChain<IN extends MessageProvider,OUT extends MessageProvider>

java.lang.Object
  extended by com.github.fge.jsonschema.core.processing.ProcessorChain<IN,OUT>
Type Parameters:
IN - the input type for that chain
OUT - the output type for that chain

@Immutable
public final class ProcessorChain<IN extends MessageProvider,OUT extends MessageProvider>
extends Object

A processor chain

This class allows to build a chain out of different Processor instances. Chaining two processors p1 and p2 only requires that the output of p1 be compatible with the input of p2.

The result behaves like a processor itself, so it can be used in other chains as well.

Sample usage:

     final Processor<X, Y> chain = ProcessorChain.startWith(p1)
         .chainWith(p2).chainWith(...).getProcessor();

     // input is of type X
     final Y ret = chain.process(report, X);
 

Note that all instances are immutable: each alteration of the chain returns a new chain. This, for example, will not work:

     final ProcessorChain<X, Y> chain = ProcessorChain.startWith(p1);
     chain.failOnError(); // WRONG!
     chain.getProcessor(); // Will return p1, not p1 with a stop condition
 


Method Summary
<NEWOUT extends MessageProvider>
ProcessorChain<IN,NEWOUT>
chainWith(Processor<OUT,NEWOUT> p)
          Add a processor to the chain
 ProcessorChain<IN,OUT> failOnError()
          Stop the processing chain on failure
 ProcessorChain<IN,OUT> failOnError(ProcessingMessage message)
          Stop the processing chain on failure
 Processor<IN,OUT> getProcessor()
           
static
<X extends MessageProvider,Y extends MessageProvider>
ProcessorChain<X,Y>
startWith(Processor<X,Y> p)
          Start a processing chain with a single processor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startWith

public static <X extends MessageProvider,Y extends MessageProvider> ProcessorChain<X,Y> startWith(Processor<X,Y> p)
Start a processing chain with a single processor

Type Parameters:
X - the input type
Y - the output type
Parameters:
p - the processor
Returns:
a single element processing chain
Throws:
NullPointerException - processor is null

failOnError

public ProcessorChain<IN,OUT> failOnError()
Stop the processing chain on failure

Inserting this into a chain will stop the processing chain if the previous processor ended up with an error (ie, ProcessingReport.isSuccess() returns false).

Returns:
a new chain

failOnError

public ProcessorChain<IN,OUT> failOnError(ProcessingMessage message)
Stop the processing chain on failure

Inserting this into a chain will stop the processing chain if the previous processor ended up with an error (ie, ProcessingReport.isSuccess() returns false).

Parameters:
message - the processing message to use
Returns:
a new chain
See Also:
ProcessingMessage.asException(), ProcessingMessage.setExceptionProvider(ExceptionProvider)

chainWith

public <NEWOUT extends MessageProvider> ProcessorChain<IN,NEWOUT> chainWith(Processor<OUT,NEWOUT> p)
Add a processor to the chain

Type Parameters:
NEWOUT - the return type for that new processor
Parameters:
p - the processor to add
Returns:
a new chain consisting of the previous chain with the new processor appended
Throws:
NullPointerException - processor to append is null

getProcessor

public Processor<IN,OUT> getProcessor()