org.apache.stanbol.entityhub.jersey.utils
Class JerseyUtils

java.lang.Object
  extended by org.apache.stanbol.entityhub.jersey.utils.JerseyUtils

public final class JerseyUtils
extends Object

Utility methods used by several of the RESTful service endpoints of the Entityhub.

Author:
Rupert Westenthaler

Field Summary
static Set<String> ENTITY_SUPPORTED_MEDIA_TYPES
          Unmodifiable Set with the Media Types supported for Entity
static Set<String> QUERY_RESULT_SUPPORTED_MEDIA_TYPES
          Unmodifiable Set with the Media Types supported for QueryResultList
static Set<String> REPRESENTATION_SUPPORTED_MEDIA_TYPES
          Unmodifiable Set with the Media Types supported for Representation
 
Method Summary
static org.apache.stanbol.entityhub.servicesapi.query.FieldQuery createFieldQueryForFindRequest(String name, String field, String language, Integer limit, Integer offset, String ldpath)
          Creates an FieldQuery for parameters parsed by the /find requests supported by the /symbol, /sites and {siteId} RESTful endpoints.
static Map<String,String> parseForm(InputStream entityStream, String charset)
          This Method is intended to parse form data from MediaType.APPLICATION_FORM_URLENCODED requests.
static boolean testParameterizedType(Class<?> rawType, Class<?>[] parameterTypes, Type type)
          Tests the parsed type against the raw type and parsed Type parameters.
static boolean testType(Class<?> required, Type type)
          Tests if a generic type (may be <?>, <? extends {required}> or <? super {required}>) is compatible with the required one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPRESENTATION_SUPPORTED_MEDIA_TYPES

public static final Set<String> REPRESENTATION_SUPPORTED_MEDIA_TYPES
Unmodifiable Set with the Media Types supported for Representation


ENTITY_SUPPORTED_MEDIA_TYPES

public static final Set<String> ENTITY_SUPPORTED_MEDIA_TYPES
Unmodifiable Set with the Media Types supported for Entity


QUERY_RESULT_SUPPORTED_MEDIA_TYPES

public static final Set<String> QUERY_RESULT_SUPPORTED_MEDIA_TYPES
Unmodifiable Set with the Media Types supported for QueryResultList

Method Detail

createFieldQueryForFindRequest

public static org.apache.stanbol.entityhub.servicesapi.query.FieldQuery createFieldQueryForFindRequest(String name,
                                                                                                       String field,
                                                                                                       String language,
                                                                                                       Integer limit,
                                                                                                       Integer offset,
                                                                                                       String ldpath)
                                                                                                throws javax.ws.rs.WebApplicationException,
                                                                                                       IllegalArgumentException
Creates an FieldQuery for parameters parsed by the /find requests supported by the /symbol, /sites and {siteId} RESTful endpoints. TODO: This has to be refactored to use "EntityQuery" as soon as Multiple query types are implemented for the Entityhub.

Parameters:
name - the name pattern to search entities for (required)
field - the field used to search for entities (required)
language - the language of the parsed name pattern (optional)
limit - the maximum number of result (optional)
offset - the offset of the first result (optional)
Returns:
the FieldQuery representing the parsed parameter
Throws:
javax.ws.rs.WebApplicationException - in case the parsed name pattern is invalid. The validation of this required parameter provided by the Request is done by this method.
IllegalArgumentException - in case the parsed field is invalid. Callers of this method need to ensure that this parameter is set to an valid value.

testType

public static boolean testType(Class<?> required,
                               Type type)
Tests if a generic type (may be <?>, <? extends {required}> or <? super {required}>) is compatible with the required one. TODO: Should be moved to an utility class

Parameters:
required - the required class the generic type MUST BE compatible with
genericType - the required class
Returns:
if the generic type is compatible with the required class

testParameterizedType

public static boolean testParameterizedType(Class<?> rawType,
                                            Class<?>[] parameterTypes,
                                            Type type)
Tests the parsed type against the raw type and parsed Type parameters. This allows e.g. to check for Map<String,Number> but also works with classes that extend generic types such as Dummy extends HashMap<String,String>.

Parameters:
rawType - the raw type to test against
parameterTypes - the types of the parameters
type - the type to test
Returns:
if the type is compatible or not

parseForm

public static Map<String,String> parseForm(InputStream entityStream,
                                           String charset)
                                    throws IOException
This Method is intended to parse form data from MediaType.APPLICATION_FORM_URLENCODED requests. This functionality us usually needed when writing a MessageBodyReader to get the data from the "InputStream entityStream" parameter of the MessageBodyReader.readFrom(Class, Type, java.lang.annotation.Annotation[], MediaType, javax.ws.rs.core.MultivaluedMap, InputStream) method.

Parameters:
entityStream - the stream with the form data
charset - The charset used for the request (if null or empty UTF-8 is used as default.
Returns:
the parsed form data as key value map
Throws:
IOException - on any exception while reading the data form the stream


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.