edu.uci.ics.jung.io
Class GraphMLReader<G extends Hypergraph<V,E>,V,E>

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by edu.uci.ics.jung.io.GraphMLReader<G,V,E>
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class GraphMLReader<G extends Hypergraph<V,E>,V,E>
extends DefaultHandler

Reads in data from a GraphML-formatted file and generates graphs based on that data. Currently supports the following parts of the GraphML specification:

Each of these is exposed via appropriate 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.

See Also:
"http://graphml.graphdrawing.org/specification.html"

Nested Class Summary
protected static class GraphMLReader.KeyType
           
protected static class GraphMLReader.TagState
           
 
Field Summary
protected  E current_edge
           
protected  G current_graph
           
protected  String current_key
           
protected  LinkedList<GraphMLReader.TagState> current_states
           
protected  V current_vertex
           
protected  EdgeType default_edgetype
           
protected  Map<E,String> edge_desc
           
protected  org.apache.commons.collections15.Factory<E> edge_factory
           
protected  org.apache.commons.collections15.BidiMap<E,String> edge_ids
           
protected  Map<String,GraphMLMetadata<E>> edge_metadata
           
protected  Map<G,String> graph_desc
           
protected  org.apache.commons.collections15.Factory<G> graph_factory
           
protected  Map<String,GraphMLMetadata<G>> graph_metadata
           
protected  List<G> graphs
           
protected  Collection<V> hyperedge_vertices
           
protected  GraphMLReader.KeyType key_type
           
protected  SAXParser saxp
           
protected  org.apache.commons.collections15.BidiMap<String,GraphMLReader.TagState> tag_state
           
protected  Map<V,String> vertex_desc
           
protected  org.apache.commons.collections15.Factory<V> vertex_factory
           
protected  org.apache.commons.collections15.BidiMap<V,String> vertex_ids
           
protected  Map<String,GraphMLMetadata<V>> vertex_metadata
           
 
Constructor Summary
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.collections15.Factory<V> vertex_factory, org.apache.commons.collections15.Factory<E> edge_factory)
          Creates a GraphMLReader instance with the specified vertex and edge factories.
 
Method Summary
protected
<T> void
addDatum(Map<String,GraphMLMetadata<T>> metadata, T current_elt, String text)
           
protected
<T> void
addExtraData(Map<String,String> atts, Map<String,GraphMLMetadata<T>> metadata_map, T current_elt)
           
protected  void assignEdgeSourceTarget(E e, Attributes atts, Map<String,String> edge_atts)
           
 void characters(char[] ch, int start, int length)
           
protected  void clearData()
           
protected  void createEdge(Attributes atts, GraphMLReader.TagState state)
           
protected  void createKey(Attributes atts)
           
protected  void createVertex(Attributes atts)
           
 void endElement(String uri, String name, String qName)
           
protected  Map<String,String> getAttributeMap(Attributes atts)
           
 Map<E,String> getEdgeDescriptions()
          Returns a map from edges to edge descriptions.
 org.apache.commons.collections15.BidiMap<E,String> getEdgeIDs()
          Returns a bidirectional map relating edges and IDs.
 Map<String,GraphMLMetadata<E>> getEdgeMetadata()
          Returns a map from edge type name to type metadata.
 Map<G,String> getGraphDescriptions()
          Returns a map from graphs to graph descriptions.
 Map<String,GraphMLMetadata<G>> getGraphMetadata()
          Returns a map from graph type name to type metadata.
 Map<V,String> getVertexDescriptions()
          Returns a map from vertices to vertex descriptions.
 org.apache.commons.collections15.BidiMap<V,String> getVertexIDs()
          Returns a bidirectional map relating vertices and IDs.
 Map<String,GraphMLMetadata<V>> getVertexMetadata()
          Returns a map from vertex type name to type metadata.
