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

com.tinkerpop.frames.annotations.PropertyMethodHandler 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 com.tinkerpop.blueprints.Element;
import com.tinkerpop.frames.ClassUtilities;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.MethodHandler;

import java.lang.reflect.Method;

public class PropertyMethodHandler implements MethodHandler {

    @Override
    public Class getAnnotationType() {
        return Property.class;
    }

    @Override
    public Object processElement(Object frame, Method method,
            Object[] arguments, Property annotation,
            FramedGraph framedGraph, Element element) {
        if (ClassUtilities.isGetMethod(method)) {
            Object value = element.getProperty(annotation.value());
            if (method.getReturnType().isEnum())
                return getValueAsEnum(method, value);
            else
                return value;
        } else if (ClassUtilities.isSetMethod(method)) {
            Object value = arguments[0];
            if (null == value) {
                element.removeProperty(annotation.value());
            } else {
                if (value.getClass().isEnum()) {
                    element.setProperty(annotation.value(), ((Enum) value).name());
                } else {
                    element.setProperty(annotation.value(), value);
                }
            }
            if (method.getReturnType().isAssignableFrom(frame.getClass()))
        	return frame;
        } else if (ClassUtilities.isRemoveMethod(method)) {
            element.removeProperty(annotation.value());
            return null;
        }

        return null;
    }

    private Enum getValueAsEnum(final Method method, final Object value) {
        Class en = (Class) method.getReturnType();
        if (value != null)
            return Enum.valueOf(en, value.toString());

        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy