Example usage for java.lang.annotation ElementType METHOD

List of usage examples for java.lang.annotation ElementType METHOD

Introduction

In this page you can find the example usage for java.lang.annotation ElementType METHOD.

Prototype

ElementType METHOD

To view the source code for java.lang.annotation ElementType METHOD.

Click Source Link

Document

Method declaration

Usage

From source file:com.agimatec.validation.util.PropertyAccess.java

public ElementType getElementType() {
    return ElementType.METHOD;
}

From source file:org.apache.bval.util.PropertyAccess.java

/**
 * {@inheritDoc}
 */
public ElementType getElementType() {
    return rememberField != null ? ElementType.FIELD : ElementType.METHOD;
}

From source file:org.raml.jaxrs.codegen.core.visitors.HttpMethodAnnotationVisitor.java

@SuppressWarnings("unchecked")
@Override//from   www.jav  a2  s.co m
public void visit(ResourceMethod resourceMethod) {
    JMethod annotatable = resourceMethod.getGeneratedObject();

    String httpMethod = resourceMethod.getAction().getType().toString();
    final Object annotationClass = httpMethodAnnotations.get(httpMethod.toUpperCase());
    if (annotationClass == null) {
        try {
            final JPackage pkg = getCodeModel()._package(getConfiguration().getSupportPackage());
            final JDefinedClass annotationClazz = pkg._annotationTypeDeclaration(httpMethod);
            annotationClazz.annotate(Target.class).param("value", ElementType.METHOD);
            annotationClazz.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
            annotationClazz.annotate(HttpMethod.class).param("value", httpMethod);
            annotationClazz.javadoc().add("Custom JAX-RS support for HTTP " + httpMethod + ".");
            annotatable.annotate(annotationClazz);

            httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz);
        } catch (JClassAlreadyExistsException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } else if (annotationClass instanceof JClass) {
        annotatable.annotate((JClass) annotationClass);
    } else if (annotationClass instanceof Class) {
        annotatable.annotate((Class<? extends Annotation>) annotationClass);
    } else {
        throw new IllegalStateException(
                "Found annotation: " + annotationClass + " for HTTP method: " + httpMethod);
    }

    String resourceInterfacePath = strip(resourceMethod.getResourceInterface().getResource().getRelativeUri(),
            "/");
    String path = StringUtils.substringAfter(resourceMethod.getAction().getResource().getUri(),
            resourceInterfacePath + "/");

    annotatable.annotate(Path.class).param(DEFAULT_ANNOTATION_PARAMETER, path);

    MimeType requestMimeType = resourceMethod.getMimeType();
    if (requestMimeType != null) {
        annotatable.annotate(Consumes.class).param(DEFAULT_ANNOTATION_PARAMETER, requestMimeType.getType());
    }

    List<String> responseContentTypes = new ArrayList<String>();
    for (MimeType mimeType : RamlHelper.getUniqueResponseMimeTypes(resourceMethod.getAction())) {
        responseContentTypes.add(mimeType.getType());
    }
    if (!responseContentTypes.isEmpty()) {
        final JAnnotationArrayMember paramArray = annotatable.annotate(Produces.class)
                .paramArray(DEFAULT_ANNOTATION_PARAMETER);
        for (String responseMimeType : responseContentTypes) {
            paramArray.param(responseMimeType);
        }
    }
}

From source file:org.apache.bval.util.IndexedAccess.java

/**
 * {@inheritDoc}
 */
@Override
public ElementType getElementType() {
    return ElementType.METHOD;
}

From source file:org.apache.bval.util.MethodAccess.java

/**
 * {@inheritDoc}
 */
public ElementType getElementType() {
    return ElementType.METHOD;
}

From source file:org.mule.config.processors.DecoratingAnnotatedServiceProcessor.java

