Example usage for java.lang.reflect Field getAnnotation

List of usage examples for java.lang.reflect Field getAnnotation

Introduction

In this page you can find the example usage for java.lang.reflect Field getAnnotation.

Prototype

public <T extends Annotation> T getAnnotation(Class<T> annotationClass) 

Source Link

Usage

From source file:com.cloudera.nav.sdk.client.writer.registry.MPropertyEntry.java

public MPropertyEntry(Field field, Method getter) {
    ann = field.getAnnotation(MProperty.class);
    String attr = ann.attribute();
    this.attribute = StringUtils.isEmpty(attr) ? field.getName() : attr;
    this.field = field;
    this.getter = getter;
}

From source file:stormy.pythian.core.description.InputStreamDescriptionFactory.java

private InputStreamDescription createInputStreamDescription(Class<?> componentClass, Field inputStreamField) {
    InputStream annotation = inputStreamField.getAnnotation(InputStream.class);
    String streamName = annotation.name();

    NameMapper nameMapper = ReflectionHelper.getNameMapper(componentClass, streamName);
    ListMapper listMapper = ReflectionHelper.getListMapper(componentClass, streamName);

    if (nameMapper != null) {
        List<FeatureDescription> expectedFeatures = featureDescriptorFactory.createDescriptions(nameMapper);
        return new InputStreamDescription(streamName, MappingType.NAMED, expectedFeatures,
                annotation.mandatory());
    } else if (listMapper != null) {
        return new InputStreamDescription(streamName, LISTED, new ArrayList<FeatureDescription>(),
                annotation.mandatory());
    } else {/*  www  .  java 2  s.c  o  m*/
        return new InputStreamDescription(streamName, MappingType.NONE);
    }
}

From source file:stormy.pythian.core.description.PropertyDescriptionFactory.java

@SuppressWarnings("unchecked")
public List<PropertyDescription> createPropertyDescriptions(Class<?> componentClass) {
    List<PropertyDescription> propertyDescriptions = new ArrayList<>();

    Set<Field> propertyFields = getAllFields(componentClass, withAnnotation(Property.class));
    for (Field propertyField : propertyFields) {
        Property property = propertyField.getAnnotation(Property.class);
        PropertyDescription propertyDescription = new PropertyDescription(property.name(),
                property.description(), property.mandatory(), fromType(propertyField.getType()));
        if (PropertyType.ENUM.equals(propertyDescription.getType())) {
            List<String> enumValues = retrieveEnumValues(propertyField);
            propertyDescription.setAcceptedValues(enumValues);
        }//from w ww. j ava  2s  . c o m

        propertyDescriptions.add(propertyDescription);
    }

    return propertyDescriptions;
}

From source file:jease.cmf.service.Serializer.java

public boolean isNotSerialized(Field field) {
    return field.getAnnotation(NotSerialized.class) != null;
}

From source file:io.gravitee.management.service.processor.ApiSynchronizationProcessor.java

public boolean processCheckSynchronization(ApiEntity deployedApi, ApiEntity apiToDeploy) {
    Class<ApiEntity> cl = ApiEntity.class;
    List<Object> requiredFieldsDeployedApi = new ArrayList<Object>();
    List<Object> requiredFieldsApiToDeploy = new ArrayList<Object>();
    for (Field f : cl.getDeclaredFields()) {
        if (f.getAnnotation(DeploymentRequired.class) != null) {
            boolean previousAccessibleState = f.isAccessible();
            f.setAccessible(true);/*from w w  w  .ja  v  a 2 s. c  o m*/
            try {
                requiredFieldsDeployedApi.add(f.get(deployedApi));
                requiredFieldsApiToDeploy.add(f.get(apiToDeploy));
            } catch (Exception e) {
                LOGGER.error("Error access API required deployment fields", e);
            } finally {
                f.setAccessible(previousAccessibleState);
            }
        }
    }

    try {
        String requiredFieldsDeployedApiDefinition = objectMapper.writeValueAsString(requiredFieldsDeployedApi);
        String requiredFieldsApiToDeployDefinition = objectMapper.writeValueAsString(requiredFieldsApiToDeploy);

        return requiredFieldsDeployedApiDefinition.equals(requiredFieldsApiToDeployDefinition);
    } catch (Exception e) {
        LOGGER.error("Unexpected error while generating API deployment required fields definition", e);
        return false;
    }
}

From source file:be.fedict.trust.xkms2.ServiceConsumerInstanceResolver.java

private void injectServices(T endpoint, TrustService trustService) {
    LOG.debug("injecting services into JAX-WS endpoint...");
    Field[] fields = endpoint.getClass().getDeclaredFields();
    for (Field field : fields) {
        EJB ejbAnnotation = field.getAnnotation(EJB.class);
        if (null == ejbAnnotation) {
            continue;
        }// w  ww .  j  a  va2s.  c o  m
        if (field.getType().equals(TrustService.class)) {
            field.setAccessible(true);
            try {
                field.set(endpoint, trustService);
            } catch (Exception e) {
                throw new RuntimeException("injection error: " + e.getMessage(), e);
            }
        }
    }
}

From source file:jp.gr.java_conf.ka_ka_xyz.processor.JPA20AnnotationProcessor.java

private void registerFieldAnnotation(Field field) {
    Column column = field.getAnnotation(Column.class);
    String colName = null;// w w w  .j ava2  s  . c  o m
    if (column != null) {
        colName = column.name();
        fieldColMap.put(field.getName(), colName);
    }

}

From source file:edu.usu.sdl.openstorefront.validation.SizeRule.java

@Override
protected String getValidationRule(Field field) {
    StringBuilder sb = new StringBuilder();
    Size size = field.getAnnotation(Size.class);
    sb.append("Min Length: ").append(size.min()).append(" Max Length: ").append(size.max());
    return sb.toString();
}

From source file:edu.usu.sdl.openstorefront.validation.PatternRule.java

@Override
protected String getValidationRule(Field field) {
    StringBuilder sb = new StringBuilder();
    Pattern pattern = field.getAnnotation(Pattern.class);
    sb.append("Pattern allowed: ").append(pattern.regexp());
    return sb.toString();
}

From source file:edu.usu.sdl.openstorefront.validation.MaxValueRule.java

@Override
protected String getValidationRule(Field field) {
    StringBuilder sb = new StringBuilder();
    Max max = field.getAnnotation(Max.class);
    sb.append("Max value allowed: ").append(max.value());
    return sb.toString();
}