Home / Class/ AutoConfigurationClass Class — spring-boot Architecture

AutoConfigurationClass Class — spring-boot Architecture

Architecture documentation for the AutoConfigurationClass class in AutoConfigurationSorter.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationSorter.java lines 171–295

	private class AutoConfigurationClass {

		private final String className;

		private final MetadataReaderFactory metadataReaderFactory;

		private final @Nullable AutoConfigurationMetadata autoConfigurationMetadata;

		private volatile @Nullable AnnotationMetadata annotationMetadata;

		private volatile @Nullable Set<String> before;

		private volatile @Nullable Set<String> after;

		AutoConfigurationClass(String className, MetadataReaderFactory metadataReaderFactory,
				@Nullable AutoConfigurationMetadata autoConfigurationMetadata) {
			this.className = className;
			this.metadataReaderFactory = metadataReaderFactory;
			this.autoConfigurationMetadata = autoConfigurationMetadata;
		}

		boolean isAvailable() {
			try {
				if (!wasProcessed()) {
					getAnnotationMetadata();
				}
				return true;
			}
			catch (Exception ex) {
				return false;
			}
		}

		Set<String> getBefore() {
			Set<String> before = this.before;
			if (before == null) {
				before = getClassNames("AutoConfigureBefore", AutoConfigureBefore.class);
				this.before = before;
			}
			return before;
		}

		Set<String> getAfter() {
			Set<String> after = this.after;
			if (after == null) {
				after = getClassNames("AutoConfigureAfter", AutoConfigureAfter.class);
				this.after = after;
			}
			return after;
		}

		private Set<String> getClassNames(String metadataKey, Class<? extends Annotation> annotation) {
			Set<String> annotationValue = wasProcessed() ? getSet(metadataKey) : getAnnotationValue(annotation);
			return applyReplacements(annotationValue);
		}

		private Set<String> getSet(String metadataKey) {
			Assert.state(this.autoConfigurationMetadata != null, "'autoConfigurationMetadata' must not be null");
			return this.autoConfigurationMetadata.getSet(this.className, metadataKey, Collections.emptySet());
		}

		private Set<String> applyReplacements(Set<String> values) {
			if (AutoConfigurationSorter.this.replacementMapper == null) {
				return values;
			}
			Set<String> replaced = new LinkedHashSet<>(values);
			for (String value : values) {
				replaced.add(AutoConfigurationSorter.this.replacementMapper.apply(value));
			}
			return replaced;
		}

		private int getOrder() {
			if (wasProcessed()) {
				Assert.state(this.autoConfigurationMetadata != null, "'autoConfigurationMetadata' must not be null");
				return this.autoConfigurationMetadata.getInteger(this.className, "AutoConfigureOrder",
						AutoConfigureOrder.DEFAULT_ORDER);
			}
			Map<String, @Nullable Object> attributes = getAnnotationMetadata()
				.getAnnotationAttributes(AutoConfigureOrder.class.getName());
			if (attributes != null) {
				Integer value = (Integer) attributes.get("value");
				Assert.state(value != null, "'value' must not be null");
				return value;
			}
			return AutoConfigureOrder.DEFAULT_ORDER;
		}

		private boolean wasProcessed() {
			return (this.autoConfigurationMetadata != null
					&& this.autoConfigurationMetadata.wasProcessed(this.className));
		}

		private Set<String> getAnnotationValue(Class<?> annotation) {
			Map<String, @Nullable Object> attributes = getAnnotationMetadata()
				.getAnnotationAttributes(annotation.getName(), true);
			if (attributes == null) {
				return Collections.emptySet();
			}
			Set<String> result = new LinkedHashSet<>();
			String[] value = (String[]) attributes.get("value");
			String[] name = (String[]) attributes.get("name");
			Assert.state(value != null, "'value' must not be null");
			Assert.state(name != null, "'name' must not be null");
			Collections.addAll(result, value);
			Collections.addAll(result, name);
			return result;
		}

		private AnnotationMetadata getAnnotationMetadata() {
			AnnotationMetadata annotationMetadata = this.annotationMetadata;
			if (annotationMetadata == null) {
				try {
					MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(this.className);
					annotationMetadata = metadataReader.getAnnotationMetadata();
					this.annotationMetadata = annotationMetadata;
				}
				catch (IOException ex) {
					throw new IllegalStateException("Unable to read meta-data for class " + this.className, ex);
				}
			}
			return annotationMetadata;
		}

	}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free