Here are the examples of the java api org.springframework.core.env.PropertyResolver taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
85 Examples
19
Source : LogFileTests.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Test
public void noProperties() {
PropertyResolver resolver = getPropertyResolver(null, null);
LogFile logFile = LogFile.get(resolver);
replacedertThat(logFile).isNull();
}
19
Source : LoggingSystemProperties.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private void setSystemProperty(PropertyResolver resolver, String systemPropertyName, String propertyName) {
setSystemProperty(systemPropertyName, resolver.getProperty("logging." + propertyName));
}
19
Source : LoggingSystemProperties.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private PropertyResolver getPropertyResolver() {
if (this.environment instanceof ConfigurableEnvironment) {
PropertyResolver resolver = new PropertySourcesPropertyResolver(((ConfigurableEnvironment) this.environment).getPropertySources());
((PropertySourcesPropertyResolver) resolver).setIgnoreUnresolvableNestedPlaceholders(true);
return resolver;
}
return this.environment;
}
19
Source : LoggingSystemProperties.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
public void apply(LogFile logFile) {
PropertyResolver resolver = getPropertyResolver();
setSystemProperty(resolver, EXCEPTION_CONVERSION_WORD, "exception-conversion-word");
setSystemProperty(PID_KEY, new ApplicationPid().toString());
setSystemProperty(resolver, CONSOLE_LOG_PATTERN, "pattern.console");
setSystemProperty(resolver, FILE_LOG_PATTERN, "pattern.file");
setSystemProperty(resolver, FILE_MAX_HISTORY, "file.max-history");
setSystemProperty(resolver, FILE_MAX_SIZE, "file.max-size");
setSystemProperty(resolver, LOG_LEVEL_PATTERN, "pattern.level");
setSystemProperty(resolver, LOG_DATEFORMAT_PATTERN, "pattern.dateformat");
if (logFile != null) {
logFile.applyToSystemProperties();
}
}
19
Source : LogFile.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* Get a {@link LogFile} from the given Spring {@link Environment}.
* @param propertyResolver the {@link PropertyResolver} used to obtain the logging
* properties
* @return a {@link LogFile} or {@code null} if the environment didn't contain any
* suitable properties
*/
public static LogFile get(PropertyResolver propertyResolver) {
String file = propertyResolver.getProperty(FILE_PROPERTY);
String path = propertyResolver.getProperty(PATH_PROPERTY);
if (StringUtils.hasLength(file) || StringUtils.hasLength(path)) {
return new LogFile(file, path);
}
return null;
}
19
Source : DefaultLogbackConfiguration.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* Default logback configuration used by Spring Boot. Uses {@link LogbackConfigurator} to
* improve startup time. See also the {@code defaults.xml}, {@code console-appender.xml}
* and {@code file-appender.xml} files provided for clreplacedic {@code logback.xml} use.
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Vedran Pavic
* @since 1.1.2
*/
clreplaced DefaultLogbackConfiguration {
private static final String CONSOLE_LOG_PATTERN = "%clr(%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}}){faint} " + "%clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} " + "%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} " + "%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}";
private static final String FILE_LOG_PATTERN = "%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} " + "${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}";
private static final String MAX_FILE_SIZE = "10MB";
private final PropertyResolver patterns;
private final LogFile logFile;
DefaultLogbackConfiguration(LoggingInitializationContext initializationContext, LogFile logFile) {
this.patterns = getPatternsResolver(initializationContext.getEnvironment());
this.logFile = logFile;
}
private PropertyResolver getPatternsResolver(Environment environment) {
if (environment == null) {
return new PropertySourcesPropertyResolver(null);
}
if (environment instanceof ConfigurableEnvironment) {
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(((ConfigurableEnvironment) environment).getPropertySources());
resolver.setIgnoreUnresolvableNestedPlaceholders(true);
return resolver;
}
return environment;
}
public void apply(LogbackConfigurator config) {
synchronized (config.getConfigurationLock()) {
base(config);
Appender<ILoggingEvent> consoleAppender = consoleAppender(config);
if (this.logFile != null) {
Appender<ILoggingEvent> fileAppender = fileAppender(config, this.logFile.toString());
config.root(Level.INFO, consoleAppender, fileAppender);
} else {
config.root(Level.INFO, consoleAppender);
}
}
}
private void base(LogbackConfigurator config) {
config.conversionRule("clr", ColorConverter.clreplaced);
config.conversionRule("wex", WhitespaceThrowableProxyConverter.clreplaced);
config.conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter.clreplaced);
config.logger("org.apache.catalina.startup.DigesterFactory", Level.ERROR);
config.logger("org.apache.catalina.util.LifecycleBase", Level.ERROR);
config.logger("org.apache.coyote.http11.Http11NioProtocol", Level.WARN);
config.logger("org.apache.sshd.common.util.SecurityUtils", Level.WARN);
config.logger("org.apache.tomcat.util.net.NioSelectorPool", Level.WARN);
config.logger("org.eclipse.jetty.util.component.AbstractLifeCycle", Level.ERROR);
config.logger("org.hibernate.validator.internal.util.Version", Level.WARN);
}
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("logging.pattern.console", CONSOLE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
config.start(encoder);
appender.setEncoder(encoder);
config.appender("CONSOLE", appender);
return appender;
}
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("logging.pattern.file", FILE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
appender.setEncoder(encoder);
config.start(encoder);
appender.setFile(logFile);
setRollingPolicy(appender, config, logFile);
config.appender("FILE", appender);
return appender;
}
private void setRollingPolicy(RollingFileAppender<ILoggingEvent> appender, LogbackConfigurator config, String logFile) {
SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new SizeAndTimeBasedRollingPolicy<>();
rollingPolicy.setFileNamePattern(logFile + ".%d{yyyy-MM-dd}.%i.gz");
setMaxFileSize(rollingPolicy, this.patterns.getProperty("logging.file.max-size", MAX_FILE_SIZE));
rollingPolicy.setMaxHistory(this.patterns.getProperty("logging.file.max-history", Integer.clreplaced, CoreConstants.UNBOUND_HISTORY));
appender.setRollingPolicy(rollingPolicy);
rollingPolicy.setParent(appender);
config.start(rollingPolicy);
}
private void setMaxFileSize(SizeAndTimeBasedRollingPolicy<ILoggingEvent> rollingPolicy, String maxFileSize) {
try {
rollingPolicy.setMaxFileSize(FileSize.valueOf(maxFileSize));
} catch (NoSuchMethodError ex) {
// Logback < 1.1.8 used String configuration
Method method = ReflectionUtils.findMethod(SizeAndTimeBasedRollingPolicy.clreplaced, "setMaxFileSize", String.clreplaced);
ReflectionUtils.invokeMethod(method, rollingPolicy, maxFileSize);
}
}
}
19
Source : ResourceArrayPropertyEditor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Editor for {@link org.springframework.core.io.Resource} arrays, to
* automatically convert {@code String} location patterns
* (e.g. {@code "file:C:/my*.txt"} or {@code "clreplacedpath*:myfile.txt"})
* to {@code Resource} array properties. Can also translate a collection
* or array of location patterns into a merged Resource array.
*
* <p>A path may contain {@code ${...}} placeholders, to be
* resolved as {@link org.springframework.core.env.Environment} properties:
* e.g. {@code ${user.dir}}. Unresolvable placeholders are ignored by default.
*
* <p>Delegates to a {@link ResourcePatternResolver},
* by default using a {@link PathMatchingResourcePatternResolver}.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 1.1.2
* @see org.springframework.core.io.Resource
* @see ResourcePatternResolver
* @see PathMatchingResourcePatternResolver
*/
public clreplaced ResourceArrayPropertyEditor extends PropertyEditorSupport {
private static final Log logger = LogFactory.getLog(ResourceArrayPropertyEditor.clreplaced);
private final ResourcePatternResolver resourcePatternResolver;
@Nullable
private PropertyResolver propertyResolver;
private final boolean ignoreUnresolvablePlaceholders;
/**
* Create a new ResourceArrayPropertyEditor with a default
* {@link PathMatchingResourcePatternResolver} and {@link StandardEnvironment}.
* @see PathMatchingResourcePatternResolver
* @see Environment
*/
public ResourceArrayPropertyEditor() {
this(new PathMatchingResourcePatternResolver(), null, true);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
*/
public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, @Nullable PropertyResolver propertyResolver) {
this(resourcePatternResolver, propertyResolver, true);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
* @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
* if no corresponding system property could be found
*/
public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, @Nullable PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
replacedert.notNull(resourcePatternResolver, "ResourcePatternResolver must not be null");
this.resourcePatternResolver = resourcePatternResolver;
this.propertyResolver = propertyResolver;
this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
}
/**
* Treat the given text as a location pattern and convert it to a Resource array.
*/
@Override
public void setAsText(String text) {
String pattern = resolvePath(text).trim();
try {
setValue(this.resourcePatternResolver.getResources(pattern));
} catch (IOException ex) {
throw new IllegalArgumentException("Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage());
}
}
/**
* Treat the given value as a collection or array and convert it to a Resource array.
* Considers String elements as location patterns and takes Resource elements as-is.
*/
@Override
public void setValue(Object value) throws IllegalArgumentException {
if (value instanceof Collection || (value instanceof Object[] && !(value instanceof Resource[]))) {
Collection<?> input = (value instanceof Collection ? (Collection<?>) value : Arrays.asList((Object[]) value));
List<Resource> merged = new ArrayList<>();
for (Object element : input) {
if (element instanceof String) {
// A location pattern: resolve it into a Resource array.
// Might point to a single resource or to multiple resources.
String pattern = resolvePath((String) element).trim();
try {
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
for (Resource resource : resources) {
if (!merged.contains(resource)) {
merged.add(resource);
}
}
} catch (IOException ex) {
// ignore - might be an unresolved placeholder or non-existing base directory
if (logger.isDebugEnabled()) {
logger.debug("Could not retrieve resources for pattern '" + pattern + "'", ex);
}
}
} else if (element instanceof Resource) {
// A Resource object: add it to the result.
Resource resource = (Resource) element;
if (!merged.contains(resource)) {
merged.add(resource);
}
} else {
throw new IllegalArgumentException("Cannot convert element [" + element + "] to [" + Resource.clreplaced.getName() + "]: only location String and Resource object supported");
}
}
super.setValue(merged.toArray(new Resource[0]));
} else {
// An arbitrary value: probably a String or a Resource array.
// setAsText will be called for a String; a Resource array will be used as-is.
super.setValue(value);
}
}
/**
* Resolve the given path, replacing placeholders with
* corresponding system property values if necessary.
* @param path the original file path
* @return the resolved file path
* @see PropertyResolver#resolvePlaceholders
* @see PropertyResolver#resolveRequiredPlaceholders(String)
*/
protected String resolvePath(String path) {
if (this.propertyResolver == null) {
this.propertyResolver = new StandardEnvironment();
}
return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) : this.propertyResolver.resolveRequiredPlaceholders(path));
}
}
19
Source : ResourceEditor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* {@link java.beans.PropertyEditor Editor} for {@link Resource}
* descriptors, to automatically convert {@code String} locations
* e.g. {@code file:C:/myfile.txt} or {@code clreplacedpath:myfile.txt} to
* {@code Resource} properties instead of using a {@code String} location property.
*
* <p>The path may contain {@code ${...}} placeholders, to be
* resolved as {@link org.springframework.core.env.Environment} properties:
* e.g. {@code ${user.dir}}. Unresolvable placeholders are ignored by default.
*
* <p>Delegates to a {@link ResourceLoader} to do the heavy lifting,
* by default using a {@link DefaultResourceLoader}.
*
* @author Juergen Hoeller
* @author Dave Syer
* @author Chris Beams
* @since 28.12.2003
* @see Resource
* @see ResourceLoader
* @see DefaultResourceLoader
* @see PropertyResolver#resolvePlaceholders
*/
public clreplaced ResourceEditor extends PropertyEditorSupport {
private final ResourceLoader resourceLoader;
@Nullable
private PropertyResolver propertyResolver;
private final boolean ignoreUnresolvablePlaceholders;
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using a {@link DefaultResourceLoader} and {@link StandardEnvironment}.
*/
public ResourceEditor() {
this(new DefaultResourceLoader(), null);
}
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using the given {@link ResourceLoader} and {@link PropertyResolver}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
*/
public ResourceEditor(ResourceLoader resourceLoader, @Nullable PropertyResolver propertyResolver) {
this(resourceLoader, propertyResolver, true);
}
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using the given {@link ResourceLoader}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
* @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
* if no corresponding property could be found in the given {@code propertyResolver}
*/
public ResourceEditor(ResourceLoader resourceLoader, @Nullable PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
replacedert.notNull(resourceLoader, "ResourceLoader must not be null");
this.resourceLoader = resourceLoader;
this.propertyResolver = propertyResolver;
this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
}
@Override
public void setAsText(String text) {
if (StringUtils.hasText(text)) {
String locationToUse = resolvePath(text).trim();
setValue(this.resourceLoader.getResource(locationToUse));
} else {
setValue(null);
}
}
/**
* Resolve the given path, replacing placeholders with corresponding
* property values from the {@code environment} if necessary.
* @param path the original file path
* @return the resolved file path
* @see PropertyResolver#resolvePlaceholders
* @see PropertyResolver#resolveRequiredPlaceholders
*/
protected String resolvePath(String path) {
if (this.propertyResolver == null) {
this.propertyResolver = new StandardEnvironment();
}
return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) : this.propertyResolver.resolveRequiredPlaceholders(path));
}
@Override
@Nullable
public String getAsText() {
Resource value = (Resource) getValue();
try {
// Try to determine URL for resource.
return (value != null ? value.getURL().toExternalForm() : "");
} catch (IOException ex) {
// Couldn't determine resource URL - return null to indicate
// that there is no appropriate text representation.
return null;
}
}
}
19
Source : OnMissingPropertyCondition.java
with Apache License 2.0
from spring-projects
with Apache License 2.0
from spring-projects
private Collection<String> findMatchingProperties(PropertyResolver propertyResolver, List<String> propertyNames) {
return propertyNames.stream().filter(propertyResolver::containsProperty).collect(Collectors.toSet());
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from smallFive55
with Apache License 2.0
from smallFive55
private static String resolvePlaceholders(String attributeValue, PropertyResolver propertyResolver) {
String resolvedValue = attributeValue;
if (propertyResolver != null) {
resolvedValue = propertyResolver.resolvePlaceholders(resolvedValue);
resolvedValue = trimWhitespace(resolvedValue);
}
return resolvedValue;
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from smallFive55
with Apache License 2.0
from smallFive55
/**
* Get the {@link Annotation} attributes
*
* @param annotation specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return non-null
* @since 2.6.6
*/
public static Map<String, Object> getAttributes(Annotation annotation, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
Set<String> ignoreAttributeNamesSet = new HashSet<String>(arrayToList(ignoreAttributeNames));
Map<String, Object> attributes = getAnnotationAttributes(annotation);
Map<String, Object> actualAttributes = new LinkedHashMap<String, Object>();
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
String attributeName = entry.getKey();
Object attributeValue = entry.getValue();
// ignore default attribute value
if (ignoreDefaultValue && nullSafeEquals(attributeValue, getDefaultValue(annotation, attributeName))) {
continue;
}
// ignore attribute name
if (ignoreAttributeNamesSet.contains(attributeName)) {
continue;
}
/**
* @since 2.6.6
* ignore annotation member
*/
if (attributeValue.getClreplaced().isAnnotation()) {
continue;
}
if (attributeValue.getClreplaced().isArray() && attributeValue.getClreplaced().getComponentType().isAnnotation()) {
continue;
}
if (attributeValue instanceof String) {
attributeValue = resolvePlaceholders(valueOf(attributeValue), propertyResolver);
} else if (attributeValue instanceof String[]) {
String[] values = (String[]) attributeValue;
for (int i = 0; i < values.length; i++) {
values[i] = resolvePlaceholders(values[i], propertyResolver);
}
attributeValue = values;
}
actualAttributes.put(attributeName, attributeValue);
}
return actualAttributes;
}
19
Source : AnnotationPropertyValuesAdapter.java
with Apache License 2.0
from smallFive55
with Apache License 2.0
from smallFive55
/**
* {@link Annotation} {@link PropertyValues} Adapter
*
* @see Annotation
* @see PropertyValues
* @since 2.5.11
*/
clreplaced AnnotationPropertyValuesAdapter implements PropertyValues {
private final Annotation annotation;
private final PropertyResolver propertyResolver;
private final boolean ignoreDefaultValue;
private final PropertyValues delegate;
public AnnotationPropertyValuesAdapter(Annotation annotation, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
this.annotation = annotation;
this.propertyResolver = propertyResolver;
this.ignoreDefaultValue = ignoreDefaultValue;
this.delegate = adapt(annotation, ignoreDefaultValue, ignoreAttributeNames);
}
public AnnotationPropertyValuesAdapter(Annotation annotation, PropertyResolver propertyResolver, String... ignoreAttributeNames) {
this(annotation, propertyResolver, true, ignoreAttributeNames);
}
private PropertyValues adapt(Annotation annotation, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return new MutablePropertyValues(getAttributes(annotation, propertyResolver, ignoreDefaultValue, ignoreAttributeNames));
}
public Annotation getAnnotation() {
return annotation;
}
public boolean isIgnoreDefaultValue() {
return ignoreDefaultValue;
}
@Override
public PropertyValue[] getPropertyValues() {
return delegate.getPropertyValues();
}
@Override
public PropertyValue getPropertyValue(String propertyName) {
return delegate.getPropertyValue(propertyName);
}
@Override
public PropertyValues changesSince(PropertyValues old) {
return delegate.changesSince(old);
}
@Override
public boolean contains(String propertyName) {
return delegate.contains(propertyName);
}
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
}
19
Source : PropertiesPlaceholderResolver.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
/**
* Placeholder Resolver for {@link Properties properties}
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.1.0
*/
public clreplaced PropertiesPlaceholderResolver {
private final PropertyResolver propertyResolver;
public PropertiesPlaceholderResolver(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}
/**
* Resolve placeholders in specified {@link Annotation annotation}
*
* @param annotation {@link Annotation annotation}
* @return Resolved {@link Properties source properties}
*/
public Properties resolve(Annotation annotation) {
Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation);
return resolve(attributes);
}
/**
* Resolve placeholders in specified {@link Map properties}
*
* @param properties {@link Map source properties}
* @return Resolved {@link Properties source properties}
*/
public Properties resolve(Map<?, ?> properties) {
Properties resolvedProperties = new Properties();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
if (entry.getValue() instanceof CharSequence) {
String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
String resolvedValue = propertyResolver.resolvePlaceholders(value);
if (StringUtils.hasText(resolvedValue)) {
// set properties if has test
resolvedProperties.setProperty(key, resolvedValue);
}
}
}
return resolvedProperties;
}
}
19
Source : NacosUtils.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
public static Properties resolveProperties(NacosProperties nacosProperties, PropertyResolver propertyResolver) {
return resolveProperties(nacosProperties, propertyResolver, null);
}
19
Source : NacosUtils.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
/**
* Resolve placeholders of properties via specified {@link PropertyResolver} if
* present
*
* @param properties The properties
* @param propertyResolver {@link PropertyResolver} instance, for instance,
* {@link Environment}
* @return a new instance of {@link Properties} after resolving.
*/
public static Properties resolveProperties(Map<?, ?> properties, PropertyResolver propertyResolver) {
PropertiesPlaceholderResolver propertiesPlaceholderResolver = new PropertiesPlaceholderResolver(propertyResolver);
return propertiesPlaceholderResolver.resolve(properties);
}
19
Source : NacosUtils.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
/**
* {@link #resolveProperties(Map, PropertyResolver) Resolve} placeholders of
* {@link NacosProperties @NacosProperties}'s attributes via specified
* {@link PropertyResolver} if present, or try to
* {@link #merge(Properties, Properties) merge} from default properties
*
* @param attributes {@link NacosProperties @NacosProperties}'s attributes
* @param propertyResolver the resolver of properties' placeholder
* @param defaultProperties default properties
* @return a new resolved {@link Properties} properties
* @see #resolveProperties(Map, PropertyResolver)
*/
public static Properties resolveProperties(Map<String, Object> attributes, PropertyResolver propertyResolver, Properties defaultProperties) {
if (CollectionUtils.isEmpty(attributes)) {
return defaultProperties;
}
Properties resolveProperties = resolveProperties(attributes, propertyResolver);
merge(resolveProperties, defaultProperties);
return resolveProperties;
}
19
Source : NacosUtils.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
public static Properties resolveProperties(NacosProperties nacosProperties, PropertyResolver propertyResolver, Properties defaultProperties) {
Map<String, Object> attributes = getAnnotationAttributes(nacosProperties);
return resolveProperties(attributes, propertyResolver, defaultProperties);
}
19
Source : PropertyResolverMessageBundle.java
with Apache License 2.0
from leangen
with Apache License 2.0
from leangen
public clreplaced PropertyResolverMessageBundle implements MessageBundle {
private final PropertyResolver propertyResolver;
public PropertyResolverMessageBundle(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}
@Override
public String getMessage(String key) {
return propertyResolver.getProperty(key);
}
@Override
public boolean containsKey(String key) {
return propertyResolver.containsProperty(key);
}
@Override
public String interpolate(String template) {
return propertyResolver.resolvePlaceholders(template);
}
}
19
Source : ResourceArrayPropertyEditor.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Editor for {@link org.springframework.core.io.Resource} arrays, to
* automatically convert {@code String} location patterns
* (e.g. {@code "file:C:/my*.txt"} or {@code "clreplacedpath*:myfile.txt"})
* to {@code Resource} array properties. Can also translate a collection
* or array of location patterns into a merged Resource array.
*
* <p>A path may contain {@code ${...}} placeholders, to be
* resolved as {@link org.springframework.core.env.Environment} properties:
* e.g. {@code ${user.dir}}. Unresolvable placeholders are ignored by default.
*
* <p>Delegates to a {@link ResourcePatternResolver},
* by default using a {@link PathMatchingResourcePatternResolver}.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 1.1.2
* @see org.springframework.core.io.Resource
* @see ResourcePatternResolver
* @see PathMatchingResourcePatternResolver
*/
public clreplaced ResourceArrayPropertyEditor extends PropertyEditorSupport {
private static final Log logger = LogFactory.getLog(ResourceArrayPropertyEditor.clreplaced);
private final ResourcePatternResolver resourcePatternResolver;
private PropertyResolver propertyResolver;
private final boolean ignoreUnresolvablePlaceholders;
/**
* Create a new ResourceArrayPropertyEditor with a default
* {@link PathMatchingResourcePatternResolver} and {@link StandardEnvironment}.
* @see PathMatchingResourcePatternResolver
* @see Environment
*/
public ResourceArrayPropertyEditor() {
this(new PathMatchingResourcePatternResolver(), null, true);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
*/
public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, PropertyResolver propertyResolver) {
this(resourcePatternResolver, propertyResolver, true);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
* @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
* if no corresponding system property could be found
*/
public ResourceArrayPropertyEditor(ResourcePatternResolver resourcePatternResolver, PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
replacedert.notNull(resourcePatternResolver, "ResourcePatternResolver must not be null");
this.resourcePatternResolver = resourcePatternResolver;
this.propertyResolver = propertyResolver;
this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
}
/**
* Treat the given text as a location pattern and convert it to a Resource array.
*/
@Override
public void setAsText(String text) {
String pattern = resolvePath(text).trim();
try {
setValue(this.resourcePatternResolver.getResources(pattern));
} catch (IOException ex) {
throw new IllegalArgumentException("Could not resolve resource location pattern [" + pattern + "]: " + ex.getMessage());
}
}
/**
* Treat the given value as a collection or array and convert it to a Resource array.
* Considers String elements as location patterns and takes Resource elements as-is.
*/
@Override
public void setValue(Object value) throws IllegalArgumentException {
if (value instanceof Collection || (value instanceof Object[] && !(value instanceof Resource[]))) {
Collection<?> input = (value instanceof Collection ? (Collection<?>) value : Arrays.asList((Object[]) value));
List<Resource> merged = new ArrayList<Resource>();
for (Object element : input) {
if (element instanceof String) {
// A location pattern: resolve it into a Resource array.
// Might point to a single resource or to multiple resources.
String pattern = resolvePath((String) element).trim();
try {
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
for (Resource resource : resources) {
if (!merged.contains(resource)) {
merged.add(resource);
}
}
} catch (IOException ex) {
// ignore - might be an unresolved placeholder or non-existing base directory
if (logger.isDebugEnabled()) {
logger.debug("Could not retrieve resources for pattern '" + pattern + "'", ex);
}
}
} else if (element instanceof Resource) {
// A Resource object: add it to the result.
Resource resource = (Resource) element;
if (!merged.contains(resource)) {
merged.add(resource);
}
} else {
throw new IllegalArgumentException("Cannot convert element [" + element + "] to [" + Resource.clreplaced.getName() + "]: only location String and Resource object supported");
}
}
super.setValue(merged.toArray(new Resource[merged.size()]));
} else {
// An arbitrary value: probably a String or a Resource array.
// setAsText will be called for a String; a Resource array will be used as-is.
super.setValue(value);
}
}
/**
* Resolve the given path, replacing placeholders with
* corresponding system property values if necessary.
* @param path the original file path
* @return the resolved file path
* @see PropertyResolver#resolvePlaceholders
* @see PropertyResolver#resolveRequiredPlaceholders(String)
*/
protected String resolvePath(String path) {
if (this.propertyResolver == null) {
this.propertyResolver = new StandardEnvironment();
}
return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) : this.propertyResolver.resolveRequiredPlaceholders(path));
}
}
19
Source : ResourceEditor.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* {@link java.beans.PropertyEditor Editor} for {@link Resource}
* descriptors, to automatically convert {@code String} locations
* e.g. {@code file:C:/myfile.txt} or {@code clreplacedpath:myfile.txt} to
* {@code Resource} properties instead of using a {@code String} location property.
*
* <p>The path may contain {@code ${...}} placeholders, to be
* resolved as {@link org.springframework.core.env.Environment} properties:
* e.g. {@code ${user.dir}}. Unresolvable placeholders are ignored by default.
*
* <p>Delegates to a {@link ResourceLoader} to do the heavy lifting,
* by default using a {@link DefaultResourceLoader}.
*
* @author Juergen Hoeller
* @author Dave Syer
* @author Chris Beams
* @since 28.12.2003
* @see Resource
* @see ResourceLoader
* @see DefaultResourceLoader
* @see PropertyResolver#resolvePlaceholders
*/
public clreplaced ResourceEditor extends PropertyEditorSupport {
private final ResourceLoader resourceLoader;
private PropertyResolver propertyResolver;
private final boolean ignoreUnresolvablePlaceholders;
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using a {@link DefaultResourceLoader} and {@link StandardEnvironment}.
*/
public ResourceEditor() {
this(new DefaultResourceLoader(), null);
}
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using the given {@link ResourceLoader} and {@link PropertyResolver}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
*/
public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver) {
this(resourceLoader, propertyResolver, true);
}
/**
* Create a new instance of the {@link ResourceEditor} clreplaced
* using the given {@link ResourceLoader}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
* @param ignoreUnresolvablePlaceholders whether to ignore unresolvable placeholders
* if no corresponding property could be found in the given {@code propertyResolver}
*/
public ResourceEditor(ResourceLoader resourceLoader, PropertyResolver propertyResolver, boolean ignoreUnresolvablePlaceholders) {
replacedert.notNull(resourceLoader, "ResourceLoader must not be null");
this.resourceLoader = resourceLoader;
this.propertyResolver = propertyResolver;
this.ignoreUnresolvablePlaceholders = ignoreUnresolvablePlaceholders;
}
@Override
public void setAsText(String text) {
if (StringUtils.hasText(text)) {
String locationToUse = resolvePath(text).trim();
setValue(this.resourceLoader.getResource(locationToUse));
} else {
setValue(null);
}
}
/**
* Resolve the given path, replacing placeholders with corresponding
* property values from the {@code environment} if necessary.
* @param path the original file path
* @return the resolved file path
* @see PropertyResolver#resolvePlaceholders
* @see PropertyResolver#resolveRequiredPlaceholders
*/
protected String resolvePath(String path) {
if (this.propertyResolver == null) {
this.propertyResolver = new StandardEnvironment();
}
return (this.ignoreUnresolvablePlaceholders ? this.propertyResolver.resolvePlaceholders(path) : this.propertyResolver.resolveRequiredPlaceholders(path));
}
@Override
public String getAsText() {
Resource value = (Resource) getValue();
try {
// Try to determine URL for resource.
return (value != null ? value.getURL().toExternalForm() : "");
} catch (IOException ex) {
// Couldn't determine resource URL - return null to indicate
// that there is no appropriate text representation.
return null;
}
}
}
19
Source : CorePropertyPlaceholderConfigurer.java
with Apache License 2.0
from igloo-project
with Apache License 2.0
from igloo-project
/**
* <p>Gère la récupération des propriétés de configuration.</p>
*
* <p>Ajout de fonctionnalités supplémentaires par rapport au configurer Spring permettant :
* - la résolution via l'appel aux méthodes getPropertyAsXXXX(propertyName) (avec subsreplacedution des placeholders)</p>
*
* @author Open Wide
*/
public clreplaced CorePropertyPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {
/**
* Propriétés de configuration.
*/
private PropertyResolver propertyResolver;
/**
* Retourne une propriété spécifique à partir de sa clé La propriété
* retournée n'est pas castée.
*
* @param key la clé
* @return l'objet propriété
*/
public String getProperty(String key) {
String rawValue = propertyResolver.getProperty(key);
if (rawValue != null) {
return propertyResolver.resolvePlaceholders(rawValue);
} else {
return null;
}
}
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, ConfigurablePropertyResolver propertyResolver) throws BeansException {
this.propertyResolver = propertyResolver;
// on garde les traitements dans la clreplacede parente
super.processProperties(beanFactoryToProcess, propertyResolver);
}
}
19
Source : TestStaticProperties.java
with Apache License 2.0
from i-novus-llc
with Apache License 2.0
from i-novus-llc
@Override
public void setPropertyResolver(PropertyResolver propertyResolver) {
TestStaticProperties.propertyResolver = propertyResolver;
}
19
Source : AppConfigJsonWriter.java
with Apache License 2.0
from i-novus-llc
with Apache License 2.0
from i-novus-llc
public void setPropertyResolver(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}
19
Source : N2oApplicationBuilder.java
with Apache License 2.0
from i-novus-llc
with Apache License 2.0
from i-novus-llc
/**
* Добавить системные свойства (key=value)
*/
public N2oApplicationBuilder properties(String... properties) {
PropertyResolver systemProperties = environment.getSystemProperties();
if (!(systemProperties instanceof SimplePropertyResolver))
throw new IllegalArgumentException("System properties is readonly");
Stream.of(properties).forEach(p -> {
String[] split = p.contains("=") ? p.split("=") : p.split(":");
((SimplePropertyResolver) systemProperties).setProperty(split[0], split[1]);
});
return this;
}
19
Source : IOProcessorImpl.java
with Apache License 2.0
from i-novus-llc
with Apache License 2.0
from i-novus-llc
public void setSystemProperties(PropertyResolver systemProperties) {
this.systemProperties = systemProperties;
}
19
Source : LogFile.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
/**
* Get a {@link LogFile} from the given Spring {@link Environment}.
*
* @param propertyResolver the {@link PropertyResolver} used to obtain the logging
* properties
* @return a {@link LogFile} or {@code null} if the environment didn't contain any
* suitable properties
*/
public static LogFile get(PropertyResolver propertyResolver) {
String file = propertyResolver.getProperty(FILE_PROPERTY);
String path = propertyResolver.getProperty(PATH_PROPERTY);
if (StringUtils.hasLength(file) || StringUtils.hasLength(path)) {
return new LogFile(file, path);
}
return null;
}
19
Source : AnnotationPropertyValuesAdapter.java
with Apache License 2.0
from finleytianhe
with Apache License 2.0
from finleytianhe
/**
* {@link Annotation} {@link PropertyValues} Adapter
*
* @see Annotation
* @see PropertyValues
* @since 2.5.11
*/
// 实现接口的方式适配器模式实现
clreplaced AnnotationPropertyValuesAdapter implements PropertyValues {
private final Annotation annotation;
private final PropertyResolver propertyResolver;
private final boolean ignoreDefaultValue;
private final PropertyValues delegate;
public AnnotationPropertyValuesAdapter(Annotation annotation, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
this.annotation = annotation;
this.propertyResolver = propertyResolver;
this.ignoreDefaultValue = ignoreDefaultValue;
this.delegate = adapt(annotation, ignoreDefaultValue, ignoreAttributeNames);
}
public AnnotationPropertyValuesAdapter(Annotation annotation, PropertyResolver propertyResolver, String... ignoreAttributeNames) {
this(annotation, propertyResolver, true, ignoreAttributeNames);
}
private PropertyValues adapt(Annotation annotation, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return new MutablePropertyValues(getAttributes(annotation, propertyResolver, ignoreDefaultValue, ignoreAttributeNames));
}
public Annotation getAnnotation() {
return annotation;
}
public boolean isIgnoreDefaultValue() {
return ignoreDefaultValue;
}
@Override
public PropertyValue[] getPropertyValues() {
return delegate.getPropertyValues();
}
@Override
public PropertyValue getPropertyValue(String propertyName) {
return delegate.getPropertyValue(propertyName);
}
@Override
public PropertyValues changesSince(PropertyValues old) {
return delegate.changesSince(old);
}
@Override
public boolean contains(String propertyName) {
return delegate.contains(propertyName);
}
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
}
19
Source : PropertiesPlaceholderResolver.java
with Apache License 2.0
from fashionbrot
with Apache License 2.0
from fashionbrot
/**
* Placeholder Resolver for {@link Properties properties}
*/
public clreplaced PropertiesPlaceholderResolver {
private final PropertyResolver propertyResolver;
public PropertiesPlaceholderResolver(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}
/**
* Resolve placeholders in specified {@link Annotation annotation}
*
* @param annotation {@link Annotation annotation}
* @return Resolved {@link Properties source properties}
*/
public Properties resolve(Annotation annotation) {
Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation);
return resolve(attributes);
}
/**
* Resolve placeholders in specified {@link Map properties}
*
* @param properties {@link Map source properties}
* @return Resolved {@link Properties source properties}
*/
public Properties resolve(Map<?, ?> properties) {
Properties resolvedProperties = new Properties();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
if (entry.getValue() instanceof CharSequence) {
String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
if (!StringUtils.isEmpty(value)) {
// set properties if has test
String resolvedValue = propertyResolver.resolvePlaceholders(value);
resolvedProperties.setProperty(key, resolvedValue);
} else {
resolvedProperties.setProperty(key, value);
}
}
}
return resolvedProperties;
}
public Properties resolveNull(Map<?, ?> properties) {
Properties resolvedProperties = new Properties();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
if (entry.getValue() instanceof CharSequence) {
String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue());
String resolvedValue = propertyResolver.resolvePlaceholders(value);
if (value.startsWith("${") && value.endsWith("}")) {
if (!value.equals(resolvedValue) && StringUtils.hasText(resolvedValue)) {
resolvedProperties.setProperty(key, resolvedValue);
} else {
resolvedProperties.setProperty(key, "");
}
} else {
resolvedProperties.setProperty(key, value);
}
}
}
return resolvedProperties;
}
}
19
Source : BeanUtil.java
with Apache License 2.0
from fashionbrot
with Apache License 2.0
from fashionbrot
/**
* Resolve placeholders of properties via specified {@link PropertyResolver} if present
*
* @param properties The properties
* @param propertyResolver {@link PropertyResolver} instance, for instance, {@link Environment}
* @return a new instance of {@link Properties} after resolving.
*/
public static Properties resolveProperties(Map<?, ?> properties, PropertyResolver propertyResolver) {
PropertiesPlaceholderResolver propertiesPlaceholderResolver = new PropertiesPlaceholderResolver(propertyResolver);
return propertiesPlaceholderResolver.resolve(properties);
}
19
Source : SpringPropertyResolverAccessor.java
with Apache License 2.0
from fangjinuo
with Apache License 2.0
from fangjinuo
@Override
public String getString(String key, String defaultValue) {
Preconditions.checkNotEmpty(key, "the property name is null or empty");
PropertyResolver propertySource = getTarget();
return propertySource.getProperty(key, defaultValue);
}
19
Source : DubboAutoConfiguration.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Creates {@link ServiceAnnotationBeanPostProcessor} Bean
*
* @param propertyResolver {@link PropertyResolver} Bean
* @return {@link ServiceAnnotationBeanPostProcessor}
*/
@ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnBean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
@Bean
public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(@Qualifier(BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) PropertyResolver propertyResolver) {
Set<String> packagesToScan = propertyResolver.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.clreplaced, emptySet());
return new ServiceAnnotationBeanPostProcessor(packagesToScan);
}
19
Source : DelegatingPropertyResolver.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Delegating {@link PropertyResolver}
*
* @since 2.7.1
*/
clreplaced DelegatingPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
DelegatingPropertyResolver(PropertyResolver delegate) {
replacedert.notNull(delegate, "The delegate of PropertyResolver must not be null");
this.delegate = delegate;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
@Nullable
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
@Nullable
public <T> T getProperty(String key, Clreplaced<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Clreplaced<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Clreplaced<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
}
19
Source : JasyptSpringEncryptedPropertiesParser.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public clreplaced JasyptSpringEncryptedPropertiesParser extends DefaultPropertiesParser {
private PropertyResolver propertyResolver;
private StringEncryptor stringEncryptor;
@Autowired
public JasyptSpringEncryptedPropertiesParser(PropertyResolver propertyResolver, StringEncryptor stringEncryptor) {
this.propertyResolver = propertyResolver;
this.stringEncryptor = stringEncryptor;
}
@Override
public String parseProperty(String key, String value, PropertiesLookup properties) {
String originalValue = this.propertyResolver.getProperty(key);
return isEncryptedValue(originalValue) ? decrypt(originalValue, this.stringEncryptor) : originalValue;
}
}
19
Source : CompatibleRelaxedPropertyResolver.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Relaxed {@link PropertyResolver} is compatible between Spring Boot 1.x and 2.0
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 1.0.3
*/
public clreplaced CompatibleRelaxedPropertyResolver implements PropertyResolver {
private final PropertyResolver delegate;
public CompatibleRelaxedPropertyResolver(PropertyResolver origin) {
this.delegate = delegatingPropertyResolver(origin);
}
private PropertyResolver delegatingPropertyResolver(PropertyResolver origin) {
return origin;
}
@Override
public boolean containsProperty(String key) {
return delegate.containsProperty(key);
}
@Override
public String getProperty(String key) {
return delegate.getProperty(key);
}
@Override
public String getProperty(String key, String defaultValue) {
return delegate.getProperty(key, defaultValue);
}
@Override
public <T> T getProperty(String key, Clreplaced<T> targetType) {
return delegate.getProperty(key, targetType);
}
@Override
public <T> T getProperty(String key, Clreplaced<T> targetType, T defaultValue) {
return delegate.getProperty(key, targetType, defaultValue);
}
// Compatible with Spring Boot 1.x
@Deprecated
public <T> Clreplaced<T> getPropertyAsClreplaced(String key, Clreplaced<T> targetType) {
return targetType;
}
@Override
public String getRequiredProperty(String key) throws IllegalStateException {
return delegate.getRequiredProperty(key);
}
@Override
public <T> T getRequiredProperty(String key, Clreplaced<T> targetType) throws IllegalStateException {
return delegate.getRequiredProperty(key, targetType);
}
@Override
public String resolvePlaceholders(String text) {
return delegate.resolvePlaceholders(text);
}
@Override
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
return delegate.resolveRequiredPlaceholders(text);
}
}
19
Source : CompatibleRelaxedPropertyResolver.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private PropertyResolver delegatingPropertyResolver(PropertyResolver origin) {
return origin;
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link AnnotationAttributes}
*
* @param annotation specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param clreplacedValuesreplacedtring whether to turn Clreplaced references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Clreplaced references
* @param nestedAnnotationsAsMap whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @param ignoreDefaultValue whether ignore default value or not
* @return non-null
* @see #getAttributes(Annotation, PropertyResolver, boolean, String...)
* @see #getAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, String...)
* @since 1.0.11
*/
public static AnnotationAttributes getAnnotationAttributes(Annotation annotation, PropertyResolver propertyResolver, boolean clreplacedValuesreplacedtring, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return fromMap(getAttributes(annotation, propertyResolver, clreplacedValuesreplacedtring, nestedAnnotationsAsMap, ignoreDefaultValue, ignoreAttributeNames));
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link Annotation} attributes
*
* @param annotationAttributes the attributes of specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return non-null
* @since 1.0.4
*/
public static Map<String, Object> getAttributes(Map<String, Object> annotationAttributes, PropertyResolver propertyResolver, String... ignoreAttributeNames) {
Set<String> ignoreAttributeNamesSet = new HashSet<String>(arrayToList(ignoreAttributeNames));
Map<String, Object> actualAttributes = new LinkedHashMap<String, Object>();
for (Map.Entry<String, Object> annotationAttribute : annotationAttributes.entrySet()) {
String attributeName = annotationAttribute.getKey();
Object attributeValue = annotationAttribute.getValue();
// ignore attribute name
if (ignoreAttributeNamesSet.contains(attributeName)) {
continue;
}
if (attributeValue instanceof String) {
attributeValue = resolvePlaceholders(valueOf(attributeValue), propertyResolver);
} else if (attributeValue instanceof String[]) {
String[] values = (String[]) attributeValue;
for (int i = 0; i < values.length; i++) {
values[i] = resolvePlaceholders(values[i], propertyResolver);
}
attributeValue = values;
}
actualAttributes.put(attributeName, attributeValue);
}
return actualAttributes;
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link Annotation} attributes
*
* @param annotation specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return non-null
* @since 1.0.2
*/
public static Map<String, Object> getAttributes(Annotation annotation, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return getAttributes(annotation, propertyResolver, false, false, ignoreDefaultValue, ignoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Try to get {@link AnnotationAttributes the annotation attributes} after merging and resolving the placeholders
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Clreplaced tyoe} pf {@link Annotation annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return If the specified annotation type is not found, return <code>null</code>
* @since 1.0.3
*/
public static AnnotationAttributes tryGetMergedAnnotationAttributes(AnnotatedElement annotatedElement, Clreplaced<? extends Annotation> annotationType, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return tryGetMergedAnnotationAttributes(annotatedElement, annotationType, propertyResolver, false, false, ignoreDefaultValue, ignoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Try to get {@link AnnotationAttributes the annotation attributes} after merging and resolving the placeholders
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Clreplaced tyoe} pf {@link Annotation annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param clreplacedValuesreplacedtring whether to turn Clreplaced references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Clreplaced references
* @param nestedAnnotationsAsMap whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return If the specified annotation type is not found, return <code>null</code>
* @since 1.0.11
*/
public static AnnotationAttributes tryGetMergedAnnotationAttributes(AnnotatedElement annotatedElement, Clreplaced<? extends Annotation> annotationType, PropertyResolver propertyResolver, boolean clreplacedValuesreplacedtring, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
Annotation annotation = tryGetMergedAnnotation(annotatedElement, annotationType, clreplacedValuesreplacedtring, nestedAnnotationsAsMap);
return annotation == null ? null : getAnnotationAttributes(annotation, propertyResolver, clreplacedValuesreplacedtring, nestedAnnotationsAsMap, ignoreDefaultValue, ignoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* @param annotation specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param clreplacedValuesreplacedtring whether to turn Clreplaced references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Clreplaced references
* @param nestedAnnotationsAsMap whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return
* @since 1.0.11
*/
public static Map<String, Object> getAttributes(Annotation annotation, PropertyResolver propertyResolver, boolean clreplacedValuesreplacedtring, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
Map<String, Object> annotationAttributes = org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(annotation, clreplacedValuesreplacedtring, nestedAnnotationsAsMap);
String[] actualIgnoreAttributeNames = ignoreAttributeNames;
if (ignoreDefaultValue && !isEmpty(annotationAttributes)) {
List<String> attributeNamesToIgnore = new LinkedList<String>(asList(ignoreAttributeNames));
for (Map.Entry<String, Object> annotationAttribute : annotationAttributes.entrySet()) {
String attributeName = annotationAttribute.getKey();
Object attributeValue = annotationAttribute.getValue();
if (nullSafeEquals(attributeValue, getDefaultValue(annotation, attributeName))) {
attributeNamesToIgnore.add(attributeName);
}
}
// extends the ignored list
actualIgnoreAttributeNames = attributeNamesToIgnore.toArray(new String[attributeNamesToIgnore.size()]);
}
return getAttributes(annotationAttributes, propertyResolver, actualIgnoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link AnnotationAttributes}
*
* @param annotation specified {@link Annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return non-null
* @see #getAttributes(Annotation, PropertyResolver, boolean, String...)
* @see #getAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, String...)
* @since 1.0.3
*/
public static AnnotationAttributes getAnnotationAttributes(Annotation annotation, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return getAnnotationAttributes(annotation, propertyResolver, false, false, ignoreDefaultValue, ignoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link AnnotationAttributes}
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Clreplaced tyoe} pf {@link Annotation annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return if <code>annotatedElement</code> can't be found in <code>annotatedElement</code>, return <code>null</code>
* @since 1.0.3
*/
public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Clreplaced<? extends Annotation> annotationType, PropertyResolver propertyResolver, boolean ignoreDefaultValue, String... ignoreAttributeNames) {
return getAnnotationAttributes(annotatedElement, annotationType, propertyResolver, false, false, ignoreDefaultValue, ignoreAttributeNames);
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link AnnotationAttributes}, if the argument <code>tryMergedAnnotation</code> is <code>true</code>,
* the {@link AnnotationAttributes} will be got from
* {@link #tryGetMergedAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, String...) merged annotation} first,
* if failed, and then to get from
* {@link #getAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, boolean, String...) normal one}
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Clreplaced tyoe} pf {@link Annotation annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param clreplacedValuesreplacedtring whether to turn Clreplaced references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Clreplaced references
* @param nestedAnnotationsAsMap whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
* @param ignoreDefaultValue whether ignore default value or not
* @param tryMergedAnnotation whether try merged annotation or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return if <code>annotatedElement</code> can't be found in <code>annotatedElement</code>, return <code>null</code>
* @since 1.0.11
*/
public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Clreplaced<? extends Annotation> annotationType, PropertyResolver propertyResolver, boolean clreplacedValuesreplacedtring, boolean nestedAnnotationsAsMap, boolean ignoreDefaultValue, boolean tryMergedAnnotation, String... ignoreAttributeNames) {
AnnotationAttributes attributes = null;
if (tryMergedAnnotation) {
attributes = tryGetMergedAnnotationAttributes(annotatedElement, annotationType, propertyResolver, clreplacedValuesreplacedtring, nestedAnnotationsAsMap, ignoreDefaultValue, ignoreAttributeNames);
}
if (attributes == null) {
attributes = getAnnotationAttributes(annotatedElement, annotationType, propertyResolver, clreplacedValuesreplacedtring, nestedAnnotationsAsMap, ignoreDefaultValue, ignoreAttributeNames);
}
return attributes;
}
19
Source : AnnotationUtils.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Get the {@link AnnotationAttributes}, if the argument <code>tryMergedAnnotation</code> is <code>true</code>,
* the {@link AnnotationAttributes} will be got from
* {@link #tryGetMergedAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, String...) merged annotation} first,
* if failed, and then to get from
* {@link #getAnnotationAttributes(AnnotatedElement, Clreplaced, PropertyResolver, boolean, boolean, String...) normal one}
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Clreplaced tyoe} pf {@link Annotation annotation}
* @param propertyResolver {@link PropertyResolver} instance, e.g {@link Environment}
* @param ignoreDefaultValue whether ignore default value or not
* @param tryMergedAnnotation whether try merged annotation or not
* @param ignoreAttributeNames the attribute names of annotation should be ignored
* @return if <code>annotatedElement</code> can't be found in <code>annotatedElement</code>, return <code>null</code>
* @since 1.0.3
*/
public static AnnotationAttributes getAnnotationAttributes(AnnotatedElement annotatedElement, Clreplaced<? extends Annotation> annotationType, PropertyResolver propertyResolver, boolean ignoreDefaultValue, boolean tryMergedAnnotation, String... ignoreAttributeNames) {
return getAnnotationAttributes(annotatedElement, annotationType, propertyResolver, false, false, ignoreDefaultValue, tryMergedAnnotation, ignoreAttributeNames);
}
19
Source : DubboTransportedAttributesResolver.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* {@link DubboTransported} annotation attributes resolver.
*
* @author <a href="mailto:[email protected]">Mercy</a>
*/
public clreplaced DubboTransportedAttributesResolver {
private final PropertyResolver propertyResolver;
public DubboTransportedAttributesResolver(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}
public Map<String, Object> resolve(DubboTransported dubboTransported) {
Map<String, Object> attributes = getAnnotationAttributes(dubboTransported);
return resolve(attributes);
}
public Map<String, Object> resolve(Map<String, Object> attributes) {
Map<String, Object> resolvedAttributes = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
Object value = entry.getValue();
if (value instanceof String) {
value = propertyResolver.resolvePlaceholders(value.toString());
}
resolvedAttributes.put(entry.getKey(), value);
}
return resolvedAttributes;
}
}
18
Source : ResourceEditorRegistrar.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* PropertyEditorRegistrar implementation that populates a given
* {@link org.springframework.beans.PropertyEditorRegistry}
* (typically a {@link org.springframework.beans.BeanWrapper} used for bean
* creation within an {@link org.springframework.context.ApplicationContext})
* with resource editors. Used by
* {@link org.springframework.context.support.AbstractApplicationContext}.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.0
*/
public clreplaced ResourceEditorRegistrar implements PropertyEditorRegistrar {
private final PropertyResolver propertyResolver;
private final ResourceLoader resourceLoader;
/**
* Create a new ResourceEditorRegistrar for the given {@link ResourceLoader}
* and {@link PropertyResolver}.
* @param resourceLoader the ResourceLoader (or ResourcePatternResolver)
* to create editors for (usually an ApplicationContext)
* @param propertyResolver the PropertyResolver (usually an Environment)
* @see org.springframework.core.env.Environment
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext
*/
public ResourceEditorRegistrar(ResourceLoader resourceLoader, PropertyResolver propertyResolver) {
this.resourceLoader = resourceLoader;
this.propertyResolver = propertyResolver;
}
/**
* Populate the given {@code registry} with the following resource editors:
* ResourceEditor, InputStreamEditor, InputSourceEditor, FileEditor, URLEditor,
* URIEditor, ClreplacedEditor, ClreplacedArrayEditor.
* <p>If this registrar has been configured with a {@link ResourcePatternResolver},
* a ResourceArrayPropertyEditor will be registered as well.
* @see org.springframework.core.io.ResourceEditor
* @see org.springframework.beans.propertyeditors.InputStreamEditor
* @see org.springframework.beans.propertyeditors.InputSourceEditor
* @see org.springframework.beans.propertyeditors.FileEditor
* @see org.springframework.beans.propertyeditors.URLEditor
* @see org.springframework.beans.propertyeditors.URIEditor
* @see org.springframework.beans.propertyeditors.ClreplacedEditor
* @see org.springframework.beans.propertyeditors.ClreplacedArrayEditor
* @see org.springframework.core.io.support.ResourceArrayPropertyEditor
*/
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader, this.propertyResolver);
doRegisterEditor(registry, Resource.clreplaced, baseEditor);
doRegisterEditor(registry, ContextResource.clreplaced, baseEditor);
doRegisterEditor(registry, InputStream.clreplaced, new InputStreamEditor(baseEditor));
doRegisterEditor(registry, InputSource.clreplaced, new InputSourceEditor(baseEditor));
doRegisterEditor(registry, File.clreplaced, new FileEditor(baseEditor));
doRegisterEditor(registry, Path.clreplaced, new PathEditor(baseEditor));
doRegisterEditor(registry, Reader.clreplaced, new ReaderEditor(baseEditor));
doRegisterEditor(registry, URL.clreplaced, new URLEditor(baseEditor));
ClreplacedLoader clreplacedLoader = this.resourceLoader.getClreplacedLoader();
doRegisterEditor(registry, URI.clreplaced, new URIEditor(clreplacedLoader));
doRegisterEditor(registry, Clreplaced.clreplaced, new ClreplacedEditor(clreplacedLoader));
doRegisterEditor(registry, Clreplaced[].clreplaced, new ClreplacedArrayEditor(clreplacedLoader));
if (this.resourceLoader instanceof ResourcePatternResolver) {
doRegisterEditor(registry, Resource[].clreplaced, new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader, this.propertyResolver));
}
}
/**
* Override default editor, if possible (since that's what we really mean to do here);
* otherwise register as a custom editor.
*/
private void doRegisterEditor(PropertyEditorRegistry registry, Clreplaced<?> requiredType, PropertyEditor editor) {
if (registry instanceof PropertyEditorRegistrySupport) {
((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor);
} else {
registry.registerCustomEditor(requiredType, editor);
}
}
}
18
Source : ConfigInspectorController.java
with GNU Lesser General Public License v2.1
from Verdoso
with GNU Lesser General Public License v2.1
from Verdoso
private Map<String, List<String[]>> obtainFinalValuesAndOrigin() {
Map<String, Object> propertyMap = envEndpoint.invoke();
PropertyResolver propertyResolver = envEndpoint.getResolver();
Set<String> keys = new TreeSet<>();
List<MapSpec> propertyMaps = new ArrayList<>();
Map<String, List<String[]>> finalValues = new HashMap<>();
findPropertyKeysFromMap(propertyMap, keys, propertyMaps);
keys.stream().filter(propertyResolver::containsProperty).forEach(key -> {
String finalValue = propertyResolver.getProperty(key);
String origin = "unknown";
for (MapSpec map : propertyMaps) {
log.debug("{}, checking inside: {}", key, map.getName());
if (map.getMap().containsKey(key)) {
origin = map.getName();
break;
}
}
finalValues.putIfAbsent(origin, new ArrayList<>());
finalValues.get(origin).add(new String[] { key, finalValue });
});
return finalValues;
}
18
Source : ResourceEditorRegistrar.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* PropertyEditorRegistrar implementation that populates a given
* {@link org.springframework.beans.PropertyEditorRegistry}
* (typically a {@link org.springframework.beans.BeanWrapper} used for bean
* creation within an {@link org.springframework.context.ApplicationContext})
* with resource editors. Used by
* {@link org.springframework.context.support.AbstractApplicationContext}.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.0
*/
public clreplaced ResourceEditorRegistrar implements PropertyEditorRegistrar {
private final PropertyResolver propertyResolver;
private final ResourceLoader resourceLoader;
/**
* Create a new ResourceEditorRegistrar for the given {@link ResourceLoader}
* and {@link PropertyResolver}.
* @param resourceLoader the ResourceLoader (or ResourcePatternResolver)
* to create editors for (usually an ApplicationContext)
* @param propertyResolver the PropertyResolver (usually an Environment)
* @see org.springframework.core.env.Environment
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext
*/
public ResourceEditorRegistrar(ResourceLoader resourceLoader, PropertyResolver propertyResolver) {
this.resourceLoader = resourceLoader;
this.propertyResolver = propertyResolver;
}
/**
* Populate the given {@code registry} with the following resource editors:
* ResourceEditor, InputStreamEditor, InputSourceEditor, FileEditor, URLEditor,
* URIEditor, ClreplacedEditor, ClreplacedArrayEditor.
* <p>If this registrar has been configured with a {@link ResourcePatternResolver},
* a ResourceArrayPropertyEditor will be registered as well.
* @see org.springframework.core.io.ResourceEditor
* @see org.springframework.beans.propertyeditors.InputStreamEditor
* @see org.springframework.beans.propertyeditors.InputSourceEditor
* @see org.springframework.beans.propertyeditors.FileEditor
* @see org.springframework.beans.propertyeditors.URLEditor
* @see org.springframework.beans.propertyeditors.URIEditor
* @see org.springframework.beans.propertyeditors.ClreplacedEditor
* @see org.springframework.beans.propertyeditors.ClreplacedArrayEditor
* @see org.springframework.core.io.support.ResourceArrayPropertyEditor
*/
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
ResourceEditor baseEditor = new ResourceEditor(this.resourceLoader, this.propertyResolver);
doRegisterEditor(registry, Resource.clreplaced, baseEditor);
doRegisterEditor(registry, ContextResource.clreplaced, baseEditor);
doRegisterEditor(registry, InputStream.clreplaced, new InputStreamEditor(baseEditor));
doRegisterEditor(registry, InputSource.clreplaced, new InputSourceEditor(baseEditor));
doRegisterEditor(registry, File.clreplaced, new FileEditor(baseEditor));
doRegisterEditor(registry, Path.clreplaced, new PathEditor(baseEditor));
doRegisterEditor(registry, Reader.clreplaced, new ReaderEditor(baseEditor));
doRegisterEditor(registry, URL.clreplaced, new URLEditor(baseEditor));
ClreplacedLoader clreplacedLoader = this.resourceLoader.getClreplacedLoader();
doRegisterEditor(registry, URI.clreplaced, new URIEditor(clreplacedLoader));
doRegisterEditor(registry, Clreplaced.clreplaced, new ClreplacedEditor(clreplacedLoader));
doRegisterEditor(registry, Clreplaced[].clreplaced, new ClreplacedArrayEditor(clreplacedLoader));
if (this.resourceLoader instanceof ResourcePatternResolver) {
doRegisterEditor(registry, Resource[].clreplaced, new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader, this.propertyResolver));
}
}
/**
* Override default editor, if possible (since that's what we really mean to do here);
* otherwise register as a custom editor.
*
* @param registry 注册器
* @param requiredType 注册类型
* @param editor 属性编辑器
*/
private void doRegisterEditor(PropertyEditorRegistry registry, Clreplaced<?> requiredType, PropertyEditor editor) {
if (registry instanceof PropertyEditorRegistrySupport) {
// 属性编辑器覆盖默认的编辑器
((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor);
} else {
// 注册自定义的属性编辑器
registry.registerCustomEditor(requiredType, editor);
}
}
}
18
Source : NacosBeanUtils.java
with Apache License 2.0
from nacos-group
with Apache License 2.0
from nacos-group
/**
* Register Global Nacos Properties Bean with specified name
*
* @param attributes the attributes of Global Nacos Properties may contain
* placeholders
* @param registry {@link BeanDefinitionRegistry}
* @param propertyResolver {@link PropertyResolver}
* @param beanName Bean name
*/
public static void registerGlobalNacosProperties(AnnotationAttributes attributes, BeanDefinitionRegistry registry, PropertyResolver propertyResolver, String beanName) {
if (attributes == null) {
// Compatible with null
return;
}
AnnotationAttributes globalPropertiesAttributes = attributes.getAnnotation("globalProperties");
registerGlobalNacosProperties((Map<?, ?>) globalPropertiesAttributes, registry, propertyResolver, beanName);
}
See More Examples