Example usage for java.lang.reflect Field isAnnotationPresent

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

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:adalid.core.AbstractDataArtifact.java

private void annotateNumericField(Field field) {
    Class<? extends Annotation> annotationClass = NumericField.class;
    Class<?>[] validTypes = new Class<?>[] { NumericPrimitive.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithNumericField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**///from   w ww  . j a  v a 2s.co m
    if (_annotatedWithNumericField) {
        NumericField annotation = field.getAnnotation(NumericField.class);
        _divisor = Math.min(maxDivisor(), Math.max(1, annotation.divisor()));
        _divisorRule = annotation.divisorRule();
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateBaseField(Field field) {
    Class<? extends Annotation> annotationClass = BaseField.class;
    Class<?>[] validTypes = new Class<?>[] { Property.class };
    boolean log = this instanceof Entity ? depth() == 1 : depth() == 0;
    _annotatedWithBaseField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateCharacterDataGen(Field field) {
    Class<? extends Annotation> annotationClass = CharacterDataGen.class;
    Class<?>[] validTypes = new Class<?>[] { CharacterProperty.class, StringProperty.class };
    boolean log = depth() == 0;
    boolean annotated = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**///from  w w  w .ja v  a2  s.c o  m
    if (annotated) {
        CharacterDataGen annotation = field.getAnnotation(CharacterDataGen.class);
        _dataGenType = annotation.type();
        //          _dataGenSeriesStart = annotation.start();
        //          _dataGenSeriesStop = annotation.stop();
        //          _dataGenSeriesStep = annotation.step();
        _dataGenSeriesStart = Math.min(10000, Math.max(1, annotation.start()));
        _dataGenSeriesStop = Math.min(10000, Math.max(1, annotation.stop()));
        _dataGenSeriesStep = Math.min(10000, Math.max(1, annotation.step()));
        _dataGenFunction = StringUtils.trimToNull(annotation.function());
        _dataGenNullable = Math.min(100, Math.max(0, annotation.nullable()));
        _dataGenPattern = StringUtils.trimToNull(annotation.pattern());
        _dataGenPrefix = StringUtils.trimToNull(annotation.prefix());
        _dataGenSuffix = StringUtils.trimToNull(annotation.suffix());
        _annotatedWithDataGen = true;
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateTimeField(Field field) {
    Class<? extends Annotation> annotationClass = TimeField.class;
    Class<?>[] validTypes = new Class<?>[] { TimeParameter.class, TimeProperty.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithTimeField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**///w ww .j a v  a 2  s  .co m
    if (_annotatedWithTimeField) {
        TimeField annotation = field.getAnnotation(TimeField.class);
        int precision = annotation.precision();
        TimeData data = (TimeData) this;
        if (precision >= 0 && precision <= Constants.MAX_TIME_PRECISION) {
            data.setPrecision(precision);
        }
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateColumnField(Field field) {
    Class<? extends Annotation> annotationClass = ColumnField.class;
    Class<?>[] validTypes = new Class<?>[] { Property.class };
    boolean log = this instanceof Entity ? depth() == 1 : depth() == 0;
    _annotatedWithColumnField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**//*w  ww. j  a v a  2 s . com*/
    if (_annotatedWithColumnField) {
        ColumnField annotation = field.getAnnotation(ColumnField.class);
        _calculable = annotation.calculable().toBoolean(_calculable);
        _nullable = annotation.nullable().toBoolean(_nullable);
        _insertable = annotation.insertable().toBoolean(_insertable);
        _updateable = annotation.updateable().toBoolean(_updateable);
        _unique = annotation.unique().toBoolean(_unique);
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateBooleanField(Field field) {
    Class<? extends Annotation> annotationClass = BooleanField.class;
    Class<?>[] validTypes = new Class<?>[] { BooleanParameter.class, BooleanProperty.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithBooleanField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**//*from  w  ww.j a  v  a  2 s .c  o m*/
    if (_annotatedWithBooleanField) {
        BooleanField annotation = field.getAnnotation(BooleanField.class);
        _booleanDisplayType = annotation.displayType();
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateTemporalDataGen(Field field) {
    Class<? extends Annotation> annotationClass = TemporalDataGen.class;
    Class<?>[] validTypes = new Class<?>[] { DateProperty.class, TimeProperty.class, TimestampProperty.class };
    boolean log = depth() == 0;
    boolean annotated = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**///from   w  ww. ja va2  s.  co  m
    if (annotated) {
        TemporalDataGen annotation = field.getAnnotation(TemporalDataGen.class);
        _dataGenType = annotation.type();
        //          _dataGenSeriesStart = annotation.start();
        //          _dataGenSeriesStop = annotation.stop();
        //          _dataGenSeriesStep = annotation.step();
        _dataGenSeriesStart = Math.min(10000, Math.max(1, annotation.start()));
        _dataGenSeriesStop = Math.min(10000, Math.max(1, annotation.stop()));
        _dataGenSeriesStep = Math.min(10000, Math.max(1, annotation.step()));
        _dataGenFunction = StringUtils.trimToNull(annotation.function());
        _dataGenNullable = Math.min(100, Math.max(0, annotation.nullable()));
        _dataGenMin = someTemporalValue(field, annotation.min());
        _dataGenMax = someTemporalValue(field, annotation.max());
        _dataGenTemporalInterval = annotation.interval();
        _annotatedWithDataGen = true;
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateTimestampField(Field field) {
    Class<? extends Annotation> annotationClass = TimestampField.class;
    Class<?>[] validTypes = new Class<?>[] { TimestampParameter.class, TimestampProperty.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithTimestampField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**///from   w  w  w .  j  av a  2  s .  co  m
    if (_annotatedWithTimestampField) {
        TimestampField annotation = field.getAnnotation(TimestampField.class);
        int precision = annotation.precision();
        TimestampData data = (TimestampData) this;
        if (precision >= 0 && precision <= Constants.MAX_TIME_PRECISION) {
            data.setPrecision(precision);
        }
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateStringField(Field field) {
    Class<? extends Annotation> annotationClass = StringField.class;
    Class<?>[] validTypes = new Class<?>[] { StringParameter.class, StringProperty.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithStringField = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**//*w  ww.ja  v a 2s.  c  o  m*/
    if (_annotatedWithStringField) {
        StringField annotation = field.getAnnotation(StringField.class);
        int maxLength = annotation.maxLength();
        int minLength = annotation.minLength();
        String regex = annotation.regex();
        StringData data = (StringData) this;
        if (maxLength >= 1 && maxLength <= Constants.MAX_STRING_LENGTH) {
            data.setMaxLength(maxLength);
            data.setMinLength(minLength >= 0 ? minLength <= maxLength ? minLength : maxLength : 0);
        } else if (minLength >= 0 && minLength <= Constants.MAX_STRING_LENGTH) {
            data.setMinLength(minLength);
        }
        data.setLetterCase(annotation.letterCase());
        data.setAllowDiacritics(annotation.allowDiacritics().toBoolean(true));
        if (StringUtils.isNotBlank(regex)) {
            try {
                data.setPattern(Pattern.compile(regex));
            } catch (PatternSyntaxException ex) {
                if (log) {
                    logger.error(getDeclaringArtifactClassName() + "." + field.getName()
                            + " has an invalid regular expression");
                    TLC.getProject().getParser().increaseErrorCount();
                }
            }
        }
    }
}

From source file:adalid.core.AbstractDataArtifact.java

private void annotateFileReference(Field field) {
    Class<? extends Annotation> annotationClass = FileReference.class;
    Class<?>[] validTypes = new Class<?>[] { StringParameter.class, StringProperty.class };
    boolean log = isParameter() || depth() == 0;
    _annotatedWithFileReference = field.isAnnotationPresent(annotationClass)
            && XS1.checkFieldAnnotation(log, field, annotationClass, validTypes);
    /**//* w  ww.j  a v  a  2 s .c o  m*/
    if (_annotatedWithFileReference) {
        FileReference annotation = field.getAnnotation(FileReference.class);
        int max = annotation.max();
        if (max > 0) {
            _maxInputFileSize = max;
        }
        MimeType[] types = annotation.types();
        if (types != null && types.length > 0) {
            _validInputFileTypes = types;
        }
        _uploadStorageOption = annotation.storage();
        switch (_uploadStorageOption) {
        case FILE:
            break;
        default:
            _joinFieldName = annotation.joinField();
            break;
        }
        if (StringUtils.isNotBlank(_joinFieldName)) {
            Operation declaringOperation = getDeclaringOperation();
            Entity declaringEntity = declaringOperation.getDeclaringEntity();
            String[] strings = new String[] { declaringOperation.getName(), getName(), "joinField" };
            String role = StringUtils.join(strings, ".");
            _joinField = XS1.getField(true, role, _joinFieldName, declaringEntity.getClass(), Entity.class,
                    new Class<?>[] {});
            if (_joinField != null) {
                _joinProperty = XS1.getProperty(_joinField, declaringEntity);
            }
        }
        _updateableFileReference = annotation.updateable().toBoolean(_updateableFileReference);
    }
}