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 java.lang.Object

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


Field Summary
static java.lang.String EDGE_2_ID_DPKEY
          Key for storing the current edge id EdgeMap in the graph.
protected  java.util.List mappers
           
static java.lang.String NODE_2_ID_DPKEY
          Key for storing the current node id NodeMap in the graph.
protected  java.util.List objectMappers
           
static java.lang.String PARAM_GRAPH
          Parameter name of the request parameter that contains graphml sent by the client.
static java.lang.String RESPONSE_DOCUMENT_TAG
          The xml element name that is used as the outermost tag for all non-graphml server responses.
static java.lang.String USERTAGS_DPKEY
          Key for storing the current user tag map in the graph
 
Constructor Summary
AbstractGraphRoundtripSupport()
           
 
Method Summary
 void addMapper(java.lang.Object tag, java.lang.String name, KeyType valueType, KeyScope scope)
          Adds integrated support for the round tripping of simple data associated with graph elements.
 void addObjectMapper(java.lang.Object tag, KeyScope scope, SerializationHandler serializer, DeserializationHandler deserializer)
          Adds integrated support for the round tripping of complex data associated with graph elements.
protected  void configureRoundtripGraph(LayoutGraph layoutGraph)
          Configure the layout graph.
protected  InputHandlerProvider createAutoMapperInputHandlerProvider()
           
protected  OutputHandlerProvider createAutoMapperOutputHandlerProvider()
           
protected static ParseEventListener createDefaultElementTagWrapper()
           
protected  InputHandlerProvider createInputHandlerProvider(java.lang.String name, java.lang.Object tag, KeyScope scope, KeyType type, boolean autoCreateDataMap)
          Creates a provider providing an InputHandler for the given name, scope and type that stores the parsed data in a data map with the given tag.
protected  InputHandlerProvider createObjectInputHandlerProvider(java.lang.String name, java.lang.Object tag, KeyScope scope, DeserializationHandler deserializer, boolean autoCreateDataMap)
          Creates a provider providing an InputHandler for the given name and scope that stores the parsed data in a data map with the given tag.
protected  OutputHandlerProvider createObjectOutputHandlerProvider(java.lang.String name, java.lang.Object tag, KeyScope scope, SerializationHandler serializer)
          Creates a provider providing an output handler for the given name and scope.
protected  OutputHandlerProvider createOutputHandlerProvider(java.lang.String name, java.lang.Object tag, KeyScope scope, KeyType type)
          Creates a provider providing an output handler for the given name and scope.
abstract  LayoutGraph createRoundtripGraph()
          Creates the graph that should be used for round tripping.
protected  InputHandlerProvider createTagInputHandlerProvider()
          Creates a new input handler provider instance that provides an input handler which handles user tags.
protected  OutputHandler createTagOutputHandler()
          Creates a new output handler instance which handles user tags.
 XmlWriter createXmlWriter(java.io.OutputStream os)
          Creates 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.
protected  InputHandlerProvider getTagInputHandlerProvider()
          Returns the input handler provider for the user tags.
protected  OutputHandler getTagOutputHandler()
          Returns the output handler for the user tags.
 boolean isSupportUserTags()
          Whether to support user tags.
abstract  boolean readGraph(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(java.io.InputStream is, Graph graph)
          Reads the graph from the given stream using the current handler.
abstract  void readGraph(java.net.URL url, Graph graph)
          Reads the graph from the given url using the current handler.
 void sendError(java.lang.String message, HttpServletResponse response)
          Send an error to the client.
 void sendError(java.lang.Throwable e, ServletOutputStream outputStream)
          Send an error to the client.
abstract  void sendGraph(Graph graph, HttpServletResponse response)
          Send the current graph to the client in GraphML format using UTF-8 encoding.
abstract  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 setSupportUserTags(boolean supportUserTags)
          Whether to support user tags.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mappers

protected java.util.List mappers

objectMappers

protected java.util.List objectMappers

NODE_2_ID_DPKEY

public static final java.lang.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 java.lang.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 java.lang.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 java.lang.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

USERTAGS_DPKEY

public static final java.lang.String USERTAGS_DPKEY
Key for storing the current user tag map in the graph

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.


readGraph

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

readGraph

public abstract boolean readGraph(HttpServletRequest request,
                                  Graph graph)
                           throws java.io.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/zlib/encodeURIComponent".

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

readGraph

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

sendGraph

public abstract void sendGraph(Graph graph,
                               HttpServletResponse response)
                        throws java.io.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:
java.io.IOException - If something goes wrong during GraphML export.

sendGraph

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

createRoundtripGraph

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

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

addMapper

public void addMapper(java.lang.Object tag,
                      java.lang.String name,
                      KeyType valueType,
                      KeyScope scope)
Adds integrated support for the round tripping of simple 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.
valueType - A KeyType describing the type of the data.
scope - A KeyScope describing the scope of the data.

addObjectMapper

public void addObjectMapper(java.lang.Object tag,
                            KeyScope scope,
                            SerializationHandler serializer,
                            DeserializationHandler deserializer)
Adds integrated support for the round tripping of complex 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) .
scope - A KeyScope describing the scope of the data.
serializer - The serializer instance that will be used for writing the complex data objects.
deserializer - The deserializer instance that will be used for reading the complex data objects.

