org.odata4j.format.json
Class JsonFormatWriter<T>

java.lang.Object
  extended by org.odata4j.format.json.JsonFormatWriter<T>
Type Parameters:
T - the type of the content elements to be written to the stream.
All Implemented Interfaces:
FormatWriter<T>
Direct Known Subclasses:
JsonCollectionFormatWriter, JsonComplexObjectFormatWriter, JsonEntryFormatWriter, JsonFeedFormatWriter, JsonPropertyFormatWriter, JsonRequestEntryFormatWriter, JsonServiceDocumentFormatWriter, JsonSimpleFormatWriter, JsonSingleLinkFormatWriter, JsonSingleLinksFormatWriter

public abstract class JsonFormatWriter<T>
extends Object
implements FormatWriter<T>

Write content to an output stream in JSON format.

This class is abstract because it delegates the strategy pattern of writing actual content elements to its (various) subclasses.

Each element in the array to be written can be wrapped in a function call on the JavaScript side by specifying the name of a function to call to the constructor.


Constructor Summary
JsonFormatWriter(String jsonpCallback)
          Creates a new JSON writer.
 
Method Summary
 String getContentType()
          Recover the MIME content type for the stream
protected  String getJsonpCallback()
           
 void write(UriInfo uriInfo, Writer w, T target)
          Write an object to the formatted version of the stream
protected  void writeCollection(JsonWriter jw, EdmCollectionType type, OCollection<? extends OObject> coll)
           
protected  void writeComplexObject(JsonWriter jw, String complexObjectName, String fullyQualifiedTypeName, List<OProperty<?>> props)
           
protected abstract  void writeContent(UriInfo uriInfo, JsonWriter jw, T target)
          A strategy method to actually write content objects
protected  void writeLinks(JsonWriter jw, OEntity oe, UriInfo uriInfo, boolean isResponse)
           
protected  void writeOEntity(UriInfo uriInfo, JsonWriter jw, OEntity oe, EdmEntitySet ees, boolean isResponse)
           
protected  void writeOProperties(JsonWriter jw, List<OProperty<?>> properties)
           
protected  void writeProperty(JsonWriter jw, OProperty<?> prop)
           
protected  void writeRequestLink(JsonWriter jw, OLink link, OEntity oe, UriInfo uriInfo)
           
protected  void writeResponseLink(JsonWriter jw, OLink link, OEntity oe, UriInfo uriInfo)
           
protected  void writeValue(JsonWriter jw, EdmType type, Object pvalue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonFormatWriter

public JsonFormatWriter(String jsonpCallback)
Creates a new JSON writer.

Parameters:
jsonpCallback - a function to call on the javascript side to act on the data provided in the content.
Method Detail

getContentType

public String getContentType()
Description copied from interface: FormatWriter
Recover the MIME content type for the stream

Specified by:
getContentType in interface FormatWriter<T>
Returns:
the MIME content type to be used for the content of this stream

getJsonpCallback

protected String getJsonpCallback()

write

public void write(UriInfo uriInfo,
                  Writer w,
                  T target)
Description copied from interface: FormatWriter
Write an object to the formatted version of the stream

Specified by:
write in interface FormatWriter<T>
Parameters:
uriInfo - the base uri of the entity documents
w - the underlying "stream" to write to
target - the object to be written

writeCollection

protected void writeCollection(JsonWriter jw,
                               EdmCollectionType type,
                               OCollection<? extends OObject> coll)

writeComplexObject

protected void writeComplexObject(JsonWriter jw,
                                  String complexObjectName,
                                  String fullyQualifiedTypeName,
                                  List<OProperty<?>> props)

writeContent

protected abstract void writeContent(UriInfo uriInfo,
                                     JsonWriter jw,
                                     T target)
A strategy method to actually write content objects

Parameters:
uriInfo - the base URI that indicates where in the schema we are
jw - the JSON writer object
target - the content value to be written

writeLinks

protected void writeLinks(JsonWriter jw,
                          OEntity oe,
                          UriInfo uriInfo,
                          boolean isResponse)

writeOEntity

protected void writeOEntity(UriInfo uriInfo,
                            JsonWriter jw,
                            OEntity oe,
                            EdmEntitySet ees,
                            boolean isResponse)

writeOProperties

protected void writeOProperties(JsonWriter jw,
                                List<OProperty<?>> properties)

writeProperty

protected void writeProperty(JsonWriter jw,
                             OProperty<?> prop)

writeRequestLink

protected void writeRequestLink(JsonWriter jw,
                                OLink link,
                                OEntity oe,
                                UriInfo uriInfo)

writeResponseLink

protected void writeResponseLink(JsonWriter jw,
                                 OLink link,
                                 OEntity oe,
                                 UriInfo uriInfo)

writeValue

protected void writeValue(JsonWriter jw,
                          EdmType type,
                          Object pvalue)


http://odata4j.org