Example usage for org.springframework.core.annotation AnnotationUtils getAnnotationAttributes

List of usage examples for org.springframework.core.annotation AnnotationUtils getAnnotationAttributes

Introduction

In this page you can find the example usage for org.springframework.core.annotation AnnotationUtils getAnnotationAttributes.

Prototype

public static Map<String, Object> getAnnotationAttributes(Annotation annotation) 

Source Link

Document

Retrieve the given annotation's attributes as a Map , preserving all attribute types.

Usage

From source file:org.alfresco.rest.framework.core.ResourceInspector.java

/**
 * Inspects the resource to determine what api it belongs to.
 * It does this by looking for the WebApi package annotation.
 * // ww  w . j  a  v  a2  s  . co  m
 * @return Api
 */
public static Api inspectApi(Class<?> resource) {
    Package myPackage = resource.getPackage();
    Annotation annot = myPackage.getAnnotation(WebApi.class);

    if (annot != null) {
        Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
        String apiName = String.valueOf(annotAttribs.get("name"));
        String apiScope = String.valueOf(annotAttribs.get("scope"));
        String apiVersion = String.valueOf(annotAttribs.get("version"));
        return Api.valueOf(apiName, apiScope, apiVersion);
    }
    return null;
}

From source file:org.alfresco.rest.framework.core.ResourceInspector.java

/**
 * Finds the property name that is used as the unique id.
 * @param uniqueIdMethod Method/*from  w w w.  j a va  2  s  . c  o m*/
 * @return String the property name that is used as the unique id.
 */
public static String findUniqueIdName(Method uniqueIdMethod) {
    Annotation annot = AnnotationUtils.findAnnotation(uniqueIdMethod, UniqueId.class);
    if (annot != null) {
        Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
        String uniqueIdName = String.valueOf(annotAttribs.get("name"));
        return uniqueIdName;
    }
    return UniqueId.UNIQUE_NAME;
}

From source file:org.springframework.cloud.iot.coap.method.ResolvableMethod.java

private String formatAnnotation(Annotation annotation) {
    Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
    //      map.forEach((key, value) -> {
    //         if (value.equals(ValueConstants.DEFAULT_NONE)) {
    //            map.put(key, "NONE");
    //         }/*from  w  w w  . j  av a  2s .  co m*/
    //      });
    return annotation.annotationType().getName() + map;
}

From source file:org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport.java

/**
 * Returns the {@link AnnotationAttributes} for the given {@link Annotation}.
 *
 * @param annotation {@link Annotation} to get the {@link AnnotationAttributes} for.
 * @return the {@link AnnotationAttributes} for the given {@link Annotation}.
 * @see org.springframework.core.annotation.AnnotationAttributes
 * @see java.lang.annotation.Annotation/*from   ww w. j av a  2 s . co  m*/
 */
protected AnnotationAttributes getAnnotationAttributes(Annotation annotation) {
    return AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes(annotation));
}

From source file:org.springframework.messaging.handler.invocation.ResolvableMethod.java

private String formatAnnotation(Annotation annotation) {
    Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
    map.forEach((key, value) -> {//from  w w w .  ja  v  a 2  s.  c  o m
        if (value.equals(DEFAULT_VALUE_NONE)) {
            map.put(key, "NONE");
        }
    });
    return annotation.annotationType().getName() + map;
}

From source file:org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration.java

private AnnotationAttributes enableMethodSecurity() {
    if (enableMethodSecurity == null) {
        // if it is null look at this instance (i.e. a subclass was used)
        EnableGlobalMethodSecurity methodSecurityAnnotation = AnnotationUtils.findAnnotation(getClass(),
                EnableGlobalMethodSecurity.class);
        Assert.notNull(methodSecurityAnnotation,
                () -> EnableGlobalMethodSecurity.class.getName() + " is required");
        Map<String, Object> methodSecurityAttrs = AnnotationUtils
                .getAnnotationAttributes(methodSecurityAnnotation);
        this.enableMethodSecurity = AnnotationAttributes.fromMap(methodSecurityAttrs);
    }/*from   www. j a  va  2s.c o  m*/
    return this.enableMethodSecurity;
}

From source file:org.springframework.security.web.method.ResolvableMethod.java

private String formatAnnotation(Annotation annotation) {
    Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
    map.forEach((key, value) -> {//from w  w  w  .java2s  .c o m
        if (value.equals(ValueConstants.DEFAULT_NONE)) {
            map.put(key, "NONE");
        }
    });
    return annotation.annotationType().getName() + map;
}

From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java

private boolean annotationHandlerVariableMatch(Annotation annotation, Object key) {
    boolean handle = false;
    Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation);
    Object object = annotationAttributes.get("key");
    Collection<String> scoll = StateMachineUtils.toStringCollection(object);
    if (!scoll.isEmpty()) {
        if (StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(key))) {
            handle = true;//from w w w  .  java 2  s. com
        }
    } else {
        handle = true;
    }
    return handle;
}

From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java

private boolean annotationHandlerEventVariableMatch(Annotation annotation, Object key) {
    boolean handle = false;
    Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(annotation);
    Object object = annotationAttributes.get("event");
    Collection<String> scoll = StateMachineUtils.toStringCollection(object);
    if (!scoll.isEmpty()) {
        if (StateMachineUtils.containsAtleastOne(scoll, StateMachineUtils.toStringCollection(key))) {
            handle = true;//from   w  ww .  j  ava2s.  com
        }
    } else {
        handle = true;
    }
    return handle;
}

From source file:org.springframework.statemachine.processor.StateMachineHandlerCallHelper.java

private boolean annotationHandlerSourceTargetMatch(String[] msources, String[] mtargets,
        Annotation methodAnnotation, State<S, E> sourceState, State<S, E> targetState) {
    Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(methodAnnotation);
    Object source = annotationAttributes.get("source");
    Object target = annotationAttributes.get("target");

    Collection<String> scoll = StateMachineUtils.toStringCollection(source);
    if (scoll.isEmpty() && msources != null) {
        scoll = Arrays.asList(msources);
    }/*www .j av a2  s  . c  o m*/
    Collection<String> tcoll = StateMachineUtils.toStringCollection(target);
    if (tcoll.isEmpty() && mtargets != null) {
        tcoll = Arrays.asList(mtargets);
    }

    boolean handle = false;
    if (!scoll.isEmpty() && !tcoll.isEmpty()) {
        if (sourceState != null && targetState != null
                && StateMachineUtils.containsAtleastOne(scoll,
                        StateMachineUtils.toStringCollection(sourceState.getIds()))
                && StateMachineUtils.containsAtleastOne(tcoll,
                        StateMachineUtils.toStringCollection(targetState.getIds()))) {
            handle = true;
        }
    } else if (!scoll.isEmpty()) {
        if (sourceState != null && StateMachineUtils.containsAtleastOne(scoll,
                StateMachineUtils.toStringCollection(sourceState.getIds()))) {
            handle = true;
        }
    } else if (!tcoll.isEmpty()) {
        if (targetState != null && StateMachineUtils.containsAtleastOne(tcoll,
                StateMachineUtils.toStringCollection(targetState.getIds()))) {
            handle = true;
        }
    } else if (scoll.isEmpty() && tcoll.isEmpty()) {
        handle = true;
    }

    return handle;
}