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

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
      extended bycom.yworks.yfiles.server.graphml.support.GraphRoundtripSupport

public class GraphRoundtripSupport
extends AbstractGraphRoundtripSupport

Utility class that helps during Graph roundtrips to the client. This instance can be used to create a temporary graph, receive it from a client's request and send it back to the client.


Field Summary
static String EDGE_LABELS_DPKEY
          The DataMap key that is used to bind Lists of yFiles FLEX client comptability Label instances.
static String EDGE_STYLE_DPKEY
          The DataMap key that is used to bind the yFiles FLEX client comptability IEdgeStyle instances.
static String NODE_LABELS_DPKEY
          The DataMap key that is used to bind Lists of yFiles FLEX client comptability Label instances.
static String NODE_STYLE_DPKEY
          The DataMap key that is used to bind the yFiles FLEX client comptability INodeStyle instances.
static String SHARED_DATA_DPKEY
           
 
Fields inherited from class com.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
EDGE_2_ID_DPKEY, mappers, NODE_2_ID_DPKEY, PARAM_GRAPH, RESPONSE_DOCUMENT_TAG
 
Constructor Summary
GraphRoundtripSupport()
           
 
Method Summary
 void addDeserializer(IDeserializer deserializer)
          Add a deserializer instance that will be registered with the serializer registry in createSerializerRegistry().
 void addSerializer(ISerializer serializer)
          Add a serializer instance that will be registered with the serializer registry in createSerializerRegistry().
protected  void configureHandler(GraphMLLayoutGraphIOHandler layoutGraphIOHandler)
          Configures the provided handler.
protected  void configureRoundtripGraph(LayoutGraph layoutGraph)
          Configure the layout graph.
protected  GraphMLLayoutGraphIOHandler createHandler()
          Creates the handler that will be used for the IO.
 LayoutGraph createRoundtripGraph()
          Creates the graph that should be used for roundtripping.
protected  SerializerRegistry createSerializerRegistry()
          Create the default serializer registry that will be used for reading and writing GraphML data.
protected  SharedDataOutputHandler createSharedDataOuputHandler()
          Create the output handler that writes shared elements.
 boolean isDocumentFragmentMode()
          Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments.
 boolean isMapLabelModels()
          Whether client-side label models will be maped to server-side label models when reading and vice-verse when writing the graph.
 boolean readGraph(javax.servlet.http.HttpServletRequest request, Graph graph)
          If the request contains the AbstractGraphRoundtripSupport.PARAM_GRAPH parameter, the parameter value is used for updating the graph instance currently stored in the session.
 void readGraph(InputStream is, Graph graph)
          Reads the graph from the given stream using the current handler.
 void readGraph(URL url, Graph graph)
          Reads the graph from the given url using the current handler.
 void sendGraph(Graph graph, javax.servlet.http.HttpServletResponse response)
          Send the current graph to the client in GraphML format using UTF-8 encoding.
 void sendGraph(Graph graph, OutputStream os, String outputEncoding)
          Writes the current graph to the stream in GraphML format using the provided encoding.
 void setDocumentFragmentMode(boolean documentFragmentMode)
          Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments.
 void setMapLabelModels(boolean mapLabelModels)
          Set whether the IO should be configured to map client-side label models to server-side label models.
 
Methods inherited from class com.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
addMapper, createXmlWriter, getGraphDecoder, sendError, sendError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODE_STYLE_DPKEY

public static final String NODE_STYLE_DPKEY
The DataMap key that is used to bind the yFiles FLEX client comptability INodeStyle instances.

If isDocumentFragmentMode() is true, xml document fragments will be contained in the data provider instead.

See Also:
isDocumentFragmentMode(), Constant Field Values

EDGE_STYLE_DPKEY

public static final String EDGE_STYLE_DPKEY
The DataMap key that is used to bind the yFiles FLEX client comptability IEdgeStyle instances.

If isDocumentFragmentMode() is true, xml document fragments will be contained in the data provider instead.

See Also:
isDocumentFragmentMode(), Constant Field Values

NODE_LABELS_DPKEY

public static final String NODE_LABELS_DPKEY
The DataMap key that is used to bind Lists of yFiles FLEX client comptability Label instances.

If isDocumentFragmentMode() is true, xml document fragments will be contained in the data provider instead.

See Also:
isDocumentFragmentMode(), Constant Field Values

EDGE_LABELS_DPKEY

public static final String EDGE_LABELS_DPKEY
The DataMap key that is used to bind Lists of yFiles FLEX client comptability Label instances.

If isDocumentFragmentMode() is true, xml document fragments will be contained in the data provider instead.

See Also:
isDocumentFragmentMode(), Constant Field Values

SHARED_DATA_DPKEY

public static final String SHARED_DATA_DPKEY
See Also:
Constant Field Values
Constructor Detail

GraphRoundtripSupport

public GraphRoundtripSupport()
Method Detail

isDocumentFragmentMode

public boolean isDocumentFragmentMode()
Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments. If false the container objects from package com.yworks.yfiles.server.graphml.flexio.data will be used.

The default value is false.

Returns:
Since:
1.3
See Also:
FlexIOTools, NODE_STYLE_DPKEY, EDGE_STYLE_DPKEY, NODE_LABELS_DPKEY, EDGE_LABELS_DPKEY

setDocumentFragmentMode

public void setDocumentFragmentMode(boolean documentFragmentMode)
Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments. If false the container objects from package com.yworks.yfiles.server.graphml.flexio.data will be used.

The default value is false.

Returns:
Since:
1.3
See Also:
FlexIOTools, NODE_STYLE_DPKEY, EDGE_STYLE_DPKEY, NODE_LABELS_DPKEY, EDGE_LABELS_DPKEY

setMapLabelModels

public void setMapLabelModels(boolean mapLabelModels)
Set whether the IO should be configured to map client-side label models to server-side label models. This will work for the free- and slider edge label models and for the discrete node label models (interior/exterior). If this property is set to false, layout calculations won't change the client's label positions

If this roundtrip support instance is not in document fragment mode, the yFiles Java label position information will be committed to the label model parameters of yFiles FLEX client Label instances when the graph is written back to the client. Because the label positions have to be up to date before the shared data is written, class SharedDataOutputHandler takes care of copying the label layout data. This behavior can be configured using SharedDataOutputHandler.setCommitLabelLayouts(boolean). The SharedDataOutputHandler instance that is used by this roundtrip support instance can be configured using createSharedDataOuputHandler(). The position information can also be comitted before, using FlexIOTools.copyLabelLayouts(y.layout.LayoutGraph).

In document fragment mode, a LabelCompatOutputHandler is registered, which commits the label layouts to the DocumentFragments contained in the NODE_LABELS_DPKEY and EDGE_LABELS_DPKEY data providers before the document fragments are written.

Parameters:
mapLabelModels - Whether to map client-side label models to yFiles Java label models. The default is true.
See Also:
LabelCompatInputHandler, LabelCompatOutputHandler

isMapLabelModels

public boolean isMapLabelModels()
Whether client-side label models will be maped to server-side label models when reading and vice-verse when writing the graph.

See Also:
setMapLabelModels(boolean)

addSerializer

public void addSerializer(ISerializer serializer)
Add a serializer instance that will be registered with the serializer registry in createSerializerRegistry().

Parameters:
serializer - A serializer instance that will be used when the graph is written.

addDeserializer

public void addDeserializer(IDeserializer deserializer)
Add a deserializer instance that will be registered with the serializer registry in createSerializerRegistry().

Parameters:
deserializer - A deserializer instance that will be used when the graph is read.

createSerializerRegistry

protected SerializerRegistry createSerializerRegistry()
Create the default serializer registry that will be used for reading and writing GraphML data. This implementation adds all default ISerializer and IDeserializer instances for reading and writing the yFiles FLEX client's GraphML format.


readGraph

public boolean readGraph(javax.servlet.http.HttpServletRequest request,
                         Graph graph)
                  throws IOException
Description copied from class: AbstractGraphRoundtripSupport
If the request contains the AbstractGraphRoundtripSupport.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 AbstractGraphRoundtripSupport.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".

Specified by:
readGraph in class AbstractGraphRoundtripSupport
Parameters:
request - The servlet request
Returns:
whether the request contained a graph that was read.
Throws:
IOException - If parsing goes wrong.

readGraph

public void readGraph(InputStream is,
                      Graph graph)
               throws IOException
Description copied from class: AbstractGraphRoundtripSupport
Reads the graph from the given stream using the current handler.

Specified by:
readGraph in class AbstractGraphRoundtripSupport
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 void readGraph(URL url,
                      Graph graph)
               throws IOException
Description copied from class: AbstractGraphRoundtripSupport
Reads the graph from the given url using the current handler.

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

createHandler

protected GraphMLLayoutGraphIOHandler createHandler()
Creates the handler that will be used for the IO. This handler provides IO for the style associated to the graph using the keys declared in this class, as well as the labels and the node ids and edge ids This implementation creates the instance and calls configureHandler(GraphMLLayoutGraphIOHandler)

Returns:
a preconfigured handler that can read to and write from graph instances. created by createRoundtripGraph().

configureHandler

protected void configureHandler(GraphMLLayoutGraphIOHandler layoutGraphIOHandler)
Configures the provided handler. This method is called by createHandler() after the creation of the handler instance.

The default implementation adds input and output handlers for graph item layout and style data and for custom mapper attributes.

Parameters:
layoutGraphIOHandler - the handler to configure
See Also:
setDocumentFragmentMode(boolean), setMapLabelModels(boolean)

createSharedDataOuputHandler

protected SharedDataOutputHandler createSharedDataOuputHandler()
Create the output handler that writes shared elements.


sendGraph

public void sendGraph(Graph graph,
                      javax.servlet.http.HttpServletResponse response)
               throws IOException
Description copied from class: AbstractGraphRoundtripSupport
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".

Specified by:
sendGraph in class AbstractGraphRoundtripSupport
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 void sendGraph(Graph graph,
                      OutputStream os,
                      String outputEncoding)
               throws IOException
Description copied from class: AbstractGraphRoundtripSupport
Writes the current graph to the stream in GraphML format using the provided encoding. This method will not close the stream.

Specified by:
sendGraph in class AbstractGraphRoundtripSupport
Parameters:
graph - The current graph.
os - The stream to write the graph to.
Throws:
IOException - If something goes wrong during GraphML export.

createRoundtripGraph

public LayoutGraph createRoundtripGraph()
Creates the graph that should be used for roundtripping. This method registers various DataMap instances with the graph instance using the key constants provided by this class.

Specified by:
createRoundtripGraph in class AbstractGraphRoundtripSupport
Returns:
an instance that can be used for reading and writing graphs.

configureRoundtripGraph

protected void configureRoundtripGraph(LayoutGraph layoutGraph)
Description copied from class: AbstractGraphRoundtripSupport
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 AbstractGraphRoundtripSupport.addMapper(Object, String, int, int).

Overrides:
configureRoundtripGraph in class AbstractGraphRoundtripSupport
Parameters:
layoutGraph - the layout graph instance that is used for roundtripping.


Copyright © 2000-2007 yWorks GmbH. All rights reserved