Introduction to the XDI graph model

Markus Sabadello edited this page May 7, 2018 · 2 revisions


Clone this wiki locally

In XDI2, the XDI graph is modeled by a small set of Java interfaces in the xdi2-core component, which are implemented by a number of different backend storage mechanisms.

Interfaces and Classes


For an example, see:

To create a Graph, an instance of the GraphFactory interface is needed. The simplest GraphFactory is the MemoryGraphFactory, which provides in-memory storage. Example:

Graph graph = MemoryGraphFactory.getInstance().openGraph();

Some implementations of GraphFactory support parameters, e.g. the BDBKeyValueGraphFactory supports specifying the path to a BDB database that should be used for storage. Example:

BDBKeyValueGraphFactory graphFactory = new BDBKeyValueGraphFactory();
Graph graph = graphFactory.openGraph();

Once a Graph has been opened, the API provides a wide range of methods to work on the ContextNode, Relation, and Literal interfaces. Example:

ContextNode root = graph.getRootContextNode();
ContextNode markus = root.setContextNode(XDIArc.create("=markus"));
ContextNode animesh = root.setContextNode(XDIArc.create("=animesh"));
ContextNode name = markus.setContextNode(XDIArc.create("<#name>"));
ContextNode value = name.setContextNode(XDIArc.create("&"));
Relation relation = markus.setRelation(XDIAddress.create("#friend"), animesh);
Literal literal = value.setLiteral("Markus Sabadello");

An XDI graph can also be thought of as consisting of a set of statements, which can be accessed using the Statement interface. Example:

System.out.println("Statement associated with a context node: " + markus.getStatement());
System.out.println("Statement associated with a relation: " + relation.getStatement());
System.out.println("Statement associated with a literal: " + literal.getStatement());


At the end, a Graph should be closed. Example:


Class diagram


Source: XDI2-CLASSES.odg

See also