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

java.lang.Object
  extended bycom.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
      extended bycom.yworks.yfiles.server.graphml.support.GraphRoundtripSupportBase
All Implemented Interfaces:
RoundtripSupport
Direct Known Subclasses:
GraphRoundtripSupport

public class GraphRoundtripSupportBase
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.


Nested Class Summary
static class GraphRoundtripSupportBase.RoundtripGraphMLLayoutGraphIOHandler
          A special GraphML I/O handler implementation that adds support for roundtrips with a yFiles FLEX client.
 
Field Summary
static java.lang.String EDGE_LABELS_DPKEY
          The DataMap key that is used to bind Lists of yFiles FLEX client compatibility Label instances.
static java.lang.String EDGE_SOURCE_PORT_DPKEY
          The DataMap key that is used to bind a yFiles FLEX client compatibility Port instance for the source port of an edge.
static java.lang.String EDGE_STYLE_DPKEY
          The DataMap key that is used to bind the yFiles FLEX client compatibility IEdgeStyle instances.
static java.lang.String EDGE_TARGET_PORT_DPKEY
          The DataMap key that is used to bind a yFiles FLEX client compatibility Port instance for the target port of an edge.
static java.lang.String EDGE_Z_ORDER_DPKEY
          The DataMap key that is used to bind the z-order for edges used on a yFiles FLEX client.
static java.lang.String NODE_LABELS_DPKEY
          The DataMap key that is used to bind Lists of yFiles FLEX client compatibility Label instances.
static java.lang.String NODE_PORTS_DPKEY
          The DataMap key that is used to bind Lists of yFiles FLEX client compatibility Port instances.
static java.lang.String NODE_STYLE_DPKEY
          The DataMap key that is used to bind the yFiles FLEX client compatibility INodeStyle instances.
static java.lang.String NODE_Z_ORDER_DPKEY
          The DataMap key that is used to bind the z-order for nodes used on a yFiles FLEX client.
static java.lang.String SHARED_DATA_DPKEY
           
static java.lang.String TABLE_DPKEY
          The DataMap key that is used to bind tables to nodes used on a yFiles FLEX client.
 
Fields inherited from class com.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
EDGE_2_ID_DPKEY, mappers, NODE_2_ID_DPKEY, objectMappers, PARAM_GRAPH, RESPONSE_DOCUMENT_TAG, USERTAGS_DPKEY
 
Constructor Summary
GraphRoundtripSupportBase()
           
 
Method Summary
 void addDeserializer(DeserializationHandler deserializer)
          Add a deserializer instance that will be registered with the GraphMLHandler in addRegisteredHandlers(y.io.graphml.GraphMLHandler).
protected  void addRegisteredHandlers(GraphMLHandler handler)
          All default SerializationHandler and DeserializationHandler instances as well as those added via addSerializer(y.io.graphml.output.SerializationHandler) or addDeserializer(y.io.graphml.input.DeserializationHandler) are added to the handler for reading and writing the yFiles FLEX client's GraphML format.
 void addSerializer(SerializationHandler serializer)
          Add a serializer instance that will be registered with the GraphMLHandler in addRegisteredHandlers(y.io.graphml.GraphMLHandler).
protected  void configureHandler(GraphMLLayoutGraphIOHandler handler)
          Configures the provided handler.
protected  void configureRoundtripGraph(LayoutGraph layoutGraph)
          Called by createRoundtripGraph() to configure the created graph instance.
protected  GraphMLLayoutGraphIOHandler createHandler()
          Creates the handler that will be used for the IO.
 LayoutGraph createRoundtripGraph()
          Creates the graph that should be used for the roundtrip.
