net.craftforge.essential.supply
Class Producer

java.lang.Object
  extended by net.craftforge.essential.supply.Producer
Direct Known Subclasses:
JaxbProducer

public class Producer
extends Object

Provides an implementation of the Controllable interface in a view setup.

Since:
02.12.2010
Author:
Christian Bick

Field Summary
protected  Configuration config
          The configuration
 
Constructor Summary
Producer(Configuration config)
          Constructs the producer by supplying the controller configuration.
 
Method Summary
 String getBestMatchingMediaType(String accepted)
           
 void plain(Object result, OutputStream out, String charset)
          Serializes the result object to plain text, using the specified character encoding.
 void produce(String accepted, Object result, OutputStream outputStream, String charset)
          Produces the given result object, serializing to the given media type and streaming it using the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

protected Configuration config
The configuration

Constructor Detail

Producer

public Producer(Configuration config)
Constructs the producer by supplying the controller configuration.

Parameters:
config - The configuration
Method Detail

produce

public void produce(String accepted,
                    Object result,
                    OutputStream outputStream,
                    String charset)
             throws ControllerException
Produces the given result object, serializing to the given media type and streaming it using the specified output stream. The given charset is used to encode the stream. The producer method is chosen accordingly to the given media type. The responsible producer method must contain this media type in its @Produces annotation.

Parameters:
accepted - The comma separated enumeration of accepted media types
result - The result object to serialize
outputStream - The output stream
charset - The charset encoding
Throws:
ControllerException - if the production process fails

getBestMatchingMediaType

public String getBestMatchingMediaType(String accepted)
                                throws ControllerException
Throws:
ControllerException

plain

public void plain(Object result,
                  OutputStream out,
                  String charset)
           throws IOException
Serializes the result object to plain text, using the specified character encoding. Uses the output stream for streaming.

Parameters:
result - The result
out - The output stream
charset - The character encoding
Throws:
IOException - Failed to initialize the writer for the output stream


Copyright © 2011. All Rights Reserved.