protected  void handleData(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(Reader reader, G g)
          Populates the specified graph with the data parsed from the reader.
 void load(String filename, G g)
          Populates the specified graph with the data parsed from the specified file.
 List<G> loadMultiple(Reader reader, org.apache.commons.collections15.Factory<G> graph_factory)
          Returns a list of the graphs parsed from the specified reader, as created by the specified factory.
 List<G> loadMultiple(String filename, org.apache.commons.collections15.Factory<G> graph_factory)
          Returns a list of the graphs parsed from the specified file, as created by the specified factory.
protected  void parse(Reader reader)
           
 void startElement(String uri, String name, String qName, Attributes atts)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

saxp

protected SAXParser saxp

default_edgetype

protected EdgeType default_edgetype

current_graph

protected G extends Hypergraph<V,E> current_graph

current_vertex

protected V current_vertex

current_edge

protected E current_edge

current_key

protected String current_key

current_states

protected LinkedList<GraphMLReader.TagState> current_states

tag_state

protected org.apache.commons.collections15.BidiMap<String,GraphMLReader.TagState> tag_state

graph_factory

protected org.apache.commons.collections15.Factory<G extends Hypergraph<V,E>> graph_factory

vertex_factory

protected org.apache.commons.collections15.Factory<V> vertex_factory

edge_factory

protected org.apache.commons.collections15.Factory<E> edge_factory

vertex_ids

protected org.apache.commons.collections15.BidiMap<V,String> vertex_ids

edge_ids

protected org.apache.commons.collections15.BidiMap<E,String> edge_ids

graph_metadata

protected Map<String,GraphMLMetadata<G extends Hypergraph<V,E>>> graph_metadata

vertex_metadata

protected Map<String,GraphMLMetadata<V>> vertex_metadata

edge_metadata

protected Map<String,GraphMLMetadata<E>> edge_metadata

vertex_desc

protected Map<V,String> vertex_desc

edge_desc

protected Map<E,String> edge_desc

graph_desc

protected Map<G extends Hypergraph<V,E>,String> graph_desc

key_type

protected GraphMLReader.KeyType key_type

hyperedge_vertices

protected Collection<V> hyperedge_vertices

graphs

protected List<G extends Hypergraph<V,E>> graphs
Constructor Detail

GraphMLReader

public GraphMLReader(org.apache.commons.collections15.Factory<V> vertex_factory,
                     org.apache.commons.collections15.Factory<E> edge_factory)
              throws ParserConfigurationException,
                     SAXException
Creates a GraphMLReader instance with the specified vertex and edge factories.

Parameters:
vertex_factory - the vertex factory to use to create vertex objects
edge_factory - the edge factory to use to create edge objects
Throws:
ParserConfigurationException
SAXException

GraphMLReader

public GraphMLReader()
              throws ParserConfigurationException,
                     SAXException
Creates a 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.

Throws:
ParserConfigurationException
SAXException
Method Detail

loadMultiple

public List<G> loadMultiple(Reader reader,
                            org.apache.commons.collections15.Factory<G> graph_factory)
                                             throws IOException
Returns a list of the graphs parsed from the specified reader, as created by the specified factory.

Throws:
IOException

loadMultiple

public List<G> loadMultiple(String filename,
                            org.apache.commons.collections15.Factory<G> graph_factory)
                                             throws IOException
Returns a list of the graphs parsed from the specified file, as created by the specified factory.

Throws:
IOException

load

public void load(Reader reader,
                 G g)
          throws IOException
Populates the specified graph with the data parsed from the reader.

Throws:
IOException

load

public void load(String filename,
                 G g)
          throws IOException
Populates the specified graph with the data parsed from the specified file.

Throws:
IOException

clearData

protected void clearData()

initializeData

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.


parse

protected void parse(Reader reader)
              throws IOException
Throws:
IOException

startElement

public void startElement(String uri,
                         String name,
                         String qName,
                         Attributes atts)
                  throws SAXNotSupportedException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class DefaultHandler
Throws:
SAXNotSupportedException

addExtraData

protected <T> void addExtraData(Map<String,String> atts,
                                Map<String,GraphMLMetadata<T>> metadata_map,
                                T current_elt)
Type Parameters:
T -
Parameters:
atts -
metadata_map -
current_elt -

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXNotSupportedException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXNotSupportedException

addDatum

protected <T> void addDatum(Map<String,GraphMLMetadata<T>> metadata,
                            T current_elt,
                            String text)
                 throws SAXNotSupportedException
Throws:
SAXNotSupportedException

endElement

public void endElement(String uri,
                       String name,
                       String qName)
                throws SAXNotSupportedException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class DefaultHandler
Throws:
SAXNotSupportedException

getAttributeMap

protected Map<String,String> getAttributeMap(Attributes atts)

handleData

protected void handleData(Attributes atts)
                   throws SAXNotSupportedException
Throws:
SAXNotSupportedException

createKey

protected void createKey(Attributes atts)
                  throws SAXNotSupportedException
Throws:
SAXNotSupportedException

createVertex

protected void createVertex(Attributes atts)
                     throws SAXNotSupportedException
Throws:
SAXNotSupportedException

createEdge

protected void createEdge(Attributes atts,
                          GraphMLReader.TagState state)
                   throws SAXNotSupportedException
Throws:
SAXNotSupportedException

assignEdgeSourceTarget

protected void assignEdgeSourceTarget(E e,
                                      Attributes atts,
                                      Map<String,String> edge_atts)
                               throws SAXNotSupportedException
Throws:
SAXNotSupportedException

getVertexIDs

public org.apache.commons.collections15.BidiMap<V,String> getVertexIDs()
Returns a bidirectional map relating vertices and IDs.


getEdgeIDs

public org.apache.commons.collections15.BidiMap<E,String> getEdgeIDs()
Returns a bidirectional map relating edges and IDs. This is not guaranteed to always be populated (edge IDs are not required in GraphML files.


getGraphMetadata

public Map<String,GraphMLMetadata<G>> getGraphMetadata()
Returns a map from graph type name to type metadata.


getVertexMetadata

public Map<String,GraphMLMetadata<V>> getVertexMetadata()
Returns a map from vertex type name to type metadata.


getEdgeMetadata

public Map<String,GraphMLMetadata<E>> getEdgeMetadata()
Returns a map from edge type name to type metadata.


getGraphDescriptions

public Map<G,String> getGraphDescriptions()
Returns a map from graphs to graph descriptions.


getVertexDescriptions

public Map<V,String> getVertexDescriptions()
Returns a map from vertices to vertex descriptions.


getEdgeDescriptions

public Map<E,String> getEdgeDescriptions()
Returns a map from edges to edge descriptions.



Copyright © 2009. All Rights Reserved.