protected  SharedDataOutputHandler createSharedDataOutputHandler()
          Create the output handler that writes shared elements.
 YDimension getDefaultNodeSize()
          The default node size that will be used for newly created nodes of a layout graph that has been created using createRoundtripGraph().
 GraphMLVersion getGraphMLVersion()
          The version string that will be used for writing the version attribute of the GraphML element.
 ISharedInstanceProvider getSharedInstanceProvider()
           
 boolean isAutoReadMapperData()
          Whether mapped data contained in the GraphML data should be automatically deserialized to a data map and registered with the graph.
 boolean isAutoWriteMapperData()
          Whether mapped data registered with the graph as a data provider should be automatically serialized.
 boolean isCommitPortLocations()
          Whether the location of the edges' end points is committed to the edges' source and target ports when writing the graph.
 boolean isDocumentFragmentMode()
          Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments.
 boolean isFoldingEnabled()
          Whether support for folded graphs is enabled.
 boolean isIgnoreMissingDeserializer()
          Returns whether to ignore if no DeserializationHandler can be found during parsing.
 boolean isLocalViewMode()
          If folding is enabled, this property determines whether only the current expanded/collapsed state is sent to the client, instead of the complete model.
 boolean isMapLabelModels()
          Whether client-side label models will be mapped to server-side label models when reading and vice-verse when writing the graph.
 boolean isParseGraphMLVersion()
          Whether to set the graphMLVersionString property to the last parsed version String, thus always writing the GraphML version string that was most recently parsed.
 boolean isSupportTables()
          Whether to support tables.
 boolean isSupportZOrder()
          Whether to support z-orders of graph elements automatically.
 void readGraph(java.io.InputStream is, Graph graph)
          Reads the graph from the given stream using the current handler.
 void readGraph(java.net.URL url, Graph graph)
          Reads the graph from the given url using the current handler.
 void sendGraph(Graph graph, java.io.OutputStream os, java.lang.String outputEncoding)
          Writes the current graph to the stream in GraphML format using the provided encoding.
 void setAutoReadMapperData(boolean autoReadMapperData)
          Set whether mapped data contained in the GraphML data should be automatically deserialized to a data map and registered with the graph.
 void setAutoWriteMapperData(boolean autoWriteMapperData)
          Set whether mapped data registered with the graph as a data provider should be automatically serialized.
 void setCommitPortLocations(boolean commitPortLocations)
          Whether the location of the edges' end points is committed to the edges' source and target ports when writing the graph.
 void setDefaultNodeSize(YDimension defaultNodeSize)
          Deprecated. Use StyledLayoutGraph and it's StyledLayoutGraph.setDefaultNodeSize(y.geom.YDimension) method instead.
 void setDocumentFragmentMode(boolean documentFragmentMode)
          Whether the style and label elements sent from the client will be parsed into and written from DocumentFragments.
 void setFoldingEnabled(boolean foldingEnabled)
          Whether support for folded graphs is enabled.
 void setGraphMLVersion(GraphMLVersion graphMLVersion)
          Set the version string that will be used for writing the version attribute of the GraphML element.
 void setIgnoreMissingDeserializer(boolean ignoreMissingDeserializer)
          Sets whether to ignore if no DeserializationHandler can be found during parsing.
 void setLocalViewMode(boolean localViewMode)
          If folding is enabled, this property determines whether only the current expanded/collapsed state is sent to the client, instead of the complete model.
 void setMapLabelModels(boolean mapLabelModels)
          Set whether the IO should be configured to map client-side label models to server-side label models.
 void setParseGraphMLVersion(boolean parseGraphMLVersion)
          Whether to set the graphMLVersion property to the last parsed version String, thus always writing the GraphML version string that was most recently parsed.
 void setSharedInstanceProvider(ISharedInstanceProvider sharedInstanceProvider)
           
 void setSupportTables(boolean supportTables)
          Whether to support tables.
 void setSupportZOrder(boolean supportZOrder)
          Set whether to support z-orders of graph elements automatically.
 
