info.sswap.http.representation.rdf
Class ModelWriter

java.lang.Object
  extended by info.sswap.http.representation.rdf.ModelWriter
All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyWriter<info.sswap.api.model.SSWAPModel>

@Provider
public class ModelWriter
extends java.lang.Object
implements javax.ws.rs.ext.MessageBodyWriter<info.sswap.api.model.SSWAPModel>

A writer for a SSWAPModel. This class is capable of producing the models as RDF/XML (commented) or Turtle.

Author:
Blazej Bulka

Field Summary
private static org.apache.log4j.Logger LOGGER
          The logger for the model writer.
 
Constructor Summary
ModelWriter()
           
 
Method Summary
 long getSize(info.sswap.api.model.SSWAPModel model, java.lang.Class<?> clazz, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
          Gets the estimated size of the output.
private  boolean isMediaTypeAcceptable(javax.ws.rs.core.MediaType mediaType)
          Checks whether mediaType is one of the acceptable MIME types (currently only RDF formats are acceptable).
 boolean isWriteable(java.lang.Class<?> clazz, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
          Checks whether this writer is capable of producing the output for the given object and the requested MIME type.
 void writeTo(info.sswap.api.model.SSWAPModel model, java.lang.Class<?> clazz, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> stringObjectMultiValuedMap, java.io.OutputStream outputStream)
          Produces the output for the specified SSWAPModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final org.apache.log4j.Logger LOGGER
The logger for the model writer.

Constructor Detail

ModelWriter

public ModelWriter()
Method Detail

getSize

public long getSize(info.sswap.api.model.SSWAPModel model,
                    java.lang.Class<?> clazz,
                    java.lang.reflect.Type type,
                    java.lang.annotation.Annotation[] annotations,
                    javax.ws.rs.core.MediaType mediaType)
Gets the estimated size of the output. Since it is difficult to estimate the size of the output without actually producing it, this method returns -1 to denote that it cannot predict the size.

Specified by:
getSize in interface javax.ws.rs.ext.MessageBodyWriter<info.sswap.api.model.SSWAPModel>
Parameters:
model - the sswap model to be written
clazz - the class of the object to be written (the actual implementation of SSWAPModel)
type - the type of the passed object (in this case java.lang.Class)
annotations - the array of annotations of the class
mediaType - the requested MIME type in which the output should be produced

isMediaTypeAcceptable

private boolean isMediaTypeAcceptable(javax.ws.rs.core.MediaType mediaType)
Checks whether mediaType is one of the acceptable MIME types (currently only RDF formats are acceptable).

Parameters:
mediaType - MIME type to be checked
Returns:
true if mediaType is one of RDF formats, false otherwise

isWriteable

public boolean isWriteable(java.lang.Class<?> clazz,
                           java.lang.reflect.Type type,
                           java.lang.annotation.Annotation[] annotations,
                           javax.ws.rs.core.MediaType mediaType)
Checks whether this writer is capable of producing the output for the given object and the requested MIME type.

Specified by:
isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<info.sswap.api.model.SSWAPModel>
Parameters:
clazz - the class of the object to be written.
type - the type of the passed object (Array, Class, etc)
annotations - the array of annotations
mediaType - the requested MIME type in which the output should be produced
Returns:
true only if the object implements SSWAPModel interface and the requested MIME type is one of the supported RDF formats (RDF/XML or turtle).

writeTo

public void writeTo(info.sswap.api.model.SSWAPModel model,
                    java.lang.Class<?> clazz,
                    java.lang.reflect.Type type,
                    java.lang.annotation.Annotation[] annotations,
                    javax.ws.rs.core.MediaType mediaType,
                    javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> stringObjectMultiValuedMap,
                    java.io.OutputStream outputStream)
             throws java.io.IOException,
                    javax.ws.rs.WebApplicationException
Produces the output for the specified SSWAPModel

Specified by:
writeTo in interface javax.ws.rs.ext.MessageBodyWriter<info.sswap.api.model.SSWAPModel>
Parameters:
model - the sswap model to be written
clazz - the class of the object to be written (the actual implementation of SSWAPModel)
type - the type of the passed object (in this case java.lang.Class)
annotations - the array of annotations of the class
mediaType - the requested MIME type in which the output should be produced
stringObjectMultiValuedMap - this parameter is not used by this implementation
outputStream - the stream to which the output should be written
Throws:
javax.ws.rs.WebApplicationException - if the specified object cannot be written by this writer or the media type is not supported by this writer
java.io.IOException - if an I/O error should occur while writing the output to the stream


Copyright (c) 2010, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.