-
Notifications
You must be signed in to change notification settings - Fork 39
Type resolvers
Bryn Cooke edited this page Jun 20, 2013
·
5 revisions
The TypeResolver
interface allows you to add interfaces that a framed element will implement. These are in addition to the interface that was passed in to the framing method, and EdgeFrame or VertexFrame.
public interface TypeResolver {
/**
* @param v The vertex being framed.
* @param defaultType The default as passed in to the framing method.
* @return Any additional interfaces that the frame should implement.
*/
Class<?>[] resolveTypes(Vertex v, Class<?> defaultType);
/**
* @param e The edge being framed.
* @param defaultType The default as passed in to the framing method.
* @return Any additional interfaces that the frame should implement.
*/
Class<?>[] resolveTypes(Edge e, Class<?> defaultType);
}
To use the type resolver, register it via a module supplied to the FramedGraphFactory
.
TypeResolver myTypeResolver = new TypeResolver() {
public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
return new Class[] { AdditionalEdge.class }; //Add the AdditionalEdge interface
}
public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
return new Class[] { AdditionalVertex.class }; //Add the AdditionalVertex interface
}
};
FramedGraph g = new FramedGraphFactory(new AbstractModule() {
public void doConfigure(FramedGraphConfiguration config) {
config.addTypeResolver(myTypeResolver);
}
}).create(baseGraph);
Person p = g.addVertex(Person.class); //p is also an instance of AdditionalVertex
AdditionalVertex av = (AdditionalVertex) p;
Every registered
TypeResolver
is called before returning the new element.
Some possible use cases
- You want to use information stored on the graph to create elements of different types.