org.foray.graphic.factory
Class GraphicFactory

java.lang.Object
  extended by org.foray.graphic.factory.GraphicFactory
Direct Known Subclasses:
BMPFactory, EPSFactory, GIFFactory, JPEGFactory, MathFactory, PDFFactory, PNGFactory, SVGFactory, TIFFFactory

public abstract class GraphicFactory
extends Object

Base class for all Graphic factory classes. Instances of GraphicFactory subclasses can be registered with GraphicServer and used there to create Graphic instances from raw input streams. Because GraphicServer might be used in multi-threaded environments, it is very important that GraphicFactory subclasses handle state information with great care. In general, all state information used in the attemptCreate() method should either be local, or some other class (perhaps an inner class) should be used to manage it.


Constructor Summary
GraphicFactory(GraphicServer4a server)
          Constructor.
 
Method Summary
protected abstract  Graphic4a attemptCreate(URL url, BufferedInputStream bis)
          Subclasses implement this method to try to create an appropriate Graphic instance.
 org.apache.commons.logging.Log getLogger()
          Get the logger.
 GraphicServer4a getServer()
          Returns the parent server.
 Graphic4a makeGraphic(URL url, BufferedInputStream bis)
          Factory method to create a Graphic instance from a given URL and a reusable input stream for that URL.
 int maxBytesToVerify()
          Tells GraphicFactory how large to set the readlimit value when marking the beginning of the stream, so that is can be reused.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicFactory

public GraphicFactory(GraphicServer4a server)
Constructor.

Parameters:
server - The parent graphic server.
Method Detail

makeGraphic

public Graphic4a makeGraphic(URL url,
                             BufferedInputStream bis)
                      throws IOException
Factory method to create a Graphic instance from a given URL and a reusable input stream for that URL.

Parameters:
url - The URL which contains the graphic content.
bis - The reusable input stream containing the bytes from url.
Returns:
The newly-created Graphic instance, or null if this factory was unable to create such an instance.
Throws:
IOException - For IO errors.

attemptCreate

protected abstract Graphic4a attemptCreate(URL url,
                                           BufferedInputStream bis)
                                    throws IOException
Subclasses implement this method to try to create an appropriate Graphic instance. Note that this superclass handles the task of marking and resetting the input stream, so all the subclass needs to do is read the stream.

Parameters:
url - The URL which contains the graphic content.
bis - The reusable input stream containing the bytes from url.
Returns:
The newly-created Graphic instance, or null if this factory was unable to create such an instance.
Throws:
IOException - For IO errors.

maxBytesToVerify

public int maxBytesToVerify()
Tells GraphicFactory how large to set the readlimit value when marking the beginning of the stream, so that is can be reused. The default value is 1024. Subclasses that need to read more than this amount when trying to create a Graphic instance should override this method and return a higher amount. Otherwise, subsequent attempts to use the stream will result in i/o errors.

Returns:
The maximum number of bytes that the factory might need to read from the stream to be able to create a Graphic from it.

getLogger

public org.apache.commons.logging.Log getLogger()
Get the logger.

Returns:
The logger.

getServer

public GraphicServer4a getServer()
Returns the parent server.

Returns:
The parent server.


Copyright © 2017. All rights reserved.