org.inria.ns.reflex.util.json
Interface JSONHandler

All Known Implementing Classes:
Handler

public interface JSONHandler

The methods of this interface are called by the parser when a comment, a value, or a member (a pair of name-value) have to be inserted in the structure hold in the given context. Therefore, the JSON handler is responsible of the creation of the target structure. A concrete implementation should populate JSON arrays, objects and documents with the values, members, and optionally comments if they are supported.

According to the configuration in use (available in the context), various behaviour can be considered.

Usage

Get the item to add with JSONContext.lastValue() (it will be an item built by the JSON factory in use).

Add it to the current structure JSONContext.peekStructure().

Additional methods are available to check the type of the item to add (JSONContext#lastIsXXX) and the type of the host structure (JSONContext#hostIsXXX).

With those informations and according to the configuration, an item can be added as an attribute, an element, or skipped. In this last case, the method MUST notify the parser that a structure (object or array) was skipped by returning false.

Author:
Philippe Poulard
See Also:
JSONContext, JSONFactory

Method Summary
 void addJSONComment(JSONContext context)
          Add a JSON comment to the current structure ; effects may vary according to the configuration in use.
 boolean addJSONMember(JSONContext context, QName name)
          Add a JSON member (that is to say a name/value pair) to the current structure ; effects may vary according to the configuration in use.
 boolean addJSONValue(JSONContext context)
          Add a JSON value to the current structure ; effects may vary according to the configuration in use.
 

Method Detail

addJSONComment

void addJSONComment(JSONContext context)
Add a JSON comment to the current structure ; effects may vary according to the configuration in use.

This method is called by the parser when it has read a JSON comment (which is hold by the given context).

Parameters:
context - The context that hold the parser state and structure.
See Also:
JSONFactory.newJSONComment(JSONContext, String), JSONConfiguration

addJSONMember

boolean addJSONMember(JSONContext context,
                      QName name)
Add a JSON member (that is to say a name/value pair) to the current structure ; effects may vary according to the configuration in use.

This method is called by the parser when it has read a JSON member (which is hold by the given context).

Parameters:
context - The context that hold the parser state and structure, and the value to add.
name - The name of the member, usually it is a simple wrapped string, but custom XML names can be considered.
Returns:
true to indicate to the parser that the member was effectively added to the target structure, false otherwise. This allow to skip unwanted structures safely.
See Also:
JSONFactory, JSONConfiguration

addJSONValue

boolean addJSONValue(JSONContext context)
Add a JSON value to the current structure ; effects may vary according to the configuration in use.

This method is called by the parser when it has read a JSON value (which is hold by the given context).

Parameters:
context - The context that hold the parser state and structure and the value to add.
Returns:
true to indicate to the parser that the member was effectively added to the target structure, false otherwise. This allow to skip unwanted structures safely.
See Also:
JSONFactory, JSONConfiguration