protected void processInbound(Class componentFactoryClass, org.mule.api.service.Service service)
        throws MuleException {

    InboundEndpoint inboundEndpoint;/*from   w  ww .  j  av  a2 s  .c  o  m*/
    List<AnnotationMetaData> annotations = AnnotationUtils.getClassAndMethodAnnotations(componentFactoryClass);
    for (AnnotationMetaData annotation : annotations) {
        inboundEndpoint = tryInboundEndpointAnnotation(annotation, ChannelType.Inbound);
        if (inboundEndpoint != null) {
            if (annotation.getType() == ElementType.METHOD) {
                inboundEndpoint.getProperties().put(MuleProperties.MULE_METHOD_PROPERTY,
                        annotation.getElementName());
            }
            ((CompositeMessageSource) service.getMessageSource()).addSource(inboundEndpoint);
        }
    }

    //Lets process the inbound routers
    processInboundRouters(componentFactoryClass, service);
}

From source file:org.springframework.data.keyvalue.riak.RiakMappedClass.java

private void initFields() {
    ReflectionUtils.doWithFields(this.clazz, new FieldCallback() {

        @Override//from  w  ww.jav a 2s  .  c o  m
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            if (!field.isAccessible())
                ReflectionUtils.makeAccessible(field);

            if (field.isAnnotationPresent(Transient.class) || field.isSynthetic()
                    || field.getModifiers() == Modifier.FINAL || field.getModifiers() == Modifier.TRANSIENT) {
                return;
            }

            // Field can only have one of these, if more than one throw an
            // error
            List<Annotation> annots = org.springframework.data.keyvalue.riak.util.AnnotationUtils
                    .getFoundAnnotation(Id.class, Column.class, Embedded.class, Version.class, ManyToOne.class,
                            OneToMany.class, Basic.class);

            // Probably allow auto generation at some point, but for now
            // have to add one of the annotations
            if (annots.size() > 1)
                throw new IllegalArgumentException(String.format(
                        "The field %s must have only one of the following annotations: "
                                + "@Id, @Basic, @Column, @Embedded, @Version, @ManyToOne, @OneToMany",
                        field.getName()));

            Annotation annot = annots.get(0);

            if (annot.annotationType().equals(Id.class))
                RiakMappedClass.this.id = field;

            // Create a new mapped field here and then add to a list of
            // property MappedFields
            propertyFields.add(new RiakMappedField(field, annot));
        }
    });
    Map<Class<? extends Annotation>, Annotation> fieldAnnotMap = new HashMap<Class<? extends Annotation>, Annotation>();
    for (Class<? extends Annotation> a : entityAnnotations) {
        Target target = a.getAnnotation(Target.class);
        if (target != null && (ArrayUtils.contains(target.value(), ElementType.FIELD)
                || ArrayUtils.contains(target.value(), ElementType.METHOD))) {
            Annotation fieldAnnot;
            if ((fieldAnnot = this.clazz.getAnnotation(a)) != null) {
                fieldAnnotMap.put(a, fieldAnnot);
            }
        }
    }
}

From source file:org.apache.bval.jsr.JsrMetaBeanFactory.java

