All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tinkerpop.frames.annotations.IncidenceAnnotationHandler Maven / Gradle / Ivy

Go to download

Windup Frames is an extension of the upstream Frames project, with tools to ease debugging and integration within windup.

There is a newer version: 4.0.1.Final
Show newest version
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 - 2025 Weber Informatics LLC | Privacy Policy