Methods inherited from class com.yworks.yfiles.server.graphml.support.AbstractGraphRoundtripSupport
addMapper, addObjectMapper, createAutoMapperInputHandlerProvider, createAutoMapperOutputHandlerProvider, createDefaultElementTagWrapper, createInputHandlerProvider, createObjectInputHandlerProvider, createObjectOutputHandlerProvider, createOutputHandlerProvider, createTagInputHandlerProvider, createTagOutputHandler, createXmlWriter, getGraphDecoder, getTagInputHandlerProvider, getTagOutputHandler, isSupportUserTags, sendError, setSupportUserTags
 
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 java.lang.String NODE_STYLE_DPKEY
The DataMap key that is used to bind the yFiles FLEX client compatibility 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 java.lang.String EDGE_STYLE_DPKEY
The DataMap key that is used to bind the yFiles FLEX client compatibility 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 java.lang.String NODE_LABELS_DPKEY
The DataMap key that is used to bind Lists of yFiles FLEX client compatibility Label instances.

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

See Also:
isDocumentFragmentMode(), Constant Field Values

NODE_PORTS_DPKEY

public static final java.lang.String NODE_PORTS_DPKEY
The DataMap key that is used to bind Lists of yFiles FLEX client compatibility Port instances.

See Also:
Constant Field Values

EDGE_LABELS_DPKEY

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

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

See Also:
isDocumentFragmentMode(), Constant Field Values

EDGE_SOURCE_PORT_DPKEY

public static final java.lang.String EDGE_SOURCE_PORT_DPKEY
The DataMap key that is used to bind a yFiles FLEX client compatibility Port instance for the source port of an edge.

See Also:
Constant Field Values

EDGE_TARGET_PORT_DPKEY

public static final java.lang.String EDGE_TARGET_PORT_DPKEY
The DataMap key that is used to bind a yFiles FLEX client compatibility Port instance for the target port of an edge.

See Also:
Constant Field Values

NODE_Z_ORDER_DPKEY

public static final java.lang.String NODE_Z_ORDER_DPKEY
The DataMap key that is used to bind the z-order for nodes used on a yFiles FLEX client.

See Also:
Constant Field Values

EDGE_Z_ORDER_DPKEY

public static final java.lang.String EDGE_Z_ORDER_DPKEY
The DataMap key that is used to bind the z-order for edges used on a yFiles FLEX client.

See Also:
Constant Field Values

TABLE_DPKEY

public static final java.lang.String TABLE_DPKEY
The DataMap key that is used to bind tables to nodes used on a yFiles FLEX client.

This map is meant to handle tables if no styles are intended to be sent to the client. If styles are sent to the client, too, and the tables are bound to the nodes via a style which implements ITableProvider it is recommended not to use this map but the table provider instead.

See Also:
Constant Field Values

SHARED_DATA_DPKEY

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

GraphRoundtripSupportBase

public GraphRoundtripSupportBase()
Method Detail

isFoldingEnabled

public boolean isFoldingEnabled()
Whether support for folded graphs is enabled.

If folding support is enabled, a FoldedLayoutGraph instance will be created by createRoundtripGraph(), and the GraphML I/O support will be configured accordingly.


setFoldingEnabled

public void setFoldingEnabled(boolean foldingEnabled)
Whether support for folded graphs is enabled.

If folding support is enabled, a FoldedLayoutGraph instance will be created by createRoundtripGraph(), and the GraphML I/O support will be configured accordingly.


isLocalViewMode

public boolean isLocalViewMode()
If folding is enabled, this property determines whether only the current expanded/collapsed state is sent to the client, instead of the complete model.


setLocalViewMode

public void setLocalViewMode(boolean localViewMode)
If folding is enabled, this property determines whether only the current expanded/collapsed state is sent to the client, instead of the complete model.


isAutoReadMapperData

public boolean isAutoReadMapperData()
Whether mapped data contained in the GraphML data should be automatically deserialized to a data map and registered with the graph.

Note that deserialization of complex data will only work if an appropriate DeserializationHandler instance is registered.

The default value is true.


setAutoReadMapperData

public void setAutoReadMapperData(boolean autoReadMapperData)
Set whether mapped data contained in the GraphML data should be automatically deserialized to a data map and registered with the graph.

Note that deserialization of complex data will only work if an appropriate DeserializationHandler instance is registered.


isAutoWriteMapperData

public boolean isAutoWriteMapperData()
Whether mapped data registered with the graph as a data provider should be automatically serialized.

Note that serialization of complex data will only work if an appropriate SerializationHandler instance is registered.

The default value is true.


setAutoWriteMapperData

public void setAutoWriteMapperData(boolean autoWriteMapperData)
Set whether mapped data registered with the graph as a data provider should be automatically serialized.

Note that serialization of complex data will only work if an appropriate SerializationHandler instance is registered.


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 createSharedDataOutputHandler(). The position information can also be committed 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 mapped to server-side label models when reading and vice-verse when writing the graph.

See Also:
setMapLabelModels(boolean)

isCommitPortLocations

public boolean isCommitPortLocations()
Whether the location of the edges' end points is committed to the edges' source and target ports when writing the graph.


setCommitPortLocations

public void setCommitPortLocations(boolean commitPortLocations)
Whether the location of the edges' end points is committed to the edges' source and target ports when writing the graph.


isSupportZOrder

public boolean isSupportZOrder()
Whether to support z-orders of graph elements automatically.

If enabled, z-order values for nodes, edges and ports are (de)serialized automatically if possible, by means of associated GraphML handlers.


setSupportZOrder

public void setSupportZOrder(boolean supportZOrder)
Set whether to support z-orders of graph elements automatically.

If enabled, z-order values for nodes, edges and ports are (de)serialized automatically if possible, by means of associated GraphML handlers.


isSupportTables

public boolean isSupportTables()
Whether to support tables.

Default is false.

Returns:
true, if tables are supported.

setSupportTables

public void setSupportTables(boolean supportTables)
Whether to support tables.

If enabled the styles are in a DataMap with the key TABLE_DPKEY. This map is meant to handle tables if no styles are intended to be sent to the client. If styles are sent to the client, too, and the tables are bound to the nodes via a style which implements ITableProvider (e.g. TableNodeStyle) it is recommended to disable this property and use the table provider instead.

Default is false.

Parameters:
supportTables - true, if tables are supported.

isIgnoreMissingDeserializer

public boolean isIgnoreMissingDeserializer()
Returns whether to ignore if no DeserializationHandler can be found during parsing.

If true a FallbackDeserializer is used in the case of a missing deserializer that prevents a parse error by deserializing the element to null.
Otherwise, a DeserializationNotSupportedException is thrown.


setIgnoreMissingDeserializer

public void setIgnoreMissingDeserializer(boolean ignoreMissingDeserializer)
Sets whether to ignore if no DeserializationHandler can be found during parsing.

If true a FallbackDeserializer is used in the case of a missing deserializer that prevents a parse error by deserializing the element to null.
Otherwise, a DeserializationNotSupportedException is thrown.


addSerializer

public void addSerializer(SerializationHandler serializer)
Add a serializer instance that will be registered with the GraphMLHandler in addRegisteredHandlers(y.io.graphml.GraphMLHandler).

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

addDeserializer

public void addDeserializer(DeserializationHandler deserializer)
Add a deserializer instance that will be registered with the GraphMLHandler in addRegisteredHandlers(y.io.graphml.GraphMLHandler).

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

addRegisteredHandlers

protected void addRegisteredHandlers(GraphMLHandler handler)
All default SerializationHandler and DeserializationHandler instances as well as those added via addSerializer(y.io.graphml.output.SerializationHandler) or addDeserializer(y.io.graphml.input.DeserializationHandler) are added to the handler for reading and writing the yFiles FLEX client's GraphML format. This method is called by configureHandler(GraphMLLayoutGraphIOHandler).

Parameters:
handler - The handler to add the SerializationHandler and DeserializationHandler.

readGraph

public void readGraph(java.io.InputStream is,
                      Graph graph)
               throws java.io.IOException
