ccc.api.jaxrs.providers
Class AbstractProvider

java.lang.Object
  extended by ccc.api.jaxrs.providers.AbstractProvider
Direct Known Subclasses:
BooleanProvider, FileReader, JsonableWriter, MetadataWriter, S11nProvider, StringCollectionWriter, UuidCollectionWriter, UUIDProvider

public class AbstractProvider
extends java.lang.Object

Abstract class providing helper methods for JAX-RS readers & writers.

Author:
Civic Computing Ltd.

Constructor Summary
AbstractProvider()
           
 
Method Summary
protected  java.io.PrintWriter createWriter(java.io.OutputStream outputStream)
          Create a UTF-8 print-writer.
protected
<T> java.lang.Class<T>
getTypeArgument(java.lang.reflect.Type type, int index)
          Determine the class argument of a parameterized type.
protected  boolean isCollectionOfType(java.lang.Class<?> clazz, java.lang.reflect.Type type)
          Determine if a type is a collection of the specified class.
protected  boolean isMapOfType(java.lang.Class<?> clazz, java.lang.reflect.Type type)
          Determine if a type is a collection of the specified class.
protected  Json readJson(javax.ws.rs.core.MediaType mediaType, java.io.InputStream entityStream)
          Read the request body into a JSON object.
protected  java.lang.String readString(javax.ws.rs.core.MediaType mediaType, java.io.InputStream entityStream)
          Read the request body into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProvider

public AbstractProvider()
Method Detail

isCollectionOfType

protected boolean isCollectionOfType(java.lang.Class<?> clazz,
                                     java.lang.reflect.Type type)
Determine if a type is a collection of the specified class.

Parameters:
clazz - The parameterized type of the collection.
type - The type to check.
Returns:
True if 'type' is a collection of type 'clazz', false otherwise.

isMapOfType

protected boolean isMapOfType(java.lang.Class<?> clazz,
                              java.lang.reflect.Type type)
Determine if a type is a collection of the specified class.

Parameters:
clazz - The parameterized type of the collection.
type - The type to check.
Returns:
True if 'type' is a collection of type 'clazz', false otherwise.

readString

protected java.lang.String readString(javax.ws.rs.core.MediaType mediaType,
                                      java.io.InputStream entityStream)
                               throws java.io.IOException
Read the request body into a string.

Parameters:
mediaType - The content type of the request.
entityStream - The request input stream.
Returns:
The body, as a string.
Throws:
java.io.IOException - If reading from the input stream fails.

readJson

protected Json readJson(javax.ws.rs.core.MediaType mediaType,
                        java.io.InputStream entityStream)
                 throws java.io.IOException
Read the request body into a JSON object.

Parameters:
mediaType - The content type of the request.
entityStream - The request input stream.
Returns:
The request body, as a JSON object.
Throws:
java.io.IOException - If reading from the input stream fails.

createWriter

protected java.io.PrintWriter createWriter(java.io.OutputStream outputStream)
Create a UTF-8 print-writer.

Parameters:
outputStream - The output stream the writer will write to.
Returns:
The new print-writer.

getTypeArgument

protected <T> java.lang.Class<T> getTypeArgument(java.lang.reflect.Type type,
                                                 int index)
Determine the class argument of a parameterized type.

Type Parameters:
T - The type of the class argument.
Parameters:
type - The parameterized type.
index - The index of the argument.
Returns:
The argument's class.


Copyright © 2010. All Rights Reserved.