Server component

Class com.gp.api.jsp.MxServerComponent is WebCharts3D server-side image generation bean. Usually, you would not create an instance of this class directly, but obtain it by calling static method getDefaultInstance that takes ServletContext as a parameter:

MxServerComponent server = MxServerComponent.getDefaultInstance(application);

This function looks up an instance of MxServerComponent in servlet context. If it exists, then gc() function is called for it and this instance is returned, otherwise a new instance is created using default constructor, stored in the context and then returned.

Constuctors:

public MxServerComponent()
Constructs a new server component instance using properties returned by MxServerProperties.read() method.
public MxServerComponent(MxServerProperties properties)
Constructs a new server component instance using provided properties.

Image generation methods:

public MxChartDescription newImageSpec()
Returns a new instance of chart description.
public byte[] getBytes(MxChartDescription dsc)
Returns the actual bytes of the image based on its description. The generated image is placed in the cache, but the reference count is not incremented.
public void saveBytesTo(MxChartDescription dsc, String path)
Produces the chart if it does not exist in the cache and saves it into a file. The generated image is placed in the cache, but the reference count is not incremented.
public String getImageID(MxChartDescription dsc)
Returns a unique image ID for the image description. This function generates the image if the image with such attributes does not exist in the cache. The generated image is placed in the cache and its reference count is incremented.
public String getImageTag(MxChartDescription dsc, String hostname)
Returns a snippet of HTML code with appropriate for this type of image HTML tag (for example <img;>) and source attribute (for example src) of this tag pointing back to server. The generated image is placed in the cache and its reference count is incremented.
The URL for the source attribute is constructed by concatenating hostname parameter with the unqiue image id. For example,
server.getImageTag(server.newImageSpec(),"/getImage.jsp?image=")
will return <img src="/getImage.jsp?image=UID>. You can then simply write this snippet into out writer to embed the image into the page.
public byte[] getCachedBytes(String guid)
Returns the actual bytes of the image based on the unique image's id. The reference count for the image is decremented.

Output:

public void writeBytesTo(MxChartDescription dsc, HttpServletResponse response) throws IOException
This method obtains the image bytes using getBytes method, sets the content type based on the image type, writes the bytes into the response, and closes the output. See also notes for writeCachedBytesTo regarding some server limitations.
public void writeCachedBytesTo(String guid, HttpServletResponse response) throws IOException
This method obtains the image bytes using getCachedBytes method, sets the content type based on the image type, writes the bytes into the response, and closes the output.

NOTE. The implementation of this method tries to obtain the ServletOutputStream from the response object. Some JSP servers do not permit it inside the JSP pages, if the JSPWriter have been already retrieved by the time this function is called. If this happens, you might try to write the bytes to the JSPWriter by creating a new String from the bytes


public void writeCachedBytesTo(String guid, JspWriter out, HttpServletResponse response) throws IOException {
Similar to the previous method, this method obtains the image bytes using getCachedBytes method, sets the content type based on the image type, writes the bytes into the response, and closes the output.

NOTE. This is a work around for the servers that will not allow us to obtain the output stream because it was already opened. This function in such case writes the image to the JspWriter. from the bytes


Miscelaneous:

public void gc()
Runs the garbage collector that removes the expired images from memory or destroys the files. This function will return immediately if the last call to the garbage collector was made within the interval specified by the MxServerProperties gcInterval member.
public int getImageCount()
Returns the number of the currently cached images.
public long getMemorySize()
Returns the amount of memory that cached images take.
public String getHtmlReport()
Returns a brief description of the component status in HTML format suitable for displaying in a browser.