org.inria.ns.reflex.util.json
Class JSONConfiguration

java.lang.Object
  extended by org.inria.ns.reflex.util.json.JSONConfiguration
Direct Known Subclasses:
Configuration

public class JSONConfiguration
extends Object

Embeds the behaviour of the JSON parser regarding the conformance to JSON (see section 4 in RFC 4627) and convenient options.

Author:
Philippe Poulard

Constructor Summary
JSONConfiguration()
           
 
Method Summary
 boolean areCommentsEnabled()
          Indicates whether the comments are enabled or not.
 boolean areCommentsIgnored()
          Indicates whether the comments are ignored or not.
 boolean areNamesUnique()
          Indicates whether the parser have to check names uniqueness or not.
 boolean areStringNamesStrict()
          Indicates whether the parser can process the name of objects as unquoted strings (not strict) or not (strict).
 JSONConfiguration disableComments()
          Indicates to the parser that the comments are disabled.
 JSONConfiguration enableComments(boolean ignore)
          Indicates to the parser that the comments are enabled.
 boolean hasToTrackPosition()
          Indicates whether the parser has to track informations about the position.
 boolean isAllowingMissingValues()
          Indicates whether the parser has to be tolerant regarding missing values that are expected.
 boolean isRootStrict()
          Indicates whether the parser can process any item on the root or only a single array or object.
 JSONConfiguration setAllowingMissingValues(boolean allowMissingValues)
          Indicates whether the parser has to be tolerant regarding missing values that are expected.
 JSONConfiguration setNamesUniqueness(boolean uniqueness)
          Indicates to the parser whether the names of object items must be unique within the host object or can appear several times.
 JSONConfiguration setRootStrictness(boolean strictness)
          Indicates to the parser whether the root can be any values or must be a single object or array.
 JSONConfiguration setStringNamesStrictness(boolean strictness)
          Indicates to the parser whether the name of object items can be unquoted strings (not strict) or must be quoted strings (strict).
 JSONConfiguration setTrackability(boolean trackability)
          Indicates whether the parser has to track informations about the position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONConfiguration

public JSONConfiguration()
Method Detail

enableComments

public JSONConfiguration enableComments(boolean ignore)
Indicates to the parser that the comments are enabled. If the parser encounters a comment, it will be processed safely.

Parameters:
ignore - Indicates whether or not the comments have to be notified to the handler.
Returns:
This, to allow chaining settings.
See Also:
JSONFactory#comment(String)

disableComments

public JSONConfiguration disableComments()
Indicates to the parser that the comments are disabled. If the parser encounters a comment, an error will be reported.

Returns:
This, to allow chaining settings.
See Also:
JSONException

areCommentsEnabled

public boolean areCommentsEnabled()
Indicates whether the comments are enabled or not.

Default is false.

Returns:
true if the parser have to process comments safely, false if the parser have to report an error.
See Also:
areCommentsIgnored(), JSONFactory#comment(String)

areCommentsIgnored

public boolean areCommentsIgnored()
Indicates whether the comments are ignored or not. This has sense only if comments are enabled.

Default is true.

Returns:
true if the parser have to process comments safely, false if the parser have to ignore them.
See Also:
areCommentsEnabled()(), JSONFactory#comment(String)

setStringNamesStrictness

public JSONConfiguration setStringNamesStrictness(boolean strictness)
Indicates to the parser whether the name of object items can be unquoted strings (not strict) or must be quoted strings (strict).

If the names have to be quoted strings and the parser encounter unquoted strings, an error will be reported.

Parameters:
strictness - true if the string names have to be quoted, false otherwise.
Returns:
This, to allow chaining settings.
See Also:
JSONFactory#startItem(String, boolean)

areStringNamesStrict

public boolean areStringNamesStrict()
Indicates whether the parser can process the name of objects as unquoted strings (not strict) or not (strict).

Default is true.

Returns:
true if the names must be quoted, false otherwise.

setNamesUniqueness

public JSONConfiguration setNamesUniqueness(boolean uniqueness)
Indicates to the parser whether the names of object items must be unique within the host object or can appear several times.

If the names must be unique and the parser encounter several identical names, an error will be reported.

Parameters:
uniqueness - true if the string names have to be unique, false otherwise.
Returns:
This, to allow chaining settings.
See Also:
JSONFactory#startItem(String, boolean)

areNamesUnique

public boolean areNamesUnique()
Indicates whether the parser have to check names uniqueness or not.

Default is false.

Returns:
true if the names must be unique, false otherwise.

setRootStrictness

public JSONConfiguration setRootStrictness(boolean strictness)
Indicates to the parser whether the root can be any values or must be a single object or array. (see section 2 in RFC 4627)

If the root value is neither an array not an object, or if there are several values on the root, and that the parser is configured to be strict, an error will be reported.

Parameters:
strictness - true if the first value must be a single object or array, false otherwise.
Returns:
This, to allow chaining settings.

isRootStrict

public boolean isRootStrict()
Indicates whether the parser can process any item on the root or only a single array or object.

Default is true.

Returns:
true if the root must be a single JSON array or JSON object, false otherwise.

setTrackability

public JSONConfiguration setTrackability(boolean trackability)
Indicates whether the parser has to track informations about the position.

Parameters:
trackability - true to indicate to the parser that it has to track informations about the position of the characters read in the source, false otherwise.
Returns:
This, to allow chaining settings.

hasToTrackPosition

public boolean hasToTrackPosition()
Indicates whether the parser has to track informations about the position.

Useful for locating errors.

Default is false.

Returns:
true if the position have to be tracked, false otherwise.

setAllowingMissingValues

public JSONConfiguration setAllowingMissingValues(boolean allowMissingValues)
Indicates whether the parser has to be tolerant regarding missing values that are expected.

Parameters:
allowMissingValues - true to indicate to the parser that it has to be tolerant regarding missing values false if it has to raise an error.
Returns:
This, to allow chaining settings.

isAllowingMissingValues

public boolean isAllowingMissingValues()
Indicates whether the parser has to be tolerant regarding missing values that are expected. For example, a comma after a value in an array implies the presence of a next value.

Default is false.

Returns:
true if missing values are accepted (and discarded) if missing values are rejected.