/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found. * @param ann the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(AnnotationAttributes ann) { return (!ann.containsKey(this.requiredParameterName) || this.requiredParameterValue == ann.getBoolean(this.requiredParameterName)); }
/** * Determine if the annotated field or method requires its dependency. * <p>A 'required' dependency means that autowiring should fail when no beans * are found. Otherwise, the autowiring process will simply bypass the field * or method when no beans are found. * @param ann the Autowired annotation * @return whether the annotation indicates that a dependency is required */ protected boolean determineRequiredStatus(AnnotationAttributes ann) { return (!ann.containsKey(this.requiredParameterName) || this.requiredParameterValue == ann.getBoolean(this.requiredParameterName)); }
@Override public void visitEnd() { if (!this.allNestedAttributes.isEmpty()) { this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0])); } else if (!this.attributes.containsKey(this.attributeName)) { Class<? extends Annotation> annotationType = this.attributes.annotationType(); if (annotationType != null) { try { Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType(); if (attributeType.isArray()) { this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0)); } } catch (NoSuchMethodException ex) { // Corresponding attribute method not found: cannot expose empty array. } } } }
else if (!AnnotationUtils.VALUE.equals(attributeName) && attributes.containsKey(attributeName)) { overrideAttribute(element, annotation, attributes, attributeName, attributeName);
@Override public void visitEnd() { if (!this.allNestedAttributes.isEmpty()) { this.attributes.put(this.attributeName, this.allNestedAttributes.toArray(new AnnotationAttributes[0])); } else if (!this.attributes.containsKey(this.attributeName)) { Class<? extends Annotation> annotationType = this.attributes.annotationType(); if (annotationType != null) { try { Class<?> attributeType = annotationType.getMethod(this.attributeName).getReturnType(); if (attributeType.isArray()) { this.attributes.put(this.attributeName, Array.newInstance(attributeType.getComponentType(), 0)); } } catch (NoSuchMethodException ex) { // Corresponding attribute method not found: cannot expose empty array. } } } }
String attributeName = annotationAttribute.getName(); Object defaultValue = annotationAttribute.getDefaultValue(); if (defaultValue != null && !attributes.containsKey(attributeName)) { if (defaultValue instanceof Annotation) { defaultValue = getAnnotationAttributes((Annotation) defaultValue, false, true);
@Override public String[] selectImports(AnnotationMetadata importingClassMetadata) { Class<?> annotationType = EnableBatchProcessing.class; AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes( annotationType.getName(), false)); Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", annotationType.getSimpleName(), importingClassMetadata.getClassName())); String[] imports; if (attributes.containsKey("modular") && attributes.getBoolean("modular")) { imports = new String[] { ModularBatchConfiguration.class.getName() }; } else { imports = new String[] { SimpleBatchConfiguration.class.getName() }; } return imports; }
else if (!AnnotationUtils.VALUE.equals(attributeName) && attributes.containsKey(attributeName)) { overrideAttribute(element, annotation, attributes, attributeName, attributeName);
String attributeName = annotationAttribute.getName(); Object defaultValue = annotationAttribute.getDefaultValue(); if (defaultValue != null && !attributes.containsKey(attributeName)) { if (defaultValue instanceof Annotation) { defaultValue = getAnnotationAttributes((Annotation) defaultValue, false, true);
private void registerDefaultValues(Class<?> annotationClass) { // Check declared default values of attributes in the annotation type. Method[] annotationAttributes = annotationClass.getMethods(); for (Method annotationAttribute : annotationAttributes) { String attributeName = annotationAttribute.getName(); Object defaultValue = annotationAttribute.getDefaultValue(); if (defaultValue != null && !this.attributes.containsKey(attributeName)) { if (defaultValue instanceof Annotation) { defaultValue = AnnotationAttributes.fromMap( AnnotationUtils.getAnnotationAttributes((Annotation)defaultValue, false, true)); } else if (defaultValue instanceof Annotation[]) { Annotation[] realAnnotations = (Annotation[]) defaultValue; AnnotationAttributes[] mappedAnnotations = new AnnotationAttributes[realAnnotations.length]; for (int i = 0; i < realAnnotations.length; i++) { mappedAnnotations[i] = AnnotationAttributes.fromMap( AnnotationUtils.getAnnotationAttributes(realAnnotations[i], false, true)); } defaultValue = mappedAnnotations; } this.attributes.put(attributeName, defaultValue); } } } }
static String resolveFunctionId(AnnotationAttributes gemfireFunctionAttributes) { return gemfireFunctionAttributes.containsKey("id") ? gemfireFunctionAttributes.getString("id") : DEFAULT_FUNCTION_ID; }
@SuppressWarnings("unused") private IndexType resolveType(GemfirePersistentEntity<?> persistentEntity, GemfirePersistentProperty persistentProperty, AnnotationAttributes indexedAttributes, IndexType indexType) { IndexType resolvedIndexType = indexedAttributes.containsKey("type") ? indexedAttributes.getEnum("type") : null; return Optional.ofNullable(resolvedIndexType).orElse(indexType); } }
static void configureBatchSize(Object target, Method method, AnnotationAttributes gemfireFunctionAttributes, PojoFunctionWrapper function) { if (gemfireFunctionAttributes.containsKey("batchSize")) { int batchSize = gemfireFunctionAttributes.getNumber("batchSize"); Assert.isTrue(batchSize >= 0, String.format("%1$s.batchSize [%2$d] specified on [%3$s.%4$s] must be a non-negative value", GemfireFunction.class.getSimpleName(), batchSize, target.getClass().getName(), method.getName())); function.setBatchSize(batchSize); } }
static void configureHasResult(AnnotationAttributes gemfireFunctionAttributes, PojoFunctionWrapper function) { if (gemfireFunctionAttributes.containsKey("hasResult")) { if (Boolean.TRUE.equals(gemfireFunctionAttributes.getBoolean("hasResult"))) { function.setHasResult(true); } } }
@SuppressWarnings("unused") private String resolveFrom(GemfirePersistentEntity<?> persistentEntity, GemfirePersistentProperty persistentProperty, AnnotationAttributes indexedAttributes) { String from = indexedAttributes.containsKey("from") ? indexedAttributes.getString("from") : null; return (StringUtils.hasText(from) ? from : persistentEntity.getRegionName()); }
static void configureHighAvailability(AnnotationAttributes gemfireFunctionAttributes, PojoFunctionWrapper function) { if (gemfireFunctionAttributes.containsKey("HA")) { function.setHA(gemfireFunctionAttributes.getBoolean("HA")); } }
static void configureOptimizeForWrite(AnnotationAttributes gemfireFunctionAttributes, PojoFunctionWrapper function) { if (gemfireFunctionAttributes.containsKey("optimizeForWrite")) { function.setOptimizeForWrite(gemfireFunctionAttributes.getBoolean("optimizeForWrite")); } }
private <T> void setAttributeIfNotDefault(AnnotationAttributes diskStoreAttributes, String attributeName, T newValue, T defaultValue) { if (!diskStoreAttributes.containsKey(attributeName) || toString(diskStoreAttributes.get(attributeName)).equals(toString(defaultValue))) { diskStoreAttributes.put(attributeName, newValue); } }
@Override @SuppressWarnings("all") public void setImportMetadata(AnnotationMetadata importMetadata) { if (isAnnotationPresent(importMetadata)) { AnnotationAttributes memberNameAttributes = getAnnotationAttributes(importMetadata); setMemberName(memberNameAttributes.containsKey("value") ? memberNameAttributes.getString("value") : null); setMemberName(memberNameAttributes.containsKey("name") ? memberNameAttributes.getString("name") : null); } }
@Override @SuppressWarnings("all") public void setImportMetadata(AnnotationMetadata importMetadata) { if (isAnnotationPresent(importMetadata)) { AnnotationAttributes distributedSystemIdAttributes = getAnnotationAttributes(importMetadata); setDistributedSystemId(distributedSystemIdAttributes.containsKey("value") ? distributedSystemIdAttributes.getNumber("value") : null); setDistributedSystemId(distributedSystemIdAttributes.containsKey("id") ? distributedSystemIdAttributes.getNumber("id") : null); } }