createXmlWriter

public XmlWriter createXmlWriter(java.io.OutputStream os)
                          throws GraphMLWriteException
Creates 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
Throws:
GraphMLWriteException

sendError

public void sendError(java.lang.Throwable e,
                      ServletOutputStream outputStream)
               throws java.io.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:
java.io.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 round tripping and the data providers for any custom mappers that were added using addMapper(Object, String,y.io.graphml.KeyType,y.io.graphml.KeyScope) and addObjectMapper(Object, y.io.graphml.KeyScope, y.io.graphml.output.SerializationHandler, y.io.graphml.input.DeserializationHandler).

Parameters:
layoutGraph - The layout graph instance that is used for round tripping.

sendError

public void sendError(java.lang.String message,
                      HttpServletResponse response)
               throws java.io.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:
java.io.IOException - If writing to the response writer fails.

isSupportUserTags

public boolean isSupportUserTags()
Whether to support user tags.

Returns:
true if user tags will be read / sent.

setSupportUserTags

public void setSupportUserTags(boolean supportUserTags)
Whether to support user tags.

Default is false

Parameters:
supportUserTags - true if user tags will be read / sent.

getTagInputHandlerProvider

protected InputHandlerProvider getTagInputHandlerProvider()
Returns the input handler provider for the user tags.

Calls createTagInputHandlerProvider() to create a new instance if needed.

Returns:
The user tags input handler provider.

createTagInputHandlerProvider

protected InputHandlerProvider createTagInputHandlerProvider()
Creates a new input handler provider instance that provides an input handler which handles user tags.

Returns:
A new input handler provider for an input handler which handles user tags.

getTagOutputHandler

protected OutputHandler getTagOutputHandler()
Returns the output handler for the user tags.

Calls createTagOutputHandler() to create a new instance if needed.

Returns:
The user tags output handler.

createTagOutputHandler

protected OutputHandler createTagOutputHandler()
Creates a new output handler instance which handles user tags.

Returns:
A new output handler which handles user tags.

createInputHandlerProvider

protected InputHandlerProvider createInputHandlerProvider(java.lang.String name,
                                                          java.lang.Object tag,
                                                          KeyScope scope,
                                                          KeyType type,
                                                          boolean autoCreateDataMap)
Creates a provider providing an InputHandler for the given name, scope and type that stores the parsed data in a data map with the given tag.

Parameters:
name - The attr.name attribute of the graphml key definition.
tag - Tha data provider tag.
scope - The scope the input handler provider shall provide an input handler for.
type - The type the input handler provider shall provide an input handler for.
autoCreateDataMap - Whether a DataMap shall be created and added to the graph if there is none registered by the given tag.
Returns:
A provider providing an input handler for the given name, scope and type that stores the parsed data in a data map with the given tag.

createObjectInputHandlerProvider

protected InputHandlerProvider createObjectInputHandlerProvider(java.lang.String name,
                                                                java.lang.Object tag,
                                                                KeyScope scope,
                                                                DeserializationHandler deserializer,
                                                                boolean autoCreateDataMap)
Creates a provider providing an InputHandler for the given name and scope that stores the parsed data in a data map with the given tag. The given deserializer is used to parse the data elements.

Parameters:
name - The attr.name attribute of the graphml key definition.
tag - Tha data provider tag.
scope - The scope the input handler provider shall provide an input handler for.
deserializer -
autoCreateDataMap - Whether a DataMap shall be created and added to the graph if there is none registered by the given tag.
Returns:
A provider providing an input handler for the given name and scope that stores the parsed data in a data map with the given tag.

createOutputHandlerProvider

protected OutputHandlerProvider createOutputHandlerProvider(java.lang.String name,
                                                            java.lang.Object tag,
                                                            KeyScope scope,
                                                            KeyType type)
Creates a provider providing an output handler for the given name and scope. The data is retrieved from a data provider that has to be registered at the graph with the given tag and serialized using the given serializer.

Parameters:
name - The attr.name to use for the written key element.
tag - The tag the data is registered at the graph with.
scope - The scope the data shall be written for.
type - The type of the data to write.
Returns:
A provider providing an output handler for the given name and scope.

createObjectOutputHandlerProvider

protected OutputHandlerProvider createObjectOutputHandlerProvider(java.lang.String name,
                                                                  java.lang.Object tag,
                                                                  KeyScope scope,
                                                                  SerializationHandler serializer)
Creates a provider providing an output handler for the given name and scope. The data is retrieved from a data provider that has to be registered at the graph with the given tag and serialized using the given serializer.

Parameters:
name - The attr.name to use for the written key element.
tag - The tag the data is registered at the graph with.
scope - The scope the data shall be written for.
serializer - The SerializationHandler used to write each data.
Returns:
A provider providing an output handler for the given name and scope.

createAutoMapperOutputHandlerProvider

protected OutputHandlerProvider createAutoMapperOutputHandlerProvider()

createAutoMapperInputHandlerProvider

protected InputHandlerProvider createAutoMapperInputHandlerProvider()

createDefaultElementTagWrapper

protected static ParseEventListener createDefaultElementTagWrapper()


Copyright © 2000-2007 yWorks GmbH. All rights reserved