use of com.tinkerpop.frames.structures.FramedVertexMap in project frames by tinkerpop.
the class GremlinGroovyAnnotationHandler method processVertex.
public Object processVertex(final GremlinGroovy annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex vertex) {
try {
final CompiledScript script = this.engine.compile(annotation.value());
final Bindings bindings = getBindings(method, arguments);
bindings.put(IT, vertex);
bindings.put(G, framedGraph);
final Object result = script.eval(bindings);
// TODO: Deprecate the use of _() and replace with it
if (result instanceof Pipe & annotation.value().startsWith(PIPE)) {
LOGGER.warning("_() is deprecated in favor of using 'it' to represent the framed vertex");
((Pipe) result).setStarts(new SingleIterator<Element>(vertex));
}
if (annotation.frame()) {
if (result instanceof Iterable) {
final FramedVertexIterable r = new FramedVertexIterable(framedGraph, (Iterable) result, ClassUtilities.getGenericClass(method));
return (ClassUtilities.returnsIterable(method)) ? r : r.iterator().hasNext() ? r.iterator().next() : null;
} else if (ClassUtilities.returnsMap(method)) {
return new FramedVertexMap(framedGraph, (Map) result, ClassUtilities.getGenericClass(method));
} else if (result instanceof Vertex) {
return framedGraph.frame((Vertex) result, ClassUtilities.getGenericClass(method));
} else {
throw new IllegalStateException("The returned object can not be framed: " + result.getClass());
}
} else {
return result;
}
} catch (ScriptException e) {
//Preserve original exception functionality.
ExceptionUtils.sneakyThrow(e);
return null;
}
}
Aggregations