As discussed in Chapter 6, Using yFiles FLEX with a yFiles Server, the yFiles FLEX client can
communicate with a yFiles Java server either using the yFiles FLEX native
GraphML extension or using a compatibility mode for the yFiles Java GraphML format.
Depending on the chosen format for client-server communication, either class
GraphRoundtripSupport
or class Graph2DRoundtripSupport
should be used on the server for client-server roundtrips.
Similar to class RoundtripHandler in the yFiles FLEX client API, the roundtrip support classes offered by the server API make it easy to deserialize GraphML data that was sent from the client and to send a serialized graph instance back to the client. Before a response is sent, any kind of modification can be applied to the graph using the yFiles Java API.
Class
AbstractGraphRoundtripSupport
is the abstract base class of both default roundtrip support classes provided by
the server library. It defines the functionality that is common for both
roundtrip support classes.
API Excerpt 7.1, “AbstractGraphRoundtripSupport graph reading and writing” lists the basic methods of the roundtrip support classes for deserializing GraphML data send from the client into a Graph instance and for sending the serialized Graph instance back to the client.
API Excerpt 7.1. AbstractGraphRoundtripSupport graph reading and writing
// Populate the given graph using the GraphML data passed as a parameter of the // given request. boolean readGraph(HttpServletRequest request, Graph graph) // Send the given graph instance as GraphML data using the given response. void sendGraph(Graph graph, HttpServletResponse response)
Custom graph item attributes can be easily added for (de)serialization as shown in API Excerpt 7.2, “Adding Simple Attributes”. Adding custom graph item attributes for client-server roundtrips is discussed in detail in the corresponding knowledge base article.
API Excerpt 7.2. Adding Simple Attributes
// Add a custom attribute for GraphML (de)serialization void addMapper(Object tag, String name, int graphMLType, int graphMLScope)
The methods listed in API Excerpt 7.3, “Configuring the roundtrip graph instance” can be used to create and configure the graph instance that is populated with the graph structure received from the client.
If the native yFiles FLEX GraphML extension is used for client-server communication,
a LayoutGraph
instance should be used
as the graph model on the server.
To create and configure a LayoutGraph instance and to (de)serialize the LayoutGraph
instance to/from GraphML data, the server library offers class
GraphRoundtripSupport
.
GraphML serialization and deserialization of Graph instances can be controlled by overriding the protected methods of GraphRoundtripSupport listed in API Excerpt 7.4, “Protected methods of GraphRoundtripSupport”.
API Excerpt 7.4. Protected methods of GraphRoundtripSupport
// Configure the I/O handler for reading and writing Graph instances protected void configureHandler( GraphMLLayoutGraphIOHandler layoutGraphIOHandler) // Create the I/O handler instance for reading and writing graph instances. protected GraphMLLayoutGraphIOHandler createHandler() // Create the SerializerRegistry that stores all IDeserializer // and ISerializer instances used for reading and writing the graph. // This factory method can be overriden in order to register // custom ISerializer and IDeserializer instances. protected SerializerRegistry createSerializerRegistry()
API Excerpt 7.5, “Automatic label model conversion” shows the GraphRoundtripSupport option for automatic label model conversion. If setMapLabelModels is set to true, the I/O mechanism will try to convert between the client and yFiles Java label models. For edge labels, the conversion is possible for the slider- and free label models. Node label position can be mapped if the discrete node label model is used (exterior or interior node label model on the client).
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.
The position information can also be comitted before, using method
commitLabelLayouts(y.layout.LayoutGraph)
.
If the yFiles Java GraphML extension is chosen for client-server communication, a
a Graph2D
instance will be used on the server
to create and modifiy the graph structure and graph visualization information.
Class
Graph2DRoundtripSupport
conveniently creates and configures a Graph2D instance for this purpose.
GraphML serialization and deserialization of Graph2D instances can be controlled by overriding the protected methods of Graph2DRoundtripSupport listed in API Excerpt 7.6, “Protected methods of Graph2DRoundtripSupport”.
API Excerpt 7.6. Protected methods of Graph2DRoundtripSupport
// Configure the I/O handler for reading and writing Graph2D instances protected void configureHandler( GraphMLIOHandler ioHandler) // Create the I/O handler instance for reading and writing Graph2D instances. protected GraphMLIOHandler createHandler()
|
Copyright ©2007-2008, yWorks GmbH. All rights reserved. |