sk.uniba.euromath.gene.rendereradapter
Class ExporterAdapter

java.lang.Object
  extended by sk.uniba.euromath.gene.rendereradapter.ExporterAdapter
All Implemented Interfaces:
IExporter

public final class ExporterAdapter
extends Object
implements IExporter

Wraps an IRenderer instance as an exporter instance.

Author:
Martin Vysny

Constructor Summary
ExporterAdapter(IRenderer renderer, RendererInfo info, IExporterFactory factory)
          Constructor.
 
Method Summary
static ExporterInfo asExporterInfo(RendererInfo info, IExporterFactory factory)
          Converts renderer info instance to the exporter info.
 void export(Source source, Result result, ExportContext context)
           Exports (transforms) the document from a single namespace and writes it to the result.
 ExporterInfo getInfo()
          Returns information about the exporter.
 Map<String,Object> getProperties()
          Properties that drives the export process.
 Object offerObject()
           When the exporter accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something on a certain instance of Graphics), then return non-null value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExporterAdapter

public ExporterAdapter(IRenderer renderer,
                       RendererInfo info,
                       IExporterFactory factory)
Constructor.

Parameters:
renderer - wrap this renderer.
info - info about the renderer.
factory - factory that will produce these exporters.
Method Detail

asExporterInfo

public static ExporterInfo asExporterInfo(RendererInfo info,
                                          IExporterFactory factory)
Converts renderer info instance to the exporter info.

Parameters:
info - info to convert
factory - register the factory.
Returns:
converted exporter info instance.

export

public void export(Source source,
                   Result result,
                   ExportContext context)
            throws ExportException,
                   IOException
Description copied from interface: IExporter

Exports (transforms) the document from a single namespace and writes it to the result.

If the result is text or binary data and the result is instance of DOMResult or SAXResult then the result must contain one text/cdata node with the result.

If needed then Coordinator may communicate with the Exporter directly via the ObjectResult class, however the plugin may throw an exception when it does not support such return style. You can use this result style to render images in the memory and give it to the renderer (the Coordinator) directly, for example when rendering images to the PDF-FOP result type.

If result does not specify the encoding then UTF-8 should be used as default encoding. If the encoding is not supported by the result file format then any valid encoding can be used. However, Coordinator is strongly encouraged to provide the encoding whenever appropriate. If the need of encoding can be avoided then use the appropriate means to avoid it. For example if the result is DOM, SAX or if StreamResult has non- null writer.

If some required properties are missing or they have incorrect values then UnsupportedOperation exception should be thrown with appropriate error message.

If object is offered as a source then the exporter must be able to free any resources associated with the object (for example it must call dispose() on java.awt.Graphics.

Both source and result must not be closed after the export is done.

Specified by:
export in interface IExporter
Parameters:
source - the source of the transformation. identifier may be null or it may identify the datasource - previous exporter, source document etc. SAXSource: reader is never null, input source is almost always null. DOMSource: node is never null. StreamSource: at least one of StreamSource.getInputStream() and StreamSource.getReader() is not null. If they are both non-null you must select one and use it exclusively - you cannot use read from both. ObjectSource: No assumptions can be made on the value of object - this protocol is user-specific.
result - the result of the transformation. identifier may be null or you may set it to identify this exporter. SAXResult: content handler is never null, lexical handler is not used and is null. node is never null, next sibling is not used and is null. StreamResult: at least one of output stream and writer is not null. If they are both non-null you must select one and use it exclusively - you cannot write to both. ObjectResult: No assumptions can be made on the value of object - this protocol is user-specific.
context - the export context.
Throws:
ExportException - if something goes wrong in the process of transformation - an unrecoverable error. All non-fatal errors and warnings should be logged using the helper's log.
IOException - if i/o error occurs.

getInfo

public ExporterInfo getInfo()
Description copied from interface: IExporter
Returns information about the exporter.

Specified by:
getInfo in interface IExporter
Returns:
info object. Must be equal with the info object returned by the exporter factory.

getProperties

public Map<String,Object> getProperties()
Description copied from interface: IExporter
Properties that drives the export process. Currently there are no properties defined, you may use this facility to introduce your own.

Specified by:
getProperties in interface IExporter
Returns:
map of properties. If some required properties are missing then the exporter may fail during the export, with the appropriate error message.

offerObject

public Object offerObject()
Description copied from interface: IExporter

When the exporter accepts the ObjectSource but wants to provide an object as a result to the exporter E (for example it wants E to draw something on a certain instance of Graphics), then return non-null value. If this functionality is not needed then just return null - if E requires some object then it can create any object as long as it is instance of class that this exporter expects.

The consumer (the one that receives the object, i.e. this) is responsible for freeing the object if necessary (at the end of the export method), even if this function returned null.

If you want producer (the one that creates the object) to create custom instances then provide a factory object. This trick is used with http://www.uniba.sk/euromath/holder/java.awt.Graphics holder - a factory is returned that is able to produce java.awt.Graphics instances.

Specified by:
offerObject in interface IExporter
Returns:
the object instance, or null.


Copyright 2003-2003-2006 null. All Rights Reserved.