Apache CXF API

org.apache.cxf.jaxrs.provider
Class AbstractJAXBProvider<T>

java.lang.Object
  extended by org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider
      extended by org.apache.cxf.jaxrs.provider.AbstractJAXBProvider<T>
All Implemented Interfaces:
javax.ws.rs.ext.MessageBodyReader<T>, javax.ws.rs.ext.MessageBodyWriter<T>
Direct Known Subclasses:
JAXBElementProvider, JSONProvider

public abstract class AbstractJAXBProvider<T>
extends AbstractConfigurableProvider
implements javax.ws.rs.ext.MessageBodyReader<T>, javax.ws.rs.ext.MessageBodyWriter<T>


Nested Class Summary
protected static class AbstractJAXBProvider.CollectionWrapper
           
protected static class AbstractJAXBProvider.JAXBCollectionWrapperReader
           
 
Field Summary
protected static ResourceBundle BUNDLE
           
protected  Map<Class<?>,JAXBContext> classContexts
           
protected  Set<Class<?>> collectionContextClasses
           
protected  Map<String,String> inAppendMap
           
protected  List<String> inDropElements
           
protected  Map<String,String> inElementsMap
           
protected  Map<String,String> jaxbElementClassMap
           
protected static Logger LOG
           
protected  boolean marshalAsJaxbElement
           
protected static String NS_MAPPER_PROPERTY_RI
           
protected static String NS_MAPPER_PROPERTY_RI_INT
           
protected  Map<String,String> outAppendMap
           
protected  List<String> outDropElements
           
protected  Map<String,String> outElementsMap
           
protected  Map<String,JAXBContext> packageContexts
           
protected  boolean unmarshalAsJaxbElement
           
protected  boolean xmlTypeAsJaxbElementOnly
           
 
Constructor Summary
AbstractJAXBProvider()
           
 
Method Summary
protected  boolean canBeReadAsJaxbElement(Class<?> type)
           
protected static Object checkAdapter(Object obj, Class<?> cls, Annotation[] anns, boolean marshal)
           
 void clearContexts()
           
protected  XMLStreamReader configureReaderRestrictions(XMLStreamReader reader)
           
protected  Object convertToJaxbElementIfNeeded(Object obj, Class<?> cls, Type genericType)
           
protected  XMLStreamReader createDepthReaderIfNeeded(XMLStreamReader reader, InputStream is)
           
protected  Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType, String enc)
           
protected  XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader, InputStream is)
           
protected  XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer, OutputStream os, boolean dropAtXmlLevel)
           
protected  Unmarshaller createUnmarshaller(Class<?> cls, Type genericType)
           
protected  Unmarshaller createUnmarshaller(Class<?> cls, Type genericType, boolean isCollection)
           
protected  Class<?> getActualType(Class<?> type, Type genericType, Annotation[] anns)
           
 JAXBContext getClassContext(Class<?> type)
           
protected  JAXBContext getClassContext(Class<?> type, Type genericType)
           
protected  JAXBContext getCollectionContext(Class<?> type)
           
protected  QName getCollectionWrapperQName(Class<?> cls, Type type, Object object, boolean pluralName)
           
protected  MessageContext getContext()
           
protected  DocumentDepthProperties getDepthProperties()
           
 JAXBContext getJAXBContext(Class<?> type, Type genericType)
           
protected  Class<?> getJaxbElementClass(Class<?> cls)
           
protected  QName getJaxbQName(Class<?> cls, Type type, Object object, boolean pluralName)
           
 JAXBContext getPackageContext(Class<?> type)
           
protected  JAXBContext getPackageContext(Class<?> type, Type genericType)
           
protected  Schema getSchema()
           
protected  Schema getSchema(Class<?> cls)
           
 long getSize(T o, Class<?> type, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mt)
           
protected static String getStackTrace(Exception ex)
           
protected
<X> X
getStreamHandlerFromCurrentMessage(Class<X> staxCls)
           
protected static void handleExceptionEnd(Throwable t, String message, boolean read)
           
protected static StringBuilder handleExceptionStart(Exception e)
           
protected  void handleJAXBException(JAXBException e, boolean read)
           
protected  void handleXMLStreamException(XMLStreamException e, boolean read)
           
 void init(List<ClassResourceInfo> cris)
          Gives providers a chance to introspect the JAX-RS model classes.
 boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, javax.ws.rs.core.MediaType mt)
           
 boolean isSkipJaxbChecks()
           
protected  boolean isSupported(Class<?> type, Type genericType, Annotation[] anns)
           
 boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, javax.ws.rs.core.MediaType mt)
           
protected  boolean isXmlRoot(Class<?> cls)
           
