public class GraphMLReader<G extends edu.uci.ics.jung.graph.Hypergraph<V,E>,V,E>
extends org.xml.sax.helpers.DefaultHandler
data
graph, vertex, edge descriptions and data
descriptions
vertex and edge IDs
get
methods.
Does not currently support nested graphs or ports.
Note that the user is responsible for supplying a graph
Factory
that can support the edge types in the supplied
GraphML file. If the graph generated by the Factory
is
not compatible (for example: if the graph does not accept directed
edges, and the GraphML file contains a directed edge) then the results
are graph-implementation-dependent.
Modifier and Type | Class and Description |
---|---|
protected static class |
GraphMLReader.KeyType |
protected static class |
GraphMLReader.TagState |
Modifier and Type | Field and Description |
---|---|
protected E |
current_edge |
protected G |
current_graph |
protected java.lang.String |
current_key |
protected java.util.LinkedList<GraphMLReader.TagState> |
current_states |
protected java.lang.StringBuilder |
current_text |
protected V |
current_vertex |
protected edu.uci.ics.jung.graph.util.EdgeType |
default_edgetype |
protected java.util.Map<E,java.lang.String> |
edge_desc |
protected org.apache.commons.collections4.Factory<E> |
edge_factory |
protected org.apache.commons.collections4.BidiMap<E,java.lang.String> |
edge_ids |
protected java.util.Map<java.lang.String,GraphMLMetadata<E>> |
edge_metadata |
protected java.util.Map<G,java.lang.String> |
graph_desc |
protected org.apache.commons.collections4.Factory<G> |
graph_factory |
protected java.util.Map<java.lang.String,GraphMLMetadata<G>> |
graph_metadata |
protected java.util.List<G> |
graphs |
protected java.util.Collection<V> |
hyperedge_vertices |
protected GraphMLReader.KeyType |
key_type |
protected javax.xml.parsers.SAXParser |
saxp |
protected org.apache.commons.collections4.BidiMap<java.lang.String,GraphMLReader.TagState> |
tag_state |
protected java.util.Map<V,java.lang.String> |
vertex_desc |
protected org.apache.commons.collections4.Factory<V> |
vertex_factory |
protected org.apache.commons.collections4.BidiMap<V,java.lang.String> |
vertex_ids |
protected java.util.Map<java.lang.String,GraphMLMetadata<V>> |
vertex_metadata |
Constructor and Description |
---|
GraphMLReader()
Creates a
GraphMLReader instance that assigns the vertex
and edge id strings to be the vertex and edge objects,
as well as their IDs. |
GraphMLReader(org.apache.commons.collections4.Factory<V> vertex_factory,
org.apache.commons.collections4.Factory<E> edge_factory)
Creates a
GraphMLReader instance with the specified
vertex and edge factories. |
Modifier and Type | Method and Description |
---|---|
protected <T> void |
addDatum(java.util.Map<java.lang.String,GraphMLMetadata<T>> metadata,
T current_elt,
java.lang.String text) |
protected <T> void |
addExtraData(java.util.Map<java.lang.String,java.lang.String> atts,
java.util.Map<java.lang.String,GraphMLMetadata<T>> metadata_map,
T current_elt) |
protected void |
assignEdgeSourceTarget(E e,
org.xml.sax.Attributes atts,
java.util.Map<java.lang.String,java.lang.String> edge_atts) |
void |
characters(char[] ch,
int start,
int length) |
protected void |
clearData() |
protected void |
createEdge(org.xml.sax.Attributes atts,
GraphMLReader.TagState state) |
protected void |
createKey(org.xml.sax.Attributes atts) |
protected void |
createVertex(org.xml.sax.Attributes atts) |
void |
endElement(java.lang.String uri,
java.lang.String name,
java.lang.String qName) |
protected java.util.Map<java.lang.String,java.lang.String> |
getAttributeMap(org.xml.sax.Attributes atts) |
java.util.Map<E,java.lang.String> |
getEdgeDescriptions()
Returns a map from edges to edge descriptions.
|
org.apache.commons.collections4.BidiMap<E,java.lang.String> |
getEdgeIDs()
Returns a bidirectional map relating edges and IDs.
|
java.util.Map<java.lang.String,GraphMLMetadata<E>> |
getEdgeMetadata()
Returns a map from edge type name to type metadata.
|
java.util.Map<G,java.lang.String> |
getGraphDescriptions()
Returns a map from graphs to graph descriptions.
|
java.util.Map<java.lang.String,GraphMLMetadata<G>> |
getGraphMetadata()
Returns a map from graph type name to type metadata.
|
java.util.Map<V,java.lang.String> |
getVertexDescriptions()
Returns a map from vertices to vertex descriptions.
|
org.apache.commons.collections4.BidiMap<V,java.lang.String> |
getVertexIDs()
Returns a bidirectional map relating vertices and IDs.
|
java.util.Map<java.lang.String,GraphMLMetadata<V>> |
getVertexMetadata()
Returns a map from vertex type name to type metadata.
|
protected void |
handleData(org.xml.sax.Attributes atts) |
protected void |
initializeData()
This is separate from initialize() because these data structures are shared among all
graphs loaded (i.e., they're defined inside
graphml rather than graph . |
void |
load(java.io.Reader reader,
G g)
Populates the specified graph with the data parsed from the reader.
|
void |
load(java.lang.String filename,
G g)
Populates the specified graph with the data parsed from the specified file.
|
java.util.List<G> |
loadMultiple(java.io.Reader reader,
org.apache.commons.collections4.Factory<G> graph_factory)
Returns a list of the graphs parsed from the specified reader, as created by
the specified factory.
|
java.util.List<G> |
loadMultiple(java.lang.String filename,
org.apache.commons.collections4.Factory<G> graph_factory)
Returns a list of the graphs parsed from the specified file, as created by
the specified factory.
|
protected void |
parse(java.io.Reader reader) |
void |
startElement(java.lang.String uri,
java.lang.String name,
java.lang.String qName,
org.xml.sax.Attributes atts) |
protected javax.xml.parsers.SAXParser saxp
protected edu.uci.ics.jung.graph.util.EdgeType default_edgetype
protected V current_vertex
protected E current_edge
protected java.lang.String current_key
protected java.util.LinkedList<GraphMLReader.TagState> current_states
protected org.apache.commons.collections4.BidiMap<java.lang.String,GraphMLReader.TagState> tag_state
protected org.apache.commons.collections4.Factory<G extends edu.uci.ics.jung.graph.Hypergraph<V,E>> graph_factory
protected org.apache.commons.collections4.Factory<V> vertex_factory
protected org.apache.commons.collections4.Factory<E> edge_factory
protected org.apache.commons.collections4.BidiMap<V,java.lang.String> vertex_ids
protected org.apache.commons.collections4.BidiMap<E,java.lang.String> edge_ids
protected java.util.Map<java.lang.String,GraphMLMetadata<G extends edu.uci.ics.jung.graph.Hypergraph<V,E>>> graph_metadata
protected java.util.Map<java.lang.String,GraphMLMetadata<V>> vertex_metadata
protected java.util.Map<java.lang.String,GraphMLMetadata<E>> edge_metadata
protected java.util.Map<V,java.lang.String> vertex_desc
protected java.util.Map<E,java.lang.String> edge_desc
protected java.util.Map<G extends edu.uci.ics.jung.graph.Hypergraph<V,E>,java.lang.String> graph_desc
protected GraphMLReader.KeyType key_type
protected java.util.Collection<V> hyperedge_vertices
protected java.lang.StringBuilder current_text
public GraphMLReader(org.apache.commons.collections4.Factory<V> vertex_factory, org.apache.commons.collections4.Factory<E> edge_factory) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
GraphMLReader
instance with the specified
vertex and edge factories.vertex_factory
- the vertex factory to use to create vertex objectsedge_factory
- the edge factory to use to create edge objectsjavax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public GraphMLReader() throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
GraphMLReader
instance that assigns the vertex
and edge id
strings to be the vertex and edge objects,
as well as their IDs.
Note that this requires that (a) each edge have a valid ID, which is not
normally a requirement for edges in GraphML, and (b) that the vertex
and edge types be assignment-compatible with String
.javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public java.util.List<G> loadMultiple(java.io.Reader reader, org.apache.commons.collections4.Factory<G> graph_factory) throws java.io.IOException
java.io.IOException
public java.util.List<G> loadMultiple(java.lang.String filename, org.apache.commons.collections4.Factory<G> graph_factory) throws java.io.IOException
java.io.IOException
public void load(java.io.Reader reader, G g) throws java.io.IOException
java.io.IOException
public void load(java.lang.String filename, G g) throws java.io.IOException
java.io.IOException
protected void clearData()
protected void initializeData()
graphml
rather than graph
.protected void parse(java.io.Reader reader) throws java.io.IOException
java.io.IOException
public void startElement(java.lang.String uri, java.lang.String name, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXNotSupportedException
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXNotSupportedException
protected <T> void addExtraData(java.util.Map<java.lang.String,java.lang.String> atts, java.util.Map<java.lang.String,GraphMLMetadata<T>> metadata_map, T current_elt)
T
- atts
- metadata_map
- current_elt
- public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXNotSupportedException
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXNotSupportedException
protected <T> void addDatum(java.util.Map<java.lang.String,GraphMLMetadata<T>> metadata, T current_elt, java.lang.String text) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
public void endElement(java.lang.String uri, java.lang.String name, java.lang.String qName) throws org.xml.sax.SAXNotSupportedException
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXNotSupportedException
protected java.util.Map<java.lang.String,java.lang.String> getAttributeMap(org.xml.sax.Attributes atts)
protected void handleData(org.xml.sax.Attributes atts) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
protected void createKey(org.xml.sax.Attributes atts) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
protected void createVertex(org.xml.sax.Attributes atts) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
protected void createEdge(org.xml.sax.Attributes atts, GraphMLReader.TagState state) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
protected void assignEdgeSourceTarget(E e, org.xml.sax.Attributes atts, java.util.Map<java.lang.String,java.lang.String> edge_atts) throws org.xml.sax.SAXNotSupportedException
org.xml.sax.SAXNotSupportedException
public org.apache.commons.collections4.BidiMap<V,java.lang.String> getVertexIDs()
public org.apache.commons.collections4.BidiMap<E,java.lang.String> getEdgeIDs()
public java.util.Map<java.lang.String,GraphMLMetadata<G>> getGraphMetadata()
public java.util.Map<java.lang.String,GraphMLMetadata<V>> getVertexMetadata()
public java.util.Map<java.lang.String,GraphMLMetadata<E>> getEdgeMetadata()
public java.util.Map<G,java.lang.String> getGraphDescriptions()
public java.util.Map<V,java.lang.String> getVertexDescriptions()
public java.util.Map<E,java.lang.String> getEdgeDescriptions()