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

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

Introduction

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

Prototype

@Nullable
public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType) 

Source Link

Document

Find a single Annotation of annotationType on the supplied Class , traversing its interfaces, annotations, and superclasses if the annotation is not directly present on the given class itself.

Usage

From source file:com.drillmap.crm.repository.extensions.invoker.ReflectionRepositoryInvoker.java

private boolean exposes(Method method) {

    RestResource annotation = AnnotationUtils.findAnnotation(method, RestResource.class);
    return annotation == null ? true : annotation.exported();
}

From source file:org.cleverbus.core.common.exception.AbstractSoapExceptionFilter.java

/**
 * Gets the SOAP fault name from the class with {@link WebFault @WebFault}.
 *
 * @param clazz the class that represents fault
 * @return fault name//from   ww w . j ava 2  s .  c o m
 */
protected static String getExFaultName(Class clazz) {
    WebFault annotation = AnnotationUtils.findAnnotation(clazz, WebFault.class);
    return annotation.name();
}

From source file:org.jnap.core.persistence.hsearch.FullTextDaoSupport.java

protected String[] getIndexedFields() {
    if (this.indexedFields == null) {
        PropertyDescriptor[] beanProperties = BeanUtils.getPropertyDescriptors(getEntityClass());
        List<String> fields = new ArrayList<String>();
        for (PropertyDescriptor propertyDescriptor : beanProperties) {
            Field field = AnnotationUtils.findAnnotation(propertyDescriptor.getReadMethod(), Field.class);
            if (field == null) {
                java.lang.reflect.Field propertyField = FieldUtils.getField(getEntityClass(),
                        propertyDescriptor.getName(), true);
                if (propertyField != null && propertyField.isAnnotationPresent(Field.class)) {
                    field = propertyField.getAnnotation(Field.class);
                }// ww  w.  jav  a2 s.  co  m
            }
            if (field != null) {
                fields.add(propertyDescriptor.getName());
            }
        }
        if (fields.isEmpty()) {
            throw new HSearchQueryException(""); // TODO ex msg
        }
        this.indexedFields = fields.toArray(new String[] {});
    }
    return this.indexedFields;
}

From source file:org.synyx.hades.dao.query.QueryMethod.java

/**
 * Returns whether the finder is a modifying one.
 * /*  w  w w. j  av a 2  s. com*/
 * @return
 */
boolean isModifyingQuery() {

    return null != AnnotationUtils.findAnnotation(method, Modifying.class);
}

From source file:org.trpr.platform.servicefw.impl.spring.web.HomeController.java

private List<ResourceInfo> findMethods(Map<String, Object> handlerMap, Set<String> urls) {

    SortedSet<ResourceInfo> result = new TreeSet<ResourceInfo>();

    for (String key : urls) {

        Object handler = handlerMap.get(key);
        Class<?> handlerType = ClassUtils.getUserClass(handler);
        HandlerMethodResolver resolver = new HandlerMethodResolver();
        resolver.init(handlerType);/*from w  w w  .j  a  v  a2  s  .  co  m*/

        String[] typeMappings = null;
        RequestMapping typeMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
        if (typeMapping != null) {
            typeMappings = typeMapping.value();
        }

        Set<Method> handlerMethods = resolver.getHandlerMethods();
        for (Method method : handlerMethods) {

            RequestMapping mapping = method.getAnnotation(RequestMapping.class);

            Collection<String> computedMappings = new HashSet<String>();
            if (typeMappings != null) {
                computedMappings.addAll(Arrays.asList(typeMappings));
            }

            for (String path : mapping.value()) {
                if (typeMappings != null) {
                    for (String parent : computedMappings) {
                        if (parent.endsWith("/")) {
                            parent = parent.substring(0, parent.length() - 1);
                        }
                        computedMappings.add(parent + path);
                    }
                } else {
                    computedMappings.add(path);
                }
            }

            logger.debug("Analysing mappings for method:" + method.getName() + ", key:" + key
                    + ", computed mappings: " + computedMappings);
            if (computedMappings.contains(key)) {
                RequestMethod[] methods = mapping.method();
                if (methods != null && methods.length > 0) {
                    for (RequestMethod requestMethod : methods) {
                        logger.debug(
                                "Added explicit mapping for path=" + key + "to RequestMethod=" + requestMethod);
                        result.add(new ResourceInfo(key, requestMethod));
                    }
                } else {
                    logger.debug("Added implicit mapping for path=" + key + "to RequestMethod=GET");
                    result.add(new ResourceInfo(key, RequestMethod.GET));
                }
            }

        }

        if (handlerMethods.isEmpty()) {
            result.add(new ResourceInfo(key, RequestMethod.GET));
        }

    }

    return new ArrayList<ResourceInfo>(result);

}

From source file:org.okj.commons.web.json.interceptor.JSONOutputterInterceptor.java

/**
 * JsonResponse/*from w  w w  .j av a2 s  . com*/
 * @param handlerMethods
 * @param request
 * @return
 */
protected Method findResolvedMethod(Set<Method> handlerMethods, HttpServletRequest request) {
    //method1?Method
    for (Enumeration<String> names = request.getParameterNames(); names.hasMoreElements();) {
        //
        String name = names.nextElement();
        String value = request.getParameter(name);

        //method
        for (Method method : handlerMethods) {
            //JsonResponse
            JsonResponse annotation = AnnotationUtils.findAnnotation(method, JsonResponse.class);
            if (isMatch(annotation, name + "=" + value)) {
                return method;
            }
        } //end for
    } //end for
    return null;
}

From source file:com.healthcit.cacure.test.DataSetTestExecutionListener.java