protected  boolean isXmlType(Class<?> cls)
           
protected  boolean objectFactoryOrIndexAvailable(Class<?> type)
           
protected  void reportEmptyContentLength()
           
 void setAttributesToElements(boolean value)
           
 void setCatalogLocation(String name)
           
 void setCollectionWrapperMap(Map<String,String> map)
           
 void setCollectionWrapperName(String wName)
           
protected  void setContext(MessageContext context)
           
 void setContextProperties(Map<String,Object> contextProperties)
           
 void setDepthProperties(DocumentDepthProperties depthProperties)
           
 void setExtraClass(Class<?>[] userExtraClass)
           
 void setInAppendElements(Map<String,String> inElements)
           
 void setInDropElements(List<String> dropElementsSet)
           
 void setInTransformElements(Map<String,String> inElements)
           
 void setJaxbElementClassMap(Map<String,String> map)
           
 void setJaxbElementClassNames(List<String> names)
           
 void setMarshallAsJaxbElement(boolean value)
           
 void setMarshallerListener(Marshaller.Listener marshallerListener)
           
protected static void setMarshallerProp(Marshaller ms, Object value, String name1, String name2)
           
protected  void setNamespaceMapper(Marshaller ms, Map<String,String> map)
           
 void setNamespaceMapperPropertyName(String namespaceMapperProperty)
           
 void setOutAppendElements(Map<String,String> map)
           
 void setOutDropElements(List<String> dropElementsSet)
           
 void setOutTransformElements(Map<String,String> outElements)
           
protected  void setSchema(Schema s)
           
 void setSchemaHandler(SchemaHandler handler)
           
 void setSchemaHandlers(Map<String,SchemaHandler> handlers)
           
 void setSchemaLocations(List<String> locations)
           
 void setSingleJaxbContext(boolean useSingleContext)
           
 void setSkipJaxbChecks(boolean skipJaxbChecks)
           
 void setUnmarshallAsJaxbElement(boolean value)
           
 void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)
           
 void setUnmarshallerProperties(Map<String,Object> unmarshalProperties)
           
 void setUseSingleContextForPackages(boolean use)
           
 void setValidateBeforeWrite(boolean validateBeforeWrite)
           
 void setValidateInput(boolean validateInput)
           
 void setValidateOutput(boolean validateOutput)
           
 void setValidationHandler(ValidationEventHandler handler)
           
 void setXmlRootAsJaxbElement(boolean xmlRootAsJaxbElement)
           
 void setXmlTypeAsJaxbElementOnly(boolean value)
           
protected  void validateObjectIfNeeded(Marshaller marshaller, Class<?> cls, Object obj)
           
 void writeTo(T t, Type genericType, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders, OutputStream entityStream)
           
 
Methods inherited from class org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider
getBus, getConsumeMediaTypes, getEnableBuffering, getEnableStreaming, getProduceMediaTypes, isPayloadEmpty, isPayloadEmpty, setBus, setConsumeMediaTypes, setEnableBuffering, setEnableStreaming, setProduceMediaTypes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ws.rs.ext.MessageBodyReader
readFrom
 
Methods inherited from interface javax.ws.rs.ext.MessageBodyWriter
writeTo
 

Field Detail

BUNDLE

protected static final ResourceBundle BUNDLE

LOG

protected static final Logger LOG

NS_MAPPER_PROPERTY_RI

protected static final String NS_MAPPER_PROPERTY_RI
See Also:
Constant Field Values

NS_MAPPER_PROPERTY_RI_INT

protected static final String NS_MAPPER_PROPERTY_RI_INT
See Also:
Constant Field Values

collectionContextClasses

protected Set<Class<?>> collectionContextClasses

jaxbElementClassMap

protected Map<String,String> jaxbElementClassMap

unmarshalAsJaxbElement

protected boolean unmarshalAsJaxbElement

marshalAsJaxbElement

protected boolean marshalAsJaxbElement

xmlTypeAsJaxbElementOnly

protected boolean xmlTypeAsJaxbElementOnly

outElementsMap

protected Map<String,String> outElementsMap

outAppendMap

protected Map<String,String> outAppendMap

outDropElements

protected List<String> outDropElements

inDropElements

protected List<String> inDropElements

inElementsMap

protected Map<String,String> inElementsMap

inAppendMap

protected Map<String,String> inAppendMap

packageContexts

protected Map<String,JAXBContext> packageContexts

classContexts

protected Map<Class<?>,JAXBContext> classContexts
Constructor Detail

AbstractJAXBProvider

public AbstractJAXBProvider()
Method Detail

setXmlRootAsJaxbElement

public void setXmlRootAsJaxbElement(boolean xmlRootAsJaxbElement)

