use of com.tinkerpop.frames.modules.TypeResolver in project frames by tinkerpop.
the class FramedGraph method frame.
/**
* A helper method for framing an edge. Note that all framed edges implement
* {@link EdgeFrame} to allow access to the underlying element
*
* @param edge
* the edge to frame
* @param direction
* the direction of the edges
* @param kind
* the default annotated interface to frame the edges as
* @param <F>
* the default type of the annotated interface
* @return a proxy objects backed by an edge and interpreted from the
* perspective of the annotate interface or null if the edge paramenter was null
*
* @deprecated Use {@link #frame(Edge, Class)}, in combination with {@link InVertex} and {@link OutVertex}.
*/
public <F> F frame(final Edge edge, final Direction direction, final Class<F> kind) {
if (edge == null) {
return null;
}
Collection<Class<?>> resolvedTypes = new HashSet<Class<?>>();
resolvedTypes.add(EdgeFrame.class);
resolvedTypes.add(kind);
for (TypeResolver typeResolver : config.getTypeResolvers()) {
resolvedTypes.addAll(Arrays.asList(typeResolver.resolveTypes(edge, kind)));
}
return (F) Proxy.newProxyInstance(config.getFrameClassLoaderResolver().resolveClassLoader(kind), resolvedTypes.toArray(new Class[resolvedTypes.size()]), new FramedElement(this, edge, direction));
}
use of com.tinkerpop.frames.modules.TypeResolver in project frames by tinkerpop.
the class FramedGraph method frame.
/**
* A helper method for framing a vertex. Note that all framed vertices
* implement {@link VertexFrame} to allow access to the underlying element
*
* @param vertex
* the vertex to frame
* @param kind
* the default annotated interface to frame the vertex as
* @param <F>
* the default type of the annotated interface
* @return a proxy objects backed by a vertex and interpreted from the
* perspective of the annotate interface or null if the vertex parameter was null
*/
public <F> F frame(final Vertex vertex, final Class<F> kind) {
if (vertex == null) {
return null;
}
Collection<Class<?>> resolvedTypes = new HashSet<Class<?>>();
resolvedTypes.add(VertexFrame.class);
resolvedTypes.add(kind);
for (TypeResolver typeResolver : config.getTypeResolvers()) {
resolvedTypes.addAll(Arrays.asList(typeResolver.resolveTypes(vertex, kind)));
}
return (F) Proxy.newProxyInstance(config.getFrameClassLoaderResolver().resolveClassLoader(kind), resolvedTypes.toArray(new Class[resolvedTypes.size()]), new FramedElement(this, vertex));
}
use of com.tinkerpop.frames.modules.TypeResolver in project frames by tinkerpop.
the class TypeResolverTest method testExtendedTypes.
@Test
public void testExtendedTypes() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {
@Override
public void doConfigure(FramedGraphConfiguration config) {
config.addTypeResolver(new TypeResolver() {
@Override
public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
return new Class[0];
}
@Override
public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
return new Class[] { ExtendedPerson.class };
}
});
}
});
framedGraph = factory.create(graph);
Person marko = framedGraph.getVertex(1, Person.class);
Assert.assertTrue(marko instanceof ExtendedPerson);
}
use of com.tinkerpop.frames.modules.TypeResolver in project frames by tinkerpop.
the class TypeResolverTest method testAdditionalTypes.
@Test
public void testAdditionalTypes() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {
@Override
public void doConfigure(FramedGraphConfiguration config) {
config.addTypeResolver(new TypeResolver() {
@Override
public Class<?>[] resolveTypes(Edge e, Class<?> defaultType) {
return new Class[] { AdditionalEdge.class };
}
@Override
public Class<?>[] resolveTypes(Vertex v, Class<?> defaultType) {
return new Class[] { AdditionalVertex.class };
}
});
}
});
framedGraph = factory.create(graph);
Person marko = framedGraph.getVertex(1, Person.class);
Assert.assertTrue(marko instanceof AdditionalVertex);
Assert.assertFalse(marko instanceof AdditionalEdge);
Knows knows = marko.getKnows().iterator().next();
Assert.assertTrue(knows instanceof AdditionalEdge);
Assert.assertFalse(knows instanceof AdditionalVertex);
}
Aggregations