com.yworks.yfiles.server.graphml.support
Class AbstractGraphRoundtripSupport

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
Direct Known Subclasses:
Graph2DRoundtripSupport, GraphRoundtripSupport

public abstract class AbstractGraphRoundtripSupport
extends Object

Common base class for the server-side roundtrip support classes.


Field Summary
static String EDGE_2_ID_DPKEY
          Key for storing the current edge id EdgeMap in the graph.
protected  List mappers
           
static String NODE_2_ID_DPKEY
          Key for storing the current node id NodeMap in the graph.
static String PARAM_GRAPH
          Parameter name of the request parameter that contains graphml sent by the client.
static String RESPONSE_DOCUMENT_TAG
          The xml element name that is used as the outermost tag for all non-graphml server responses.
 
Constructor Summary
AbstractGraphRoundtripSupport()
           
 
Method Summary
 void addMapper(Object tag, String name, int graphMLType, int graphMLScope)
          Adds integrated support for the roundtripping of data associated with graph elements.
protected  void configureRoundtripGraph(LayoutGraph layoutGraph)
          Configure the layout graph.
abstract  LayoutGraph createRoundtripGraph()
          Creates the graph that should be used for roundtripping.
 XmlWriter createXmlWriter(OutputStream os)
          Create A XMLWriter instance that can be used for sending xml formatted responses to the client.
protected  GraphDecoder getGraphDecoder()
          Get the decoder that is used to decode the data received from the client.
abstract  boolean readGraph(javax.servlet.http.HttpServletRequest request, Graph graph)
          If the request contains the PARAM_GRAPH parameter, the parameter value is used for updating the graph instance currently stored in the session.
abstract  void readGraph(InputStream is, Graph graph)
          Reads the graph from the given stream using the current handler.
abstract  void readGraph(URL url, Graph graph)
          Reads the graph from the given url using the current handler.
 void sendError(String message, javax.servlet.http.HttpServletResponse response)
          Send an error to the client.
 void sendError(Throwable e, javax.servlet.ServletOutputStream outputStream)
          Send an error to the client.
abstract  void sendGraph(Graph graph, javax.servlet.http.HttpServletResponse response)
          Send the current graph to the client in GraphML format using UTF-8 encoding.
abstract  void sendGraph(Graph graph, OutputStream os, String outputEncoding)
          Writes the current graph to the stream in GraphML format using the provided encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mappers

protected List mappers

NODE_2_ID_DPKEY

public static final String NODE_2_ID_DPKEY
Key for storing the current node id NodeMap in the graph.

See Also:
Constant Field Values

EDGE_2_ID_DPKEY

public static final String EDGE_2_ID_DPKEY
Key for storing the current edge id EdgeMap in the graph.

See Also:
Constant Field Values

PARAM_GRAPH

public static final String PARAM_GRAPH
Parameter name of the request parameter that contains graphml sent by the client.

See Also:
Constant Field Values

RESPONSE_DOCUMENT_TAG

public static final String RESPONSE_DOCUMENT_TAG
The xml element name that is used as the outermost tag for all non-graphml server responses.

See Also:
Constant Field Values
Constructor Detail

AbstractGraphRoundtripSupport

public AbstractGraphRoundtripSupport()
Method Detail

getGraphDecoder

protected GraphDecoder getGraphDecoder()
Get the decoder that is used to decode the data received from the client.

Returns:

readGraph

public abstract void readGraph(InputStream is,
                               Graph graph)
                        throws IOException
Reads the graph from the given stream using the current handler.

Parameters:
is - the stream to use - the encoding should be UTF-8
graph - the graph to read the result in.
Throws:
IOException - if an io exception occured.

readGraph

public abstract boolean readGraph(javax.servlet.http.HttpServletRequest request,
                                  Graph graph)
                           throws IOException
If the request contains the PARAM_GRAPH parameter, the parameter value is used for updating the graph instance currently stored in the session.

