Class AbstractXStreamWrapper

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatContentTypeHeader, org.apache.camel.spi.DataFormatName, org.apache.camel.StatefulService, org.apache.camel.SuspendableService
    Direct Known Subclasses:
    JsonDataFormat, XStreamDataFormat

    public abstract class AbstractXStreamWrapper
    extends org.apache.camel.support.service.ServiceSupport
    implements org.apache.camel.CamelContextAware, org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName, org.apache.camel.spi.DataFormatContentTypeHeader
    An abstract class which implement data format (DataFormat) interface which leverage the XStream library for XML or JSON's marshaling and unmarshaling
    • Constructor Detail

      • AbstractXStreamWrapper

        public AbstractXStreamWrapper()
      • AbstractXStreamWrapper

        public AbstractXStreamWrapper​(com.thoughtworks.xstream.XStream xstream)
    • Method Detail

      • getCamelContext

        public org.apache.camel.CamelContext getCamelContext()
        Specified by:
        getCamelContext in interface org.apache.camel.CamelContextAware
      • setCamelContext

        public void setCamelContext​(org.apache.camel.CamelContext camelContext)
        Specified by:
        setCamelContext in interface org.apache.camel.CamelContextAware
      • getXStream

        public com.thoughtworks.xstream.XStream getXStream​(org.apache.camel.spi.ClassResolver resolver)
        Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will be created and cached.
        Parameters:
        resolver - class resolver to be used during a configuration of the XStream instance.
        Returns:
        XStream instance used by this data format.
      • getXStream

        public com.thoughtworks.xstream.XStream getXStream​(org.apache.camel.CamelContext context)
        Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will be created and cached.
        Parameters:
        context - to be used during a configuration of the XStream instance
        Returns:
        XStream instance used by this data format.
      • setXStream

        public void setXStream​(com.thoughtworks.xstream.XStream xstream)
      • createXStream

        protected com.thoughtworks.xstream.XStream createXStream​(org.apache.camel.spi.ClassResolver resolver,
                                                                 ClassLoader classLoader)
      • getModeFromString

        protected int getModeFromString​(String modeString)
      • setConverters

        public void setConverters​(Map<String,​String> converters)
      • setOmitFields

        public void setOmitFields​(Map<String,​String> omitFields)
      • getImplicitCollections

        public Map<String,​String> getImplicitCollections()
      • setImplicitCollections

        public void setImplicitCollections​(Map<String,​String> implicitCollections)
      • getXstreamDriver

        public com.thoughtworks.xstream.io.HierarchicalStreamDriver getXstreamDriver()
      • setXstreamDriver

        public void setXstreamDriver​(com.thoughtworks.xstream.io.HierarchicalStreamDriver xstreamDriver)
      • getPermissions

        public String getPermissions()
      • setPermissions

        public void setPermissions​(String permissions)
      • getMode

        public String getMode()
      • setMode

        public void setMode​(String mode)
      • isContentTypeHeader

        public boolean isContentTypeHeader()
      • setContentTypeHeader

        public void setContentTypeHeader​(boolean contentTypeHeader)
        If enabled then XStream will set the Content-Type header to application/json when marshalling to JSon and application/xml when marshalling to XML.
        Specified by:
        setContentTypeHeader in interface org.apache.camel.spi.DataFormatContentTypeHeader
      • getXstream

        public com.thoughtworks.xstream.XStream getXstream()
      • setXstream

        public void setXstream​(com.thoughtworks.xstream.XStream xstream)
      • marshal

        public void marshal​(org.apache.camel.Exchange exchange,
                            Object body,
                            OutputStream stream)
                     throws Exception
        Specified by:
        marshal in interface org.apache.camel.spi.DataFormat
        Throws:
        Exception
      • unmarshal

        public Object unmarshal​(org.apache.camel.Exchange exchange,
                                InputStream stream)
                         throws Exception
        Specified by:
        unmarshal in interface org.apache.camel.spi.DataFormat
        Throws:
        Exception
      • createHierarchicalStreamReader

        protected abstract com.thoughtworks.xstream.io.HierarchicalStreamReader createHierarchicalStreamReader​(org.apache.camel.Exchange exchange,
                                                                                                               InputStream stream)
                                                                                                        throws XMLStreamException
        Throws:
        XMLStreamException
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.service.BaseService
        Throws:
        Exception