Class ProcessingRenderer

  • All Implemented Interfaces:
    com.yahoo.component.Component, java.lang.Cloneable, java.lang.Comparable<com.yahoo.component.Component>

    public class ProcessingRenderer
    extends AsynchronousSectionedRenderer<com.yahoo.processing.Response>
    The default renderer for processing responses. Renders a response in JSON. This can be overridden to specify particular rendering of leaf Data elements. This default implementation renders the toString of each element.
    Author:
    bratseth
    • Field Summary

      • Fields inherited from class com.yahoo.component.AbstractComponent

        isDeconstructable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void beginList​(com.yahoo.processing.response.DataList<?> list)
      Invoked at the beginning of each data list, including the implicit, outermost one in the response.
      void beginResponse​(java.io.OutputStream stream)
      Invoked once at the beginning of rendering a response.
      void data​(com.yahoo.processing.response.Data data)
      Invoked for each leaf node in the data tree
      void endList​(com.yahoo.processing.response.DataList<?> list)
      Invoked at the end of each data list, including the implicit, outermost one in the response.
      void endResponse()
      Invoked once at the end of rendering a response.
      java.lang.String getEncoding()
      Name of the output encoding, if applicable.
      java.lang.String getMimeType()
      The MIME type of the rendered content sent to the client.
      void init()
      Do per instance initialization.
      protected void renderValue​(com.yahoo.processing.response.Data data, com.yahoo.text.JSONWriter writer)
      Renders the value of a data element.
      protected boolean shouldRender​(com.yahoo.processing.response.Data data)
      Returns whether this data element should be rendered.
      • Methods inherited from class com.yahoo.processing.rendering.Renderer

        clone
      • Methods inherited from class com.yahoo.component.AbstractComponent

        compareTo, getClassName, getId, getIdString, hasInitializedId, initId, isDeconstructable, setIsDeconstructable, toString
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ProcessingRenderer

        public ProcessingRenderer()
    • Method Detail

      • init

        public void init()
        Description copied from class: AsynchronousSectionedRenderer
        Do per instance initialization. If overriding this in a subclass, not invoking it in the subclass' implementation will most likely cause the rendering to fail with an exception.
        Overrides:
        init in class AsynchronousSectionedRenderer<com.yahoo.processing.Response>
      • beginResponse

        public final void beginResponse​(java.io.OutputStream stream)
                                 throws java.io.IOException
        Description copied from class: AsynchronousSectionedRenderer
        Invoked once at the beginning of rendering a response. This assigns the stream to be used throughput the rendering. Subsequent calls must use the same stream.
        Specified by:
        beginResponse in class AsynchronousSectionedRenderer<com.yahoo.processing.Response>
        Parameters:
        stream - the stream to render to in this and all subsequent calls.
        Throws:
        java.io.IOException - passed on from the stream
      • beginList

        public final void beginList​(com.yahoo.processing.response.DataList<?> list)
                             throws java.io.IOException
        Description copied from class: AsynchronousSectionedRenderer
        Invoked at the beginning of each data list, including the implicit, outermost one in the response.
        Specified by:
        beginList in class AsynchronousSectionedRenderer<com.yahoo.processing.Response>
        Parameters:
        list - the data list which now will be rendered
        Throws:
        java.io.IOException - passed on from the stream
      • endList

        public final void endList​(com.yahoo.processing.response.DataList<?> list)
                           throws java.io.IOException
        Description copied from class: AsynchronousSectionedRenderer
        Invoked at the end of each data list, including the implicit, outermost one in the response.
        Specified by:
        endList in class AsynchronousSectionedRenderer<com.yahoo.processing.Response>
        Parameters:
        list - the data list which now has no more data items to render
        Throws:
        java.io.IOException - passed on from the stream
      • data

        public final void data​(com.yahoo.processing.response.Data data)
                        throws java.io.IOException
        Description copied from class: AsynchronousSectionedRenderer
        Invoked for each leaf node in the data tree
        Specified by:
        data in class AsynchronousSectionedRenderer<com.yahoo.processing.Response>
        Parameters:
        data - the leaf node to render
        Throws:
        java.io.IOException - passed on from the stream
      • renderValue

        protected void renderValue​(com.yahoo.processing.response.Data data,
                                   com.yahoo.text.JSONWriter writer)
                            throws java.io.IOException
        Renders the value of a data element. This default implementation does writer.fieldValue(data.toString()) Override this to render data in application specific ways.
        Throws:
        java.io.IOException
      • shouldRender

        protected boolean shouldRender​(com.yahoo.processing.response.Data data)
        Returns whether this data element should be rendered. This can be overridden to add new kinds of data which should not be rendered. This default implementation returns true unless the data is instanceof ResponseHeaders.
        Returns:
        true to render it, false to skip completely
      • getEncoding

        public final java.lang.String getEncoding()
        Description copied from class: Renderer
        Name of the output encoding, if applicable.

        TODO: ensure null is OK

        Specified by:
        getEncoding in class Renderer<com.yahoo.processing.Response>
        Returns:
        The encoding of the output if applicable, e.g. "utf-8"
      • getMimeType

        public final java.lang.String getMimeType()
        Description copied from class: Renderer
        The MIME type of the rendered content sent to the client.
        Specified by:
        getMimeType in class Renderer<com.yahoo.processing.Response>
        Returns:
        The mime type of the data written to the writer, e.g. "text/plain"