@SuppressWarnings({ RAWTYPES, UNCHECKED }) private void addConstraints(final Builder builder, final Method method) { final Annotation[] annotations = method.getAnnotations(); boolean collectionConstraintAdded = false; for (final Annotation annotation : annotations) { final javax.validation.Constraint annotationAnnotation = annotation.annotationType().getAnnotation( javax.validation.Constraint.class); if (annotationAnnotation != null) { if (annotation.annotationType() != Size.class) { final GenericPropertyConstraint propertyConstraint = new GenericPropertyConstraint(annotation, method.getReturnType()); builder.add(propertyConstraint); } else { checkCollection(builder, method, (Size) annotation); collectionConstraintAdded = true; } } } if (!collectionConstraintAdded) { checkCollection(builder, method, null); } }
private void checkCollection(final PropertyMetaData.Builder builder, final Method method, final Size size) { final Class<?> type = builder.getType().getType(); if (Collection.class.isAssignableFrom(type)) { final PropertyElementType elementTypeAnnotation = method.getAnnotation(PropertyElementType.class); final Class<?> elementType = calcElementType(elementTypeAnnotation); final List<? extends PropertyConstraint<?>> elementConstraints = calcElementConstraints(method); Integer min = null; Integer max = null; if (size != null) { min = size.min(); max = size.max(); } final PropertyConstraint<?> propertyConstraint = new ListValueConstraint(elementType, min, max, elementConstraints); builder.add(propertyConstraint); } }
private void addCategories(final Builder builder, final Method method) { final List<Class<?>> categories = readCategories(method); if (!categories.isEmpty()) { final PropertyCategories.Builder catBuilder = new PropertyCategories.Builder(); for (final Class<?> category : categories) { catBuilder.with(category); } final PropertyCategories propertyCategories = catBuilder.build(); builder.with(propertyCategories); } }
/** * Creates the instance. * * @return the created instance. * @throws NullPointerException if any of the required arguments is not set. */ @SuppressWarnings(UNCHECKED) public PropertyMetaData build() throws NullPointerException { Arg.checkNotNull("context", context); Arg.checkNotNull("declaringType", declaringType); Arg.checkNotNull("key", key); Arg.checkNotNull("type", type); Arg.checkNotNull("accessType", accessType); Arg.checkNotNull("configurationTime", configurationTime); Arg.checkNotNull("defaultExpression", defaultExpression); Arg.checkNotNull("constraints", constraints); Arg.checkNotNull("documentMetaData", documentMetaDataProxy); Arg.checkNotNull("commentProxy", commentProxy); mandatory = containsMandatoryConstaint(constraints); if (categories == null) { categories = new PropertyCategories.Builder().build(); } if (useType == null) { useType = UseType.CONFIGURATION; } return new PropertyMetaData(this); }
/** * Reads the property descriptor information from the method. * * @param method the method to read the property descriptor. * @return the property descriptor provided by this method. * @throws NullPointerException if {@code method} is <code>null</code>. */ public PropertyDescriptor readDescriptor(final Method method) throws NullPointerException { Arg.checkNotNull("method", method); final PropertyMetaData.Builder builder = new PropertyMetaData.Builder(); final Class<?> declaringType = method.getDeclaringClass(); final PropertyKey key = readKey(method); final PropertyType type = readType(method); builder.with(new PropertyContextProxy(context)) .withDeclaringType(declaringType).with(key).with(type); addValueRange(builder, method); addExpression(builder, method); addLifecycle(builder, method); addConstraints(builder, method); addDocumentProxy(builder, method, key); addComments(builder); addSecured(builder, method); addCategories(builder, method); addUseType(builder, method); return builder.build(); }
private void addLifecycle(final Builder builder, final Method method) { final de.smartics.properties.api.core.annotations.PropertyLifecycle annotation = method .getAnnotation(de.smartics.properties.api.core.annotations.PropertyLifecycle.class); if (annotation != null) { final PropertyDefinitionTime configurationTime = annotation.definitionTime(); if (configurationTime != null) { builder.with(configurationTime); } final AccessType accessType = annotation.access(); if (accessType != null) { builder.with(accessType); } final long updateInterval = annotation.updateInterval(); builder.withUpdateIntervalInMs(updateInterval); } }
private void addUseType(final Builder builder, final Method method) { final Class<?> type = method.getDeclaringClass(); final de.smartics.properties.api.core.annotations.PropertyUse typeAnnotation = type.getAnnotation(de.smartics.properties.api.core.annotations.PropertyUse.class); if (typeAnnotation != null) { final UseType useType = typeAnnotation.value(); if (useType != null) { builder.with(useType); } } }
private static void addExpression(final Builder builder, final Method method) { final de.smartics.properties.api.core.annotations.PropertyExpression annotation = method .getAnnotation(de.smartics.properties.api.core.annotations.PropertyExpression.class); if (annotation != null) { final String expressionString = annotation.value(); final PropertyExpression expression = PropertyExpression.create(expressionString); builder.with(expression); } }
private static void addSecured(final Builder builder, final Method method) { final boolean secured = readSecured(method); builder.setSecured(secured); }
@SuppressWarnings({ RAWTYPES, UNCHECKED }) private static void addValueRange(final Builder builder, final Method method) { final PropertyValueRange<?> valueRange = calculateValueRange(method); if (valueRange != null) { builder.with(valueRange); final PropertyRangeConstraint<?> constraint = new PropertyRangeConstraint(valueRange); builder.add(constraint); } }
private void addComments(final Builder builder) { final PropertyCommentProxy commentProxy = new PropertyCommentProxy(context); builder.with(commentProxy); }
private void addDocumentProxy(final Builder builder, final Method method, final PropertyKey key) { final DocumentMetaDataProxy proxy = new MetaInfDocumentMetaDataProxy(key, context, method); builder.with(proxy); }