setNamespaceMapper

protected void setNamespaceMapper(Marshaller ms,
                                  Map<String,String> map)
                           throws Exception
Throws:
Exception

setMarshallerProp

protected static void setMarshallerProp(Marshaller ms,
                                        Object value,
                                        String name1,
                                        String name2)
                                 throws Exception
Throws:
Exception

setValidationHandler

public void setValidationHandler(ValidationEventHandler handler)

setSingleJaxbContext

public void setSingleJaxbContext(boolean useSingleContext)

setUseSingleContextForPackages

public void setUseSingleContextForPackages(boolean use)

setExtraClass

public void setExtraClass(Class<?>[] userExtraClass)

init

public void init(List<ClassResourceInfo> cris)
Description copied from class: AbstractConfigurableProvider
Gives providers a chance to introspect the JAX-RS model classes. For example, the JAXB provider may use the model classes to create a single composite JAXBContext supporting all the JAXB-annotated root resource classes/types.

Overrides:
init in class AbstractConfigurableProvider

setContextProperties

public void setContextProperties(Map<String,Object> contextProperties)

setUnmarshallerProperties

public void setUnmarshallerProperties(Map<String,Object> unmarshalProperties)

setUnmarshallAsJaxbElement

public void setUnmarshallAsJaxbElement(boolean value)

setMarshallAsJaxbElement

public void setMarshallAsJaxbElement(boolean value)

setXmlTypeAsJaxbElementOnly

public void setXmlTypeAsJaxbElementOnly(boolean value)

setJaxbElementClassNames

public void setJaxbElementClassNames(List<String> names)

setJaxbElementClassMap

public void setJaxbElementClassMap(Map<String,String> map)

reportEmptyContentLength

protected void reportEmptyContentLength()
                                 throws javax.ws.rs.core.NoContentException
Throws:
javax.ws.rs.core.NoContentException

getStreamHandlerFromCurrentMessage

protected <X> X getStreamHandlerFromCurrentMessage(Class<X> staxCls)

isXmlRoot

protected boolean isXmlRoot(Class<?> cls)

isXmlType

protected boolean isXmlType(Class<?> cls)

convertToJaxbElementIfNeeded

protected Object convertToJaxbElementIfNeeded(Object obj,
                                              Class<?> cls,
                                              Type genericType)
                                       throws Exception
Throws:
Exception

getJaxbElementClass

protected Class<?> getJaxbElementClass(Class<?> cls)

setCollectionWrapperName

public void setCollectionWrapperName(String wName)

setCollectionWrapperMap

public void setCollectionWrapperMap(Map<String,String> map)

setContext

protected void setContext(MessageContext context)

isWriteable

public boolean isWriteable(Class<?> type,
                           Type genericType,
                           Annotation[] anns,
                           javax.ws.rs.core.MediaType mt)
Specified by:
isWriteable in interface javax.ws.rs.ext.MessageBodyWriter<T>

writeTo

public void writeTo(T t,
                    Type genericType,
                    Annotation[] annotations,
                    javax.ws.rs.core.MediaType mediaType,
                    javax.ws.rs.core.MultivaluedMap<String,Object> httpHeaders,
                    OutputStream entityStream)
             throws IOException,
                    javax.ws.rs.WebApplicationException
Throws:
IOException
javax.ws.rs.WebApplicationException

getCollectionContext

protected JAXBContext getCollectionContext(Class<?> type)
                                    throws JAXBException
Throws:
JAXBException

getCollectionWrapperQName

protected QName getCollectionWrapperQName(Class<?> cls,
                                          Type type,
                                          Object object,
                                          boolean pluralName)
                                   throws Exception
Throws:
Exception

getJaxbQName

protected QName getJaxbQName(Class<?> cls,
                             Type type,
                             Object object,
                             boolean pluralName)
                      throws Exception
Throws:
Exception

isReadable

public boolean isReadable(Class<?> type,
                          Type genericType,
                          Annotation[] anns,
                          javax.ws.rs.core.MediaType mt)
Specified by:
isReadable in interface javax.ws.rs.ext.MessageBodyReader<T>

canBeReadAsJaxbElement

protected boolean canBeReadAsJaxbElement(Class<?> type)

setSchemaLocations

public void setSchemaLocations(List<String> locations)

setCatalogLocation

public void setCatalogLocation(String name)

setSchemaHandler

public void setSchemaHandler(SchemaHandler handler)

setSchemaHandlers

public void setSchemaHandlers(Map<String,SchemaHandler> handlers)

setSchema

protected void setSchema(Schema s)

getSize

public long getSize(T o,
                    Class<?> type,
                    Type genericType,
                    Annotation[] annotations,
                    javax.ws.rs.core.MediaType mt)
