com.github.fge.jsonschema.core.report
Class ProcessingMessage

java.lang.Object
  extended by com.github.fge.jsonschema.core.report.ProcessingMessage
All Implemented Interfaces:
AsJson

@NotThreadSafe
public final class ProcessingMessage
extends Object
implements AsJson

One processing message

Internally, a processing message has a Map whose keys are strings and values are JsonNodes. Note that all methods altering the message contents accept null: in this case, the value for that key will be a NullNode. If you submit null keys, the whole value will be ignored.

Some methods to append contents to a message accept arbitrary inputs: in this case, it is your responsibility to ensure that these inputs have a correct implementation of Object.toString().

You can use formatted strings as messages using the capabilities of Formatter; in order to pass arguments to the different placeholders, you will then use the .putArgument() methods instead of .put(). Arguments will appear in the order you submit them.

Please note that if you do:

     message.setMessage("foo %s").putArgument("something", "here")
         .setMessage("another %s message")
 

then the argument list is cleared.

You can alter the behaviour of a processing message in two ways: its log level and its ExceptionProvider (used in asException().

All mutation methods of a message return this.


Constructor Summary
ProcessingMessage()
          Constructor
 
Method Summary
 ProcessingException asException()
          Build an exception out of this message
 JsonNode asJson()
          Return a JSON representation of this object
 LogLevel getLogLevel()
          Get the log level for this message
 String getMessage()
          Get the main message
 ProcessingMessage put(String key, AsJson asJson)
          Add a key/value pair to this message
 ProcessingMessage put(String key, int value)
          Add a key/value pair to this message
<T> ProcessingMessage
put(String key, Iterable<T> values)
          Add a key/value pair to this message, where the value is a collection of items
 ProcessingMessage put(String key, JsonNode value)
          Add a key/value pair to this message
 ProcessingMessage put(String key, String value)
          Add a key/value pair to this message
<T> ProcessingMessage
put(String key, T value)
          Add a key/value pair to this message
 ProcessingMessage putArgument(String key, AsJson asJson)
          Add a key/value pair to this message, which is also a formatter argument
 ProcessingMessage putArgument(String key, int value)
          Add a key/value pair to this message, which is also a formatter argument
<T> ProcessingMessage
putArgument(String key, Iterable<T> values)
          Add a key/value pair to this message, which is also a formatter argument
 ProcessingMessage putArgument(String key, JsonNode value)
          Add a key/value pair to this message, which is also a formatter argument
<T> ProcessingMessage
putArgument(String key, T value)
          Add a key/value pair to this message, which is also a formatter argument
 ProcessingMessage setExceptionProvider(ExceptionProvider exceptionProvider)
          Set the exception provider for that particular message
 ProcessingMessage setLogLevel(LogLevel level)
          Set the log level for this message
 ProcessingMessage setMessage(String message)
          Set the main message
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProcessingMessage

public ProcessingMessage()
Constructor

By default, a message is generated with a log level of LogLevel.INFO.

Method Detail

getMessage

public String getMessage()
Get the main message

Returns:
the main message as a string

getLogLevel

public LogLevel getLogLevel()
Get the log level for this message

Returns:
the log level

setMessage

public ProcessingMessage setMessage(String message)
Set the main message

Parameters:
message - the message as a string
Returns:
this

setLogLevel

public ProcessingMessage setLogLevel(LogLevel level)
Set the log level for this message

Parameters:
level - the log level
Returns:
this
Throws:
NullPointerException - log level is null

setExceptionProvider

public ProcessingMessage setExceptionProvider(ExceptionProvider exceptionProvider)
Set the exception provider for that particular message

Parameters:
exceptionProvider - the exception provider
Returns:
this
Throws:
NullPointerException - exception provider is null

put

public ProcessingMessage put(String key,
                             JsonNode value)
Add a key/value pair to this message

This is the main method. All other put methods call this one.

Note that if the key is null, the content is ignored.

Parameters:
key - the key
value - the value as a JsonNode
Returns:
this

putArgument

public ProcessingMessage putArgument(String key,
                                     JsonNode value)
Add a key/value pair to this message, which is also a formatter argument

Parameters:
key - the key
value - the value
Returns:
this

put

public ProcessingMessage put(String key,
                             AsJson asJson)
Add a key/value pair to this message

Parameters:
key - the key
asJson - the value, which implements AsJson
Returns:
this

putArgument

public ProcessingMessage putArgument(String key,
                                     AsJson asJson)
Add a key/value pair to this message, which is also a formatter argument

Parameters:
key - the key
asJson - the value
Returns:
this

put

public ProcessingMessage put(String key,
                             String value)
Add a key/value pair to this message

Parameters:
key - the key
value - the value
Returns:
this

put

public ProcessingMessage put(String key,
                             int value)
Add a key/value pair to this message

Parameters:
key - the key
value - the value as an integer
Returns:
this

putArgument

public ProcessingMessage putArgument(String key,
                                     int value)
Add a key/value pair to this message, which is also a formatter argument

Parameters:
key - the key
value - the value
Returns:
this

put

public <T> ProcessingMessage put(String key,
                                 T value)
Add a key/value pair to this message

Ensure that toString() is correctly implemented.

Type Parameters:
T - the type of the value
Parameters:
key - the key
value - the value
Returns:
this

putArgument

public <T> ProcessingMessage putArgument(String key,
                                         T value)
Add a key/value pair to this message, which is also a formatter argument

Type Parameters:
T - the type of the value
Parameters:
key - the key
value - the value
Returns:
this

put

public <T> ProcessingMessage put(String key,
                                 Iterable<T> values)
Add a key/value pair to this message, where the value is a collection of items

This will put all values (again, using toString() of the collection into an array.

Type Parameters:
T - the element type of the collection
Parameters:
key - the key
values - the collection of values
Returns:
this

putArgument

public <T> ProcessingMessage putArgument(String key,
                                         Iterable<T> values)
Add a key/value pair to this message, which is also a formatter argument

Note that the collection will not be "exploded" into its individual arguments.

Type Parameters:
T - type of values
Parameters:
key - the key
values - the collection of values
Returns:
this

asJson

public JsonNode asJson()
Description copied from interface: AsJson
Return a JSON representation of this object

Specified by:
asJson in interface AsJson
Returns:
a JsonNode

asException

public ProcessingException asException()
Build an exception out of this message

This uses the ExceptionProvider built into the message and invokes ExceptionProvider.doException(ProcessingMessage) with this as an argument.

Returns:
an exception
See Also:
setExceptionProvider(ExceptionProvider)

toString

public String toString()
Overrides:
toString in class Object