Description copied from interface: RoundtripSupport
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:
java.io.IOException - if an io exception occurred.

readGraph

public void readGraph(java.net.URL url,
                      Graph graph)
               throws java.io.IOException
Description copied from interface: RoundtripSupport
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:
java.io.IOException - if an io exception occurred.

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, calls configureHandler(GraphMLLayoutGraphIOHandler) and finally adds an input handler provider that automatically reads mapped data contained in the GraphML data if isAutoReadMapperData() is true.

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

configureHandler

protected void configureHandler(GraphMLLayoutGraphIOHandler handler)
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:
handler - the handler to configure
See Also:
setDocumentFragmentMode(boolean), setMapLabelModels(boolean)

createSharedDataOutputHandler

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


sendGraph

public void sendGraph(Graph graph,
                      java.io.OutputStream os,
                      java.lang.String outputEncoding)
               throws java.io.IOException
Description copied from interface: RoundtripSupport
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:
java.io.IOException - If something goes wrong during GraphML export.

createRoundtripGraph

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

If isFoldingEnabled() returns true a new instance of FoldedLayoutGraph is created otherwise a StyledLayoutGraph instance is used. As FoldedLayoutGraph is a subclass of StyledLayoutGraph the returned LayoutGraph can usually be safely cast to StyledLayoutGraph. Afterwards configureRoundtripGraph(LayoutGraph) is called to configure the created graph instance.

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

getDefaultNodeSize

public YDimension getDefaultNodeSize()
The default node size that will be used for newly created nodes of a layout graph that has been created using createRoundtripGraph(). The default value is 30,30.

Returns:
The default node size

setDefaultNodeSize

public void setDefaultNodeSize(YDimension defaultNodeSize)
Deprecated. Use StyledLayoutGraph and it's StyledLayoutGraph.setDefaultNodeSize(y.geom.YDimension) method instead.

Set the default node size that will be used for newly created nodes of a layout graph that has been created using createRoundtripGraph().

Parameters:
defaultNodeSize - The default size that will be sued for new nodes.

configureRoundtripGraph

protected void configureRoundtripGraph(LayoutGraph layoutGraph)
Called by createRoundtripGraph() to configure the created graph instance. This method registers various DataMap instances with the graph instance using the key constants provided by this class.

Overrides:
configureRoundtripGraph in class AbstractGraphRoundtripSupport
Parameters:
layoutGraph - The layout graph instance that is used for round tripping.

getGraphMLVersion

public GraphMLVersion getGraphMLVersion()
The version string that will be used for writing the version attribute of the GraphML element. The default value is 1.3.

Returns:
The GraphML version string.
See Also:
setParseGraphMLVersion(boolean)

setGraphMLVersion

public void setGraphMLVersion(GraphMLVersion graphMLVersion)
Set the version string that will be used for writing the version attribute of the GraphML element. The default value is GraphMLVersion.ONE_POINT_THREE.

See Also:
setParseGraphMLVersion(boolean)

isParseGraphMLVersion

public boolean isParseGraphMLVersion()
Whether to set the graphMLVersionString property to the last parsed version String, thus always writing the GraphML version string that was most recently parsed. The default value is true.

Returns:
Whether to use the most recently parsed GraphML version string for writing.
See Also:
setGraphMLVersion(GraphMLVersion)

setParseGraphMLVersion

public void setParseGraphMLVersion(boolean parseGraphMLVersion)
Whether to set the graphMLVersion property to the last parsed version String, thus always writing the GraphML version string that was most recently parsed. The default value is true.

Parameters:
parseGraphMLVersion - Whether to parse the GraphML Version and set the graphMLVersion property to the most recently parsed value.
See Also:
setGraphMLVersion(GraphMLVersion)

getSharedInstanceProvider

public ISharedInstanceProvider getSharedInstanceProvider()

setSharedInstanceProvider

public void setSharedInstanceProvider(ISharedInstanceProvider sharedInstanceProvider)


Copyright © 2000-2013 yWorks GmbH. All rights reserved