Specified by:
getSize in interface javax.ws.rs.ext.MessageBodyWriter<T>

getContext

protected MessageContext getContext()

getJAXBContext

public JAXBContext getJAXBContext(Class<?> type,
                                  Type genericType)
                           throws JAXBException
Throws:
JAXBException

getClassContext

public JAXBContext getClassContext(Class<?> type)
                            throws JAXBException
Throws:
JAXBException

getClassContext

protected JAXBContext getClassContext(Class<?> type,
                                      Type genericType)
                               throws JAXBException
Throws:
JAXBException

getPackageContext

public JAXBContext getPackageContext(Class<?> type)

getPackageContext

protected JAXBContext getPackageContext(Class<?> type,
                                        Type genericType)

isSupported

protected boolean isSupported(Class<?> type,
                              Type genericType,
                              Annotation[] anns)

objectFactoryOrIndexAvailable

protected boolean objectFactoryOrIndexAvailable(Class<?> type)

createUnmarshaller

protected Unmarshaller createUnmarshaller(Class<?> cls,
                                          Type genericType)
                                   throws JAXBException
Throws:
JAXBException

createUnmarshaller

protected Unmarshaller createUnmarshaller(Class<?> cls,
                                          Type genericType,
                                          boolean isCollection)
                                   throws JAXBException
Throws:
JAXBException

createMarshaller

protected Marshaller createMarshaller(Object obj,
                                      Class<?> cls,
                                      Type genericType,
                                      String enc)
                               throws JAXBException
Throws:
JAXBException

validateObjectIfNeeded

protected void validateObjectIfNeeded(Marshaller marshaller,
                                      Class<?> cls,
                                      Object obj)
                               throws JAXBException
Throws:
JAXBException

getActualType

protected Class<?> getActualType(Class<?> type,
                                 Type genericType,
                                 Annotation[] anns)

checkAdapter

protected static Object checkAdapter(Object obj,
                                     Class<?> cls,
                                     Annotation[] anns,
                                     boolean marshal)

getSchema

protected Schema getSchema()

getSchema

protected Schema getSchema(Class<?> cls)

clearContexts

public void clearContexts()

getStackTrace

protected static String getStackTrace(Exception ex)

handleExceptionStart

protected static StringBuilder handleExceptionStart(Exception e)

handleExceptionEnd

protected static void handleExceptionEnd(Throwable t,
                                         String message,
                                         boolean read)

handleJAXBException

protected void handleJAXBException(JAXBException e,
                                   boolean read)

handleXMLStreamException

protected void handleXMLStreamException(XMLStreamException e,
                                        boolean read)

setOutTransformElements

public void setOutTransformElements(Map<String,String> outElements)

setInAppendElements

public void setInAppendElements(Map<String,String> inElements)

setInTransformElements

public void setInTransformElements(Map<String,String> inElements)

setOutAppendElements

public void setOutAppendElements(Map<String,String> map)

setOutDropElements

public void setOutDropElements(List<String> dropElementsSet)

setInDropElements

public void setInDropElements(List<String> dropElementsSet)

setAttributesToElements

public void setAttributesToElements(boolean value)

setSkipJaxbChecks

public void setSkipJaxbChecks(boolean skipJaxbChecks)

isSkipJaxbChecks

public boolean isSkipJaxbChecks()

createTransformWriterIfNeeded

protected XMLStreamWriter createTransformWriterIfNeeded(XMLStreamWriter writer,
                                                        OutputStream os,
                                                        boolean dropAtXmlLevel)

createTransformReaderIfNeeded

protected XMLStreamReader createTransformReaderIfNeeded(XMLStreamReader reader,
                                                        InputStream is)

createDepthReaderIfNeeded

protected XMLStreamReader createDepthReaderIfNeeded(XMLStreamReader reader,
                                                    InputStream is)

configureReaderRestrictions

protected XMLStreamReader configureReaderRestrictions(XMLStreamReader reader)

getDepthProperties

protected DocumentDepthProperties getDepthProperties()

setValidateBeforeWrite

public void setValidateBeforeWrite(boolean validateBeforeWrite)

setValidateOutput

public void setValidateOutput(boolean validateOutput)

setValidateInput

public void setValidateInput(boolean validateInput)

setDepthProperties

public void setDepthProperties(DocumentDepthProperties depthProperties)

setUnmarshallerListener

public void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener)

setMarshallerListener

public void setMarshallerListener(Marshaller.Listener marshallerListener)

setNamespaceMapperPropertyName

public void setNamespaceMapperPropertyName(String namespaceMapperProperty)

Apache CXF API

Apache CXF