Package com.yahoo.processing.rendering
Class ProcessingRenderer
- java.lang.Object
-
- com.yahoo.component.AbstractComponent
-
- com.yahoo.processing.rendering.Renderer<RESPONSE>
-
- com.yahoo.processing.rendering.AsynchronousRenderer<RESPONSE>
-
- com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Response>
-
- com.yahoo.processing.rendering.ProcessingRenderer
-
- All Implemented Interfaces:
com.yahoo.component.Component
,com.yahoo.component.Deconstructable
,java.lang.Cloneable
,java.lang.Comparable<com.yahoo.component.Component>
public class ProcessingRenderer extends AsynchronousSectionedRenderer<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
-
-
Constructor Summary
Constructors Constructor Description ProcessingRenderer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginList(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(Data data)
Invoked for each leaf node in the data treevoid
endList(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(Data data, com.yahoo.text.JSONWriter writer)
Renders the value of a data element.protected boolean
shouldRender(Data data)
Returns whether this data element should be rendered.-
Methods inherited from class com.yahoo.processing.rendering.AsynchronousSectionedRenderer
clientClosed, deconstruct, getExecution, getRecursionLevel, getResponse, onClientClosed, render, renderBeforeHandover, setNetworkWiring
-
-
-
-
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 classAsynchronousSectionedRenderer<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 classAsynchronousSectionedRenderer<Response>
- Parameters:
stream
- the stream to render to in this and all subsequent calls.- Throws:
java.io.IOException
- passed on from the stream
-
endResponse
public final void endResponse() throws java.io.IOException
Description copied from class:AsynchronousSectionedRenderer
Invoked once at the end of rendering a response.- Specified by:
endResponse
in classAsynchronousSectionedRenderer<Response>
- Throws:
java.io.IOException
- passed on from the stream
-
beginList
public final void beginList(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 classAsynchronousSectionedRenderer<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(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 classAsynchronousSectionedRenderer<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(Data data) throws java.io.IOException
Description copied from class:AsynchronousSectionedRenderer
Invoked for each leaf node in the data tree- Specified by:
data
in classAsynchronousSectionedRenderer<Response>
- Parameters:
data
- the leaf node to render- Throws:
java.io.IOException
- passed on from the stream
-
renderValue
protected void renderValue(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(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.- Specified by:
getEncoding
in classRenderer<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 classRenderer<Response>
- Returns:
- The mime type of the data written to the writer, e.g. "text/plain"
-
-