ModeShape Distribution 3.0.0.Beta4

org.infinispan.schematic.internal.document
Class JsonReader

java.lang.Object
  extended by org.infinispan.schematic.internal.document.JsonReader

@ThreadSafe
@Immutable
public class JsonReader
extends Object

A class that reads the JSON data format and constructs an in-memory BSON representation.

This reader is capable of optionally introspecting string values to look for certain string patterns that are commonly used to represent dates. In introspection is not done by default, but when it is used it looks for the following patterns:

Note that in the date forms listed above, millisOrIso is either a long value representing the number of milliseconds since epoch or a string literal in ISO-8601 format representing a date and time.

This reader also accepts non-string values that are function calls of the form

     new functionName(parameters)
 
where parameters consists of one or more JSON values (including nested functions). If the function call cannot be parsed and executed, the string literal form of the function call is kept.

Since:
5.1

Nested Class Summary
static class JsonReader.DateValueMatcher
          The component that parses a tokenized JSON stream and attempts to evaluate literal values such as dates
static class JsonReader.Parser
          The component that parses a tokenized JSON stream.
static class JsonReader.SimpleValueMatcher
          The component that matches a string value for certain patterns.
static class JsonReader.Tokenizer
          The component that tokenizes a stream of JSON content.
static interface JsonReader.ValueMatcher
          The component that matches a string value for certain patterns.
 
Field Summary
protected static JsonReader.ValueMatcher DATE_VALUE_MATCHER
           
static boolean DEFAULT_INTROSPECT
           
protected static JsonReader.ValueMatcher SIMPLE_VALUE_MATCHER
           
protected static DocumentValueFactory VALUE_FACTORY
           
 
Constructor Summary
JsonReader()
           
 
Method Summary
static Number parseNumber(String value)
          Parse the number represented by the supplied (unquoted) JSON field value.
 Document read(InputStream stream)
          Read the JSON representation from supplied input stream and construct the Document representation, using the default character set.
 Document read(InputStream stream, boolean introspectStringValues)
          Read the JSON representation from supplied input stream and construct the Document representation, using the default character set.
 Document read(InputStream stream, Charset charset)
          Read the JSON representation from supplied input stream and construct the Document representation, using the supplied character set.
 Document read(InputStream stream, Charset charset, boolean introspectStringValues)
          Read the JSON representation from supplied input stream and construct the Document representation, using the supplied character set.
 Document read(Reader reader)
          Read the JSON representation from supplied input stream and construct the Document representation.
 Document read(Reader reader, boolean introspectStringValues)
          Read the JSON representation from supplied input stream and construct the Document representation.
 Document read(String json)
          Read the JSON representation from supplied string and construct the Document representation.
 Document read(String json, boolean introspectStringValues)
          Read the JSON representation from supplied string and construct the Document representation.
 Document read(URL url)
          Read the JSON representation from supplied URL and construct the Document representation, using the default character set.
 DocumentSequence readMultiple(InputStream stream)
          Return a DocumentSequence that can be used to pull multiple documents from the stream.
 DocumentSequence readMultiple(InputStream stream, boolean introspectStringValues)
          Return a DocumentSequence that can be used to pull multiple documents from the stream.
 DocumentSequence readMultiple(Reader reader)
          Return a DocumentSequence that can be used to pull multiple documents from the stream.
 DocumentSequence readMultiple(Reader reader, boolean introspectStringValues)
          Return a DocumentSequence that can be used to pull multiple documents from the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_FACTORY

protected static final DocumentValueFactory VALUE_FACTORY

SIMPLE_VALUE_MATCHER

protected static final JsonReader.ValueMatcher SIMPLE_VALUE_MATCHER

DATE_VALUE_MATCHER

protected static final JsonReader.ValueMatcher DATE_VALUE_MATCHER

DEFAULT_INTROSPECT

public static final boolean DEFAULT_INTROSPECT
See Also:
Constant Field Values
Constructor Detail

JsonReader

public JsonReader()
Method Detail

read

public Document read(URL url)
              throws ParsingException
Read the JSON representation from supplied URL and construct the Document representation, using the default character set.

Parameters:
url - the URL to the JSON document; may not be null and must be resolvable
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the URL

read

public Document read(InputStream stream)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation, using the default character set.

Parameters:
stream - the input stream; may not be null
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(InputStream stream,
                     Charset charset)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation, using the supplied character set.

Parameters:
stream - the input stream; may not be null
charset - the character set that should be used; may not be null
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(Reader reader)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation.

Parameters:
reader - the IO reader; may not be null
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(String json)
              throws ParsingException
Read the JSON representation from supplied string and construct the Document representation.

Parameters:
json - the JSON representation; may not be null
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(InputStream stream,
                     boolean introspectStringValues)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation, using the default character set.

Parameters:
stream - the input stream; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(InputStream stream,
                     Charset charset,
                     boolean introspectStringValues)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation, using the supplied character set.

Parameters:
stream - the input stream; may not be null
charset - the character set that should be used; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(Reader reader,
                     boolean introspectStringValues)
              throws ParsingException
Read the JSON representation from supplied input stream and construct the Document representation.

Parameters:
reader - the IO reader; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

read

public Document read(String json,
                     boolean introspectStringValues)
              throws ParsingException
Read the JSON representation from supplied string and construct the Document representation.

Parameters:
json - the JSON representation; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the in-memory Document representation
Throws:
ParsingException - if there was a problem reading from the stream

readMultiple

public DocumentSequence readMultiple(InputStream stream)
Return a DocumentSequence that can be used to pull multiple documents from the stream.

Parameters:
stream - the input stream; may not be null
Returns:
the sequence that can be used to get one or more Document instances from a single input

readMultiple

public DocumentSequence readMultiple(InputStream stream,
                                     boolean introspectStringValues)
Return a DocumentSequence that can be used to pull multiple documents from the stream.

Parameters:
stream - the input stream; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the sequence that can be used to get one or more Document instances from a single input

readMultiple

public DocumentSequence readMultiple(Reader reader)
Return a DocumentSequence that can be used to pull multiple documents from the stream.

Parameters:
reader - the IO reader; may not be null
Returns:
the sequence that can be used to get one or more Document instances from a single input

readMultiple

public DocumentSequence readMultiple(Reader reader,
                                     boolean introspectStringValues)
Return a DocumentSequence that can be used to pull multiple documents from the stream.

Parameters:
reader - the IO reader; may not be null
introspectStringValues - true if the string values should be examined for common patterns, or false otherwise
Returns:
the sequence that can be used to get one or more Document instances from a single input

parseNumber

public static Number parseNumber(String value)
Parse the number represented by the supplied (unquoted) JSON field value.

Parameters:
value - the string representation of the value
Returns:
the number, or null if the value could not be parsed

ModeShape Distribution 3.0.0.Beta4

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.