Annotation findAnnotation(Method method, Class<? extends Annotation> annotationType) {
    Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType);
    return annotation == null ? AnnotationUtils.findAnnotation(method.getDeclaringClass(), annotationType)
            : annotation;/*from w w  w  . jav  a2s.com*/
}

From source file:org.vaadin.spring.security.AbstractVaadinSecurity.java

@Override
public boolean hasAccessToSecuredMethod(Object securedObject, String methodName,
        Class<?>... methodParameterTypes) {
    try {//  w ww .  j a  v  a 2  s. com
        final Method method = securedObject.getClass().getMethod(methodName, methodParameterTypes);
        final Secured secured = AnnotationUtils.findAnnotation(method, Secured.class);
        Assert.notNull(secured, "securedObject did not have @Secured annotation");
        return hasAccessToObject(securedObject, secured.value());
    } catch (NoSuchMethodException ex) {
        throw new IllegalArgumentException("Method " + methodName + " does not exist", ex);
    }
}

From source file:org.javelin.sws.ext.bind.SweJaxbContext.java

/**
 * <p>Get a representation of a class and it's (JAXB2) metadata as a <i>pattern</i> of static and dynamic {@link XMLEvent XML events}.</p>
 * /*  www . j  a  v  a  2  s . c o m*/
 * <p>A class which is to be known by the registry should be directly convertible to a series of XML events. What is not mandatory here is
 * the root element of the marshalled object.</p>
 * 
 * <p>The produced pattern is automatically cached in the registry. Also the metadata for {@link XmlRootElement} annotated classes is cached.</p>
 * 
 * @param cl
 * @return
 */
@SuppressWarnings("unchecked")
@Override
public <T> TypedPattern<T> determineAndCacheXmlPattern(Class<T> cl) {
    // DESIGNFLAW: some check are done using map.containsKey(), some - using TypedPatternRegistry
    if (this.patterns.containsKey(cl)) {
        return (TypedPattern<T>) this.patterns.get(cl);
    }

    TypedPattern<T> pattern = null;

    log.trace("Mapping {} class to TypedPattern", cl.getName());

    // defaults
    JaxbMetadata meta = this.package2meta.get(cl.getPackage().getName());

    // package customization - cached
    if (!this.package2meta.containsKey(cl.getPackage().getName())) {
        meta = JaxbMetadata.defaultForPackage(cl.getPackage());
        // determine package-level default accessor type
        XmlAccessorType xmlAccessorType = AnnotationUtils.getAnnotation(cl.getPackage(), XmlAccessorType.class);
        XmlSchema xmlSchema = AnnotationUtils.getAnnotation(cl.getPackage(), XmlSchema.class);

        if (xmlAccessorType != null)
            meta.setXmlAccessType(xmlAccessorType.value());
        if (xmlSchema != null) {
            meta.setNamespace(xmlSchema.namespace());
            meta.setElementForm(xmlSchema.elementFormDefault());
            meta.setAttributeForm(xmlSchema.attributeFormDefault());
        }

        this.package2meta.put(cl.getPackage().getName(), meta);
    }

    // class customization - not cached
    XmlAccessorType xmlAccessorType = AnnotationUtils.findAnnotation(cl, XmlAccessorType.class);
    XmlType xmlType = AnnotationUtils.getAnnotation(cl, XmlType.class);

    XmlAccessType xmlAccessType = xmlAccessorType == null ? meta.getXmlAccessType() : xmlAccessorType.value();
    String namespace = xmlType == null || "##default".equals(xmlType.namespace()) ? meta.getNamespace()
            : xmlType.namespace();
    QName typeName = new QName(namespace,
            xmlType == null || "##default".equals(xmlType.name()) ? cl.getSimpleName() : xmlType.name());

    // before stepping into the class we'll add TemporaryTypedPattern to the mapping to be able to analyze cross-dependent classes
    TemporaryTypedPattern<T> txp = TemporaryTypedPattern.newTemporaryTypedPattern(typeName, cl);
    this.patterns.put(cl, txp);

    PropertyCallback<T> pc = new PropertyCallback<T>(this, cl, typeName, xmlAccessType, meta.getElementForm(),
            meta.getAttributeForm());
    // this is where the magic happens
    pattern = pc.analyze();
    txp.setRealPattern(pattern);

    // cache known global elements
    XmlRootElement xmlRootElement = AnnotationUtils.findAnnotation(cl, XmlRootElement.class);
    if (xmlRootElement != null) {
        String rootElementNamespace = "##default".equals(xmlRootElement.namespace()) ? meta.getNamespace()
                : xmlRootElement.namespace();
        String rootElementName = "##default".equals(xmlRootElement.name()) ? cl.getSimpleName()
                : xmlRootElement.name();
        QName rootQName = new QName(rootElementNamespace, rootElementName);

        ElementPattern<?> elementPattern = ElementPattern.newElementPattern(rootQName, pattern);
        this.rootPatterns.put(cl, elementPattern);
        this.rootPatternsForQNames.put(rootQName, elementPattern);
    }

    this.patterns.put(pattern.getJavaType(), pattern);
    this.patternsForTypeQNames.put(pattern.getSchemaType(), pattern);

    // see also
    XmlSeeAlso xmlSeeAlso = AnnotationUtils.findAnnotation(cl, XmlSeeAlso.class);
    if (xmlSeeAlso != null) {
        for (Class<?> c : xmlSeeAlso.value()) {
            log.trace("Analyzing @XmlSeeAlso class {}", c.getName());
            this.determineAndCacheXmlPattern(c);
        }
    }

    return pattern;
}

From source file:springfox.documentation.spring.data.rest.EntityRequestHandler.java

@Override
public <T extends Annotation> Optional<T> findControllerAnnotation(Class<T> annotation) {
    return Optional.fromNullable(AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), annotation));
}