The default implementation 1
For the construction of converters from any other graph exchange format to GXL it often can be useful to have a "tool" that outputs the resulting GXL file according to the incoming event stream. That's what the default implementation 1 does. The abstract class hierarchy is implemented in the way that a valid GXL file (of course only in the case that the event stream is valid) is output. All the user has to do is to
1 ) parse the source document
2 ) decide which construct of the source format shall be converted into which GXL construct
3 ) generate the right event stream for the GXLConnector
The default implementation 1 then automatically writes the GXL file. For more detailed information about how to write a converter from any other exchange format to GXL have a look at the chapter <...>2GXL.
You can furthermore take the default implementation 1 (and as well the default implementation 2) to get a first impression of how the abstract class hierarchy has to be implemented. To understand how the default implementation 1 works, the "strategy" of writing GXL files shall be shortly described.
If for example the GXL file
| <gxl> |
| <graph id = "A1"> |
| </graph> |
| </gxl> |
shall be output, the necessary event stream that has to be provided by the user is the following :
| GXLDocumentHandler | GXLConnector | ||
| 1 ) | startElement ("gxl") | --> | create ("gxl") |
| 2 ) | startElement ("graph") | --> | create ("graph") |
| 3 ) | attribute ("id", "A1", true) | --> | setAttributeValue ("id", "A1") |
| 4 ) | endElement ("graph") | --> | close ("graph") |
| 5 ) | endElement ("gxl") | --> | close ("gxl") |
When the GXLConnector gets this input, it generates the according method calls in the abstract class hierarchy. The generated method calls and the output they provide are shown in table 1.
| event nr. | method call(s) | output | ||
|
1 ) |
GXLGXLAPIImpl.createGXL() | <gxl | ||
| 2 ) | GXLGXLAPIImpl.createGraph() | >
|
||
| 3 ) | GXLGraphAPIImpl.setAttributeValue("id","A1") | id = "A1" | ||
| 4 ) | GXLGraphAPIImpl.close()
GXLGXLAPIImpl.closeGraph() --not implemented-- |
|
||
| 5 ) | GXLGXLAPIImpl.close() |
|
table 1 : Methods in the abstract class hierarchy and the provided output
This strategy, examplarily shown for the constructs gxl and graph, is used for all gxl constructs. The default implementation 1 is an example for the use of the method getCurrentDepth() in the GXLOutputAPI. It is used to format the output file (the white spaces before the graph tags). For the detailed source code, have a look at the source code section.