/**
 * Add cascade validation and constraints from xml mappings
 * /*w ww .  j av  a  2  s . c  o m*/
 * @param beanClass
 * @param metabean
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
private void addXmlConstraints(Class<?> beanClass, MetaBean metabean)
        throws IllegalAccessException, InvocationTargetException {
    for (final MetaConstraint<?, ? extends Annotation> metaConstraint : factory.getMetaConstraints(beanClass)) {
        Meta meta;
        AccessStrategy access = metaConstraint.getAccessStrategy();
        boolean create = false;
        if (access == null) { // class level
            meta = null;
        } else if (access.getElementType() == ElementType.METHOD
                && !metaConstraint.getMember().getName().startsWith("get")) { // TODO: better getter test
            final Method method = Method.class.cast(metaConstraint.getMember());
            meta = metabean.getMethod(method);
            final MetaMethod metaMethod;
            if (meta == null) {
                meta = new MetaMethod(metabean, method);
                metaMethod = MetaMethod.class.cast(meta);
                metabean.addMethod(method, metaMethod);
            } else {
                metaMethod = MetaMethod.class.cast(meta);
            }
            final Integer index = metaConstraint.getIndex();
            if (index != null && index >= 0) {
                MetaParameter param = metaMethod.getParameter(index);
                if (param == null) {
                    param = new MetaParameter(metaMethod, index);
                    metaMethod.addParameter(index, param);
                }
                param.addAnnotation(metaConstraint.getAnnotation());
            } else {
                metaMethod.addAnnotation(metaConstraint.getAnnotation());
            }
            continue;
        } else if (access.getElementType() == ElementType.CONSTRUCTOR) {
            final Constructor<?> constructor = Constructor.class.cast(metaConstraint.getMember());
            meta = metabean.getConstructor(constructor);
            final MetaConstructor metaConstructor;
            if (meta == null) {
                meta = new MetaConstructor(metabean, constructor);
                metaConstructor = MetaConstructor.class.cast(meta);
                metabean.addConstructor(constructor, metaConstructor);
            } else {
                metaConstructor = MetaConstructor.class.cast(meta);
            }
            final Integer index = metaConstraint.getIndex();
            if (index != null && index >= 0) {
                MetaParameter param = metaConstructor.getParameter(index);
                if (param == null) {
                    param = new MetaParameter(metaConstructor, index);
                    metaConstructor.addParameter(index, param);
                }
                param.addAnnotation(metaConstraint.getAnnotation());
            } else {
                metaConstructor.addAnnotation(metaConstraint.getAnnotation());
            }
            continue;
        } else { // property level
            meta = metabean.getProperty(access.getPropertyName());
            create = meta == null;
            if (create) {
                meta = addMetaProperty(metabean, access);
            }
        }
        if (!annotationProcessor.processAnnotation(metaConstraint.getAnnotation(), meta, beanClass,
                metaConstraint.getAccessStrategy(), new AppendValidationToMeta(meta == null ? metabean : meta),
                false) && create) {
            metabean.putProperty(access.getPropertyName(), null);
        }
    }
    for (final AccessStrategy access : factory.getValidAccesses(beanClass)) {
        if (access.getElementType() == ElementType.PARAMETER) {
            continue;
        }

        MetaProperty metaProperty = metabean.getProperty(access.getPropertyName());
        boolean create = metaProperty == null;
        if (create) {
            metaProperty = addMetaProperty(metabean, access);
        }
        if (!annotationProcessor.addAccessStrategy(metaProperty, access) && create) {
            metabean.putProperty(access.getPropertyName(), null);
        }
    }
}

From source file:org.raml.jaxrs.codegen.core.Context.java

private JDefinedClass createCustomHttpMethodAnnotation(final String httpMethod)
        throws JClassAlreadyExistsException {
    final JPackage pkg = codeModel._package(getSupportPackage());
    final JDefinedClass annotationClazz = pkg._annotationTypeDeclaration(httpMethod);
    annotationClazz.annotate(Target.class).param("value", ElementType.METHOD);
    annotationClazz.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
    annotationClazz.annotate(HttpMethod.class).param("value", httpMethod);
    annotationClazz.javadoc().add("Custom JAX-RS support for HTTP " + httpMethod + ".");
    httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz);
    return annotationClazz;
}

From source file:org.bonitasoft.engine.bdm.CodeGenerator.java

protected void checkAnnotationTarget(final JAnnotatable annotable,
        final Class<? extends Annotation> annotationType, final Set<ElementType> supportedElementTypes) {
    if (annotable instanceof JClass && !supportedElementTypes.isEmpty()
            && !supportedElementTypes.contains(ElementType.TYPE)) {
        throw new IllegalArgumentException(annotationType.getName() + " is not supported for " + annotable);
    }/*from ww  w.  ja va2s  .c o m*/
    if (annotable instanceof JFieldVar && !supportedElementTypes.isEmpty()
            && !supportedElementTypes.contains(ElementType.FIELD)) {
        throw new IllegalArgumentException(annotationType.getName() + " is not supported for " + annotable);
    }
    if (annotable instanceof JMethod && !supportedElementTypes.isEmpty()
            && !supportedElementTypes.contains(ElementType.METHOD)) {
        throw new IllegalArgumentException(annotationType.getName() + " is not supported for " + annotable);
    }
}