spark.data.io
Class SONReader

java.lang.Object
  extended by spark.data.io.SONReader
All Implemented Interfaces:
SparkReader

public class SONReader
extends java.lang.Object
implements SparkReader

This is a concrete implementation of SparkReader that will read text sources in SON formation. SON format is just like JSON except that a class name can precede objects such as "Point{ x:17, y:45 }". The translation between the class name and the actual Java class to be created is determined by the TypeFactory that is used with the reader.

Author:
olsen

Constructor Summary
SONReader()
          This creates a new SONReader.
SONReader(java.lang.String input)
          This creates a new SONReader.
SONReader(java.lang.String[] typePackageList)
          This creates a new SONReader.
SONReader(java.lang.String[] typePackageList, java.io.InputStream input)
          This creates a new SONReader.
SONReader(java.lang.String[] typePackageList, java.lang.String input)
          This creates a new SONReader.
 
Method Summary
 TypeFactory getTypeFactory()
          This will return the TypeFactory being used.
 SV read()
          This is the heart of the reader.
 void setSource(java.io.InputStream source)
          This will set the source from which objects are to be read.
 void setSource(java.lang.String source)
          This will set a string from which objects can be read.
 void setTypeFactory(TypeFactory factory)
          This will set the TypeFactory to be used in constructing objects based on what is read from the external form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SONReader

public SONReader()
This creates a new SONReader. It will have TypeFactorySimple (just SObj and SArray objects) as its factory.


SONReader

public SONReader(java.lang.String[] typePackageList)
This creates a new SONReader. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory.

Parameters:
typePackageList - this is the restricted list of packages from which objects can be created. See TypeFactoryReflect for complete documentation on the package list.

SONReader

public SONReader(java.lang.String[] typePackageList,
                 java.io.InputStream input)
This creates a new SONReader. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory.

Parameters:
typePackageList - this is the restricted list of packages from which objects can be written. See TypeFactoryReflect for complete documentation on the package list.
input - this is the input stream from which the SON is to be read.

SONReader

public SONReader(java.lang.String input)
This creates a new SONReader. It will have TypeFactorySimple (just SObj and SArray objects) as its factory.

Parameters:
input - a string from which the SON object is to be read.

SONReader

public SONReader(java.lang.String[] typePackageList,
                 java.lang.String input)
This creates a new SONReader. It will have a TypeFactoryReflect (allows subclasses of SO) as its factory. Pretty printing will be turned on.

Parameters:
typePackageList - this is the restricted list of packages from which objects can be written. See TypeFactoryReflect for complete documentation on the package list.
input - this is the string from which SON objects are read.
Method Detail

setTypeFactory

public void setTypeFactory(TypeFactory factory)
Description copied from interface: SparkReader
This will set the TypeFactory to be used in constructing objects based on what is read from the external form.

Specified by:
setTypeFactory in interface SparkReader
Parameters:
factory - the factory to be used in translating type names into objects

getTypeFactory

public TypeFactory getTypeFactory()
Description copied from interface: SparkReader
This will return the TypeFactory being used.

Specified by:
getTypeFactory in interface SparkReader
Returns:
a TypeFactory

setSource

public void setSource(java.io.InputStream source)
Description copied from interface: SparkReader
This will set the source from which objects are to be read.

Specified by:
setSource in interface SparkReader
Parameters:
source - an input stream from which to read objects.

setSource

public void setSource(java.lang.String source)
Description copied from interface: SparkReader
This will set a string from which objects can be read.

Specified by:
setSource in interface SparkReader
Parameters:
source - the source string from which objects can be read

read

public SV read()
Description copied from interface: SparkReader
This is the heart of the reader. This is where an object or any Spark value is read from the source.

Specified by:
read in interface SparkReader
Returns:
the value that was read or null if there were no values left in the source.