Java Code Examples for org.springframework.core.env.PropertySource#getName()

The following examples show how to use org.springframework.core.env.PropertySource#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationClassParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void addPropertySource(PropertySource<?> propertySource) {
	String name = propertySource.getName();
	MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();

	if (this.propertySourceNames.contains(name)) {
		// We've already added a version, we need to extend it
		PropertySource<?> existing = propertySources.get(name);
		if (existing != null) {
			PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ?
					((ResourcePropertySource) propertySource).withResourceName() : propertySource);
			if (existing instanceof CompositePropertySource) {
				((CompositePropertySource) existing).addFirstPropertySource(newSource);
			}
			else {
				if (existing instanceof ResourcePropertySource) {
					existing = ((ResourcePropertySource) existing).withResourceName();
				}
				CompositePropertySource composite = new CompositePropertySource(name);
				composite.addPropertySource(newSource);
				composite.addPropertySource(existing);
				propertySources.replace(name, composite);
			}
			return;
		}
	}

	if (this.propertySourceNames.isEmpty()) {
		propertySources.addLast(propertySource);
	}
	else {
		String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
		propertySources.addBefore(firstProcessed, propertySource);
	}
	this.propertySourceNames.add(name);
}
 
Example 2
Source File: ConfigurationClassParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void addPropertySource(PropertySource<?> propertySource) {
	String name = propertySource.getName();
	MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();

	if (this.propertySourceNames.contains(name)) {
		// We've already added a version, we need to extend it
		PropertySource<?> existing = propertySources.get(name);
		if (existing != null) {
			PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ?
					((ResourcePropertySource) propertySource).withResourceName() : propertySource);
			if (existing instanceof CompositePropertySource) {
				((CompositePropertySource) existing).addFirstPropertySource(newSource);
			}
			else {
				if (existing instanceof ResourcePropertySource) {
					existing = ((ResourcePropertySource) existing).withResourceName();
				}
				CompositePropertySource composite = new CompositePropertySource(name);
				composite.addPropertySource(newSource);
				composite.addPropertySource(existing);
				propertySources.replace(name, composite);
			}
			return;
		}
	}

	if (this.propertySourceNames.isEmpty()) {
		propertySources.addLast(propertySource);
	}
	else {
		String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
		propertySources.addBefore(firstProcessed, propertySource);
	}
	this.propertySourceNames.add(name);
}
 
Example 3
Source File: ConfigurationClassParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void addPropertySource(PropertySource<?> propertySource) {
	String name = propertySource.getName();
	MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
	if (propertySources.contains(name) && this.propertySourceNames.contains(name)) {
		// We've already added a version, we need to extend it
		PropertySource<?> existing = propertySources.get(name);
		PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ?
				((ResourcePropertySource) propertySource).withResourceName() : propertySource);
		if (existing instanceof CompositePropertySource) {
			((CompositePropertySource) existing).addFirstPropertySource(newSource);
		}
		else {
			if (existing instanceof ResourcePropertySource) {
				existing = ((ResourcePropertySource) existing).withResourceName();
			}
			CompositePropertySource composite = new CompositePropertySource(name);
			composite.addPropertySource(newSource);
			composite.addPropertySource(existing);
			propertySources.replace(name, composite);
		}
	}
	else {
		if (this.propertySourceNames.isEmpty()) {
			propertySources.addLast(propertySource);
		}
		else {
			String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
			propertySources.addBefore(firstProcessed, propertySource);
		}
	}
	this.propertySourceNames.add(name);
}
 
Example 4
Source File: AkkaConfigPropertyAdapter.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
public static boolean isEligiblePropertySource(PropertySource source) {
  // Exclude system environment properties and system property sources
  // because they are already included in the default configuration
  final String name = source.getName();
  return (source instanceof EnumerablePropertySource) &&
      !(
          name.equalsIgnoreCase(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME) ||
              name.equalsIgnoreCase(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
      );
}
 
Example 5
Source File: CachingDelegateEncryptablePropertySource.java    From jasypt-spring-boot with MIT License 5 votes vote down vote up
public CachingDelegateEncryptablePropertySource(PropertySource<T> delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) {
    super(delegate.getName(), delegate.getSource());
    Assert.notNull(delegate, "PropertySource delegate cannot be null");
    Assert.notNull(resolver, "EncryptablePropertyResolver cannot be null");
    Assert.notNull(filter, "EncryptablePropertyFilter cannot be null");
    this.delegate = delegate;
    this.resolver = resolver;
    this.filter = filter;
    this.cache = new HashMap<>();
}
 
Example 6
Source File: SpringConfigurationPropertySource.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
private static boolean hasSystemEnvironmentName(PropertySource<?> source) {
    String name = source.getName();
    return StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME.equals(name)
            || name.endsWith("-"
            + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
}
 
Example 7
Source File: EncryptablePropertySourceWrapper.java    From jasypt-spring-boot with MIT License 4 votes vote down vote up
public EncryptablePropertySourceWrapper(PropertySource<T> delegate, EncryptablePropertyResolver resolver, EncryptablePropertyFilter filter) {
    super(delegate.getName(), delegate.getSource());
    encryptableDelegate = new CachingDelegateEncryptablePropertySource<>(delegate, resolver, filter);
}
 
Example 8
Source File: SimpleBootstrapPropertySource.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
public SimpleBootstrapPropertySource(PropertySource<T> delegate) {
	super(BOOTSTRAP_PROPERTY_SOURCE_NAME + "-" + delegate.getName(),
			delegate.getSource());
	this.delegate = delegate;
}
 
Example 9
Source File: CloudConfigAwarePropertySource.java    From kork with Apache License 2.0 4 votes vote down vote up
CloudConfigAwarePropertySource(PropertySource source, ConfigurableApplicationContext context) {
  super(source.getName(), source);
  this.context = context;
}