org.broadleafcommerce.core.web.api
Class BroadleafMessageBodyReaderWriter
java.lang.Object
org.broadleafcommerce.core.web.api.BroadleafMessageBodyReaderWriter
- All Implemented Interfaces:
- javax.ws.rs.ext.ContextResolver<JAXBContext>, javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
@Component
@Provider
public class BroadleafMessageBodyReaderWriter
- extends Object
- implements javax.ws.rs.ext.MessageBodyReader<Object>, javax.ws.rs.ext.MessageBodyWriter<Object>, javax.ws.rs.ext.ContextResolver<JAXBContext>, org.springframework.context.ApplicationContextAware
This custom MessageBodyReaderWriter was written in order to correctly handle
any custom extended entities that Broadleaf is aware of. The intent is to
replace any paramerterized types with the correct implementations that are
defined in the Application Context. Once the correct generic types are
replaced, the class then delegates to the default XML or JSON List providers.
- Author:
- elbertbautista
- See Also:
JSONListElementProvider,
XMLListElementProvider
|
Method Summary |
protected Type |
getApiWrapper(Class<?> type,
Type lookupType)
Via the ApplicationContext we can look up exactly what implementation
corresponds to the parameterized domain interface and determine if that
is annotated with proper JAXB annotations for serialization. |
JAXBContext |
getContext(Class<?> ignored)
|
protected Type |
getLookupType(Class<?> type,
Type genericType)
|
long |
getSize(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
|
protected void |
initializeTypeMap()
|
boolean |
isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
|
boolean |
isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
|
Object |
readFrom(Class<Object> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders,
InputStream entityStream)
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
|
void |
writeTo(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
applicationContext
protected org.springframework.context.ApplicationContext applicationContext
ps
@Context
protected javax.ws.rs.ext.Providers ps
xif
@Context
protected com.sun.jersey.spi.inject.Injectable<XMLInputFactory> xif
spf
@Context
protected com.sun.jersey.spi.inject.Injectable<SAXParserFactory> spf
jaxbContext
protected JAXBContext jaxbContext
typeMap
protected HashMap<String,Class<?>> typeMap
xmlListProvider
protected com.sun.jersey.core.impl.provider.entity.XMLListElementProvider.App xmlListProvider
jsonListProvider
protected com.sun.jersey.json.impl.provider.entity.JSONListElementProvider.App jsonListProvider
xmlRootElementProvider
protected com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider.App xmlRootElementProvider
jsonRootElementProvider
protected com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.App jsonRootElementProvider
BroadleafMessageBodyReaderWriter
public BroadleafMessageBodyReaderWriter()
isReadable
public boolean isReadable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
- Specified by:
isReadable in interface javax.ws.rs.ext.MessageBodyReader<Object>
isWriteable
public boolean isWriteable(Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
- Specified by:
isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<Object>
readFrom
public Object readFrom(Class<Object> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,String> httpHeaders,
InputStream entityStream)
throws IOException,
javax.ws.rs.WebApplicationException
- Specified by:
readFrom in interface javax.ws.rs.ext.MessageBodyReader<Object>
- Throws:
IOException
javax.ws.rs.WebApplicationException
getSize
public long getSize(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
- Specified by:
getSize in interface javax.ws.rs.ext.MessageBodyWriter<Object>
writeTo
public void writeTo(Object t,
Class<?> type,
Type genericType,
Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType,
javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
OutputStream entityStream)
throws IOException
- Specified by:
writeTo in interface javax.ws.rs.ext.MessageBodyWriter<Object>
- Throws:
IOException
getLookupType
protected Type getLookupType(Class<?> type,
Type genericType)
getApiWrapper
protected Type getApiWrapper(Class<?> type,
Type lookupType)
- Via the ApplicationContext we can look up exactly what implementation
corresponds to the parameterized domain interface and determine if that
is annotated with proper JAXB annotations for serialization. We then
return the correct implementing Class in case of a root element, a new
ParameterizedType in case of a collection, or a new Array in case of an
array The default providers can then handle the actual serialization of
the List or Root element safely.
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
getContext
public JAXBContext getContext(Class<?> ignored)
- Specified by:
getContext in interface javax.ws.rs.ext.ContextResolver<JAXBContext>
initializeTypeMap
protected void initializeTypeMap()
Copyright © 2013. All Rights Reserved.