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

zed.org.apache.camel.rest.annotations.RestAnnotations Maven / Gradle / Ivy

There is a newer version: 0.0.20
Show newest version
package zed.org.apache.camel.rest.annotations;

import org.apache.camel.spi.Registry;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;

public class RestAnnotations {

    public static List findRestOperations(Class type, String name) {
        List annotatedMethods = new LinkedList<>();
        for (Method method : type.getMethods()) {
            if (method.isAnnotationPresent(RestOperation.class)) {
                if (name == null || method.getName().equals(name)) {
                    annotatedMethods.add(method);
                }
            }
        }
        for (Class iface : type.getInterfaces()) {
            annotatedMethods.addAll(findRestOperations(iface, name));
        }
        return unmodifiableList(annotatedMethods);
    }

    public static List findRestOperations(Class type) {
        return findRestOperations(type, null);
    }

    public static Map findBeansWithRestOperations(Registry registry) {
        Map beans = new HashMap<>();
        for (Map.Entry bean : registry.findByTypeWithName(Object.class).entrySet()) {
            if (!findRestOperations(bean.getValue().getClass()).isEmpty()) {
                beans.put(bean.getKey(), bean.getValue());
            }
        }
        return beans;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy