org.apache.tuscany.sca.databinding.json.axiom
Class JSONDataSource

java.lang.Object
  extended by org.apache.tuscany.sca.databinding.json.axiom.JSONDataSource
Direct Known Subclasses:
JSONBadgerfishDataSource

public class JSONDataSource
extends java.lang.Object

JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in the OMSourcedElementImpl and can be used either to expand the tree or get the JSON String directly without expanding. This uses the "Mapped" JSON convention.


Field Summary
protected  JSONObject json
           
 
Constructor Summary
JSONDataSource(JSONObject json)
           
 
Method Summary
protected  java.lang.String getJSONString()
           
 javax.xml.stream.XMLStreamReader getReader()
          Gives the StAX reader using the "Mapped" formatted input JSON String.
 void serialize(java.io.OutputStream outputStream, OMOutputFormat omOutputFormat)
          Writes JSON into the output stream.
 void serialize(java.io.Writer writer, OMOutputFormat omOutputFormat)
          Writes JSON through the writer.
 void serialize(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
          Writes XML through the XMLStreamWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

json

protected JSONObject json
Constructor Detail

JSONDataSource

public JSONDataSource(JSONObject json)
Method Detail

serialize

public void serialize(java.io.OutputStream outputStream,
                      OMOutputFormat omOutputFormat)
               throws javax.xml.stream.XMLStreamException
Writes JSON into the output stream. As this should write JSON, it directly gets the JSON string and writes it without expanding the tree.

Parameters:
outputStream - the stream to be written into
omOutputFormat - format of the message, this is ignored.
Throws:
javax.xml.stream.XMLStreamException - if there is an error while writing the message in to the output stream.

serialize

public void serialize(java.io.Writer writer,
                      OMOutputFormat omOutputFormat)
               throws javax.xml.stream.XMLStreamException
Writes JSON through the writer. As this should write JSON, it directly gets the JSON string and writes it without expanding the tree.

Parameters:
writer - Writer to be written into
omOutputFormat - format of the message, this is ignored.
Throws:
javax.xml.stream.XMLStreamException - if there is an error while writing the message through the writer.

serialize

public void serialize(javax.xml.stream.XMLStreamWriter xmlStreamWriter)
               throws javax.xml.stream.XMLStreamException
Writes XML through the XMLStreamWriter. As the input data source is JSON, this method needs to get a StAX reader from that JSON String. Therefore this uses the getReader() method to get the StAX reader writes the events into the XMLStreamWriter.

Parameters:
xmlStreamWriter - StAX writer to be written into
Throws:
javax.xml.stream.XMLStreamException - if there is an error while writing the message through the StAX writer.

getReader

public javax.xml.stream.XMLStreamReader getReader()
                                           throws javax.xml.stream.XMLStreamException
Gives the StAX reader using the "Mapped" formatted input JSON String.

Returns:
The XMLStreamReader according to the JSON String.
Throws:
javax.xml.stream.XMLStreamException - if there is an error while making the StAX reader.

getJSONString

protected java.lang.String getJSONString()