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

org.iris_events.asyncapi.parsers.MessageScopeParser Maven / Gradle / Ivy

There is a newer version: 6.1.8
Show newest version
package org.iris_events.asyncapi.parsers;

import java.lang.reflect.Method;
import java.util.Objects;

import org.iris_events.annotations.Message;
import org.iris_events.annotations.Scope;
import org.iris_events.asyncapi.IrisAnnotationRuntimeException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.IndexView;

public class MessageScopeParser {
    private static final String MESSAGE_SCOPE_PARAM = "scope";

    public static Scope getFromAnnotationClass(Message messageAnnotation) {
        final var scope = messageAnnotation.scope();
        if (Objects.nonNull(scope)) {
            return scope;
        }
        try {
            Method method = messageAnnotation.annotationType().getMethod(MESSAGE_SCOPE_PARAM);
            return (Scope) method.getDefaultValue();
        } catch (NoSuchMethodException e) {
            throw new IrisAnnotationRuntimeException(
                    String.format("Malformed %s annotation. Does not contain %s parameter default",
                            Message.class.getName(),
                            MESSAGE_SCOPE_PARAM));
        }

    }

    public static Scope getFromAnnotationInstance(AnnotationInstance messageAnnotation, IndexView index) {
        return Scope.valueOf(messageAnnotation.valueWithDefault(index, MESSAGE_SCOPE_PARAM).asString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy