Home / Class/ SpringProfileArbiter Class — spring-boot Architecture

SpringProfileArbiter Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java lines 42–118

@Plugin(name = "SpringProfile", category = Node.CATEGORY, elementType = Arbiter.ELEMENT_TYPE, deferChildren = true,
		printObject = true)
final class SpringProfileArbiter implements Arbiter {

	private final @Nullable Environment environment;

	private final Profiles profiles;

	private SpringProfileArbiter(@Nullable Environment environment, String[] profiles) {
		this.environment = environment;
		this.profiles = Profiles.of(profiles);
	}

	@Override
	public boolean isCondition() {
		return (this.environment != null) && this.environment.acceptsProfiles(this.profiles);
	}

	@PluginBuilderFactory
	static Builder newBuilder() {
		return new Builder();
	}

	/**
	 * Standard Builder to create the Arbiter.
	 */
	static final class Builder implements org.apache.logging.log4j.core.util.Builder<SpringProfileArbiter> {

		private static final Logger statusLogger = StatusLogger.getLogger();

		@PluginBuilderAttribute
		@SuppressWarnings("NullAway.Init")
		private String name;

		@PluginConfiguration
		@SuppressWarnings("NullAway.Init")
		private Configuration configuration;

		@PluginLoggerContext
		@SuppressWarnings("NullAway.Init")
		private LoggerContext loggerContext;

		private Builder() {
		}

		/**
		 * Sets the profile name or expression.
		 * @param name the profile name or expression
		 * @return this
		 * @see Profiles#of(String...)
		 */
		public Builder setName(String name) {
			this.name = name;
			return this;
		}

		@Override
		public SpringProfileArbiter build() {
			Environment environment = Log4J2LoggingSystem.getEnvironment(this.loggerContext);
			if (environment == null) {
				statusLogger.debug("Creating Arbiter without a Spring Environment");
			}
			String name = this.configuration.getStrSubstitutor().replace(this.name);
			String[] profiles = trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
			return new SpringProfileArbiter(environment, profiles);
		}

		// The array has no nulls in it, but StringUtils.trimArrayElements return
		// @Nullable String[]
		@SuppressWarnings("NullAway")
		private String[] trimArrayElements(String[] array) {
			return StringUtils.trimArrayElements(array);
		}

	}

}

Analyze Your Own Codebase

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

Try Supermodel Free