To decide whether the value of the PARAM_GRAPH parameter has to be decoded and decompressed, the "graphEncoding" parameter is used. For example, to indicate base64-encoded, zlib-compressed and URI-encoded data, the value has to be "base64/deflate/encodeURIComponent".

Parameters:
request - The servlet request
Returns:
whether the request contained a graph that was read.
Throws:
IOException - If parsing goes wrong.

readGraph

public abstract void readGraph(URL url,
                               Graph graph)
                        throws IOException
Reads the graph from the given url using the current handler.

Parameters:
url - the URL to use
graph - the graph to read the result in.
Throws:
IOException - if an io exception occured.

sendGraph

public abstract void sendGraph(Graph graph,
                               javax.servlet.http.HttpServletResponse response)
                        throws IOException
Send the current graph to the client in GraphML format using UTF-8 encoding. This method will close the response stream.

The response content type is set to "text/xml".

Parameters:
graph - The current graph.
response - The response that will be sent to the client.
Throws:
IOException - If something goes wrong during GraphML export.

sendGraph

public abstract void sendGraph(Graph graph,
                               OutputStream os,
                               String outputEncoding)
                        throws IOException
Writes the current graph to the stream in GraphML format using the provided encoding. This method will not close the stream.

Parameters:
graph - The current graph.
os - The stream to write the graph to.
Throws:
IOException - If something goes wrong during GraphML export.

createRoundtripGraph

public abstract LayoutGraph createRoundtripGraph()
Creates the graph that should be used for roundtripping.

Returns:
an instance that can be used for reading and writing graphs.

addMapper

public void addMapper(Object tag,
                      String name,
                      int graphMLType,
                      int graphMLScope)
Adds integrated support for the roundtripping of data associated with graph elements. Calling this method after the creation of this instance will prepare the io mechanism to read and write the associated data from the requests and to the responses. Also an appropriate DataMap will be automatically registered using the provided key on the graph instances created by createRoundtripGraph().

Parameters:
tag - The tag to use for the DataMap that can be queried from the graph's instance using Graph.getDataProvider(Object) .
name - The name to use for the data in the GraphML file.
graphMLType - A constant from the AttributeConstants describing the type of the data.
graphMLScope - A constant from the list of scope constants defined in GraphMLConstants.

createXmlWriter

public XmlWriter createXmlWriter(OutputStream os)
Create A XMLWriter instance that can be used for sending xml formatted responses to the client.

Parameters:
os - An output stream to write xml to
Returns:
A XMLWriter implementation

sendError

public void sendError(Throwable e,
                      javax.servlet.ServletOutputStream outputStream)
               throws IOException
Send an error to the client. The error is sent in XML format:
  <?xml version="1.0" encoding="UTF-8"?>
  <response>
    <errors>
      <error>
       <![CDATA[
          error message
        ]]>
      <error>
    </errors>
 </response>
 

Parameters:
e - The error.
outputStream - the stream to write the error to - this stream will not be closed.
Throws:
IOException - If writing to the response writer fails.

configureRoundtripGraph

protected void configureRoundtripGraph(LayoutGraph layoutGraph)
Configure the layout graph.

The default implementation adds the data providers that are required for client-server roundtripping and the data providers for any custom mappers that were added using addMapper(Object, String, int, int).

Parameters:
layoutGraph - the layout graph instance that is used for roundtripping.

sendError

public void sendError(String message,
                      javax.servlet.http.HttpServletResponse response)
               throws IOException
Send an error to the client. The error is sent in XML format:
  <?xml version="1.0" encoding="UTF-8"?>
  <response>
    <errors>
      <error>
       <![CDATA[
          error message
        ]]>
      <error>
    </errors>
 </response>
 

Parameters:
message - The error message.
response - The response.
Throws:
IOException - If writing to the response writer fails.


Copyright © 2000-2007 yWorks GmbH. All rights reserved