Skip to content

Frame initializers

Bryn Cooke edited this page Aug 6, 2013 · 5 revisions

Sometimes you need to be able to initialize a vertex or edge is added to the graph knowing the type of frame that it was created with.

The FrameInitializer interface allows a newly added vertex or edge to be initialized before it is returned to the user.

publicinterfaceFrameInitializer {
/** * @param kind The kind of frame.  * @param framedGraph The graph. * @param element The new element that is being inserted into the graph. */publicvoidinitElement(finalClass<?> kind, finalFramedGraph<?> framedGraph, finalElementelement);
}

To use the initializer register it via a module with the FramedGraphFactory.

FrameInitializermyInitializer = newFrameInitializer() {
publicvoidinitElement(finalClass<?> kind, finalFramedGraph<?> framedGraph, finalElementelement) {
element.setProperty("class", kind.getName()); //For example: save the class name of the frame on the element
}
};
FramedGraphg = newFramedGraphFactory(newAbstractModule() {
publicvoiddoConfigure(FramedGraphConfigurationconfig) {
config.addFrameInitializer(myInitializer);
}
}).create(baseGraph);
Personp = g.addVertex(null, Person.class); //myInitializer is called.

Every registered initializer is called before returning the new element.

Some possible use cases

  • You want to save the type information of the frame to the vertex.
  • You want to set the default property values of the vertex based on the frame type.

Clone this wiki locally