com.tinkerpop.frames.annotations.IncidenceAnnotationHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of frames Show documentation
Show all versions of frames Show documentation
Frames is a framework for exposing the elements of a Blueprints graph as Java objects.
Instead of writing software in terms of vertices and edges, with Frames,
software is written in terms of domain objects and their relationships to each other.
package com.tinkerpop.frames.annotations;
import java.lang.reflect.Method;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.ClassUtilities;
import com.tinkerpop.frames.EdgeFrame;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.Incidence;
import com.tinkerpop.frames.VertexFrame;
import com.tinkerpop.frames.structures.FramedEdgeIterable;
public class IncidenceAnnotationHandler implements AnnotationHandler {
@Override
public Class getAnnotationType() {
return Incidence.class;
}
@Override
public Object processElement(final Incidence annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) {
if (element instanceof Vertex) {
return processVertex(annotation, method, arguments, framedGraph, (Vertex) element);
} else {
throw new UnsupportedOperationException();
}
}
public Object processVertex(final Incidence incidence, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex element) {
if (ClassUtilities.isGetMethod(method)) {
return new FramedEdgeIterable(framedGraph, element.getEdges(incidence.direction(), incidence.label()), incidence.direction(), ClassUtilities.getGenericClass(method));
} else if (ClassUtilities.isAddMethod(method)) {
switch(incidence.direction()) {
case OUT:
return framedGraph.addEdge(null, element, ((VertexFrame) arguments[0]).asVertex(), incidence.label(), Direction.OUT, method.getReturnType());
case IN:
return framedGraph.addEdge(null, ((VertexFrame) arguments[0]).asVertex(), element, incidence.label(), Direction.IN, method.getReturnType());
case BOTH:
throw new UnsupportedOperationException("Direction.BOTH it not supported on 'add' or 'set' methods");
}
} else if (ClassUtilities.isRemoveMethod(method)) {
framedGraph.removeEdge(((EdgeFrame) arguments[0]).asEdge());
return null;
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy