Module org.apache.logging.log4j
Package org.apache.logging.log4j.util
Class ContextAwarePropertySource
- java.lang.Object
-
- org.apache.logging.log4j.util.ContextAwarePropertySource
-
- All Implemented Interfaces:
PropertySource
- Direct Known Subclasses:
EnvironmentPropertySource
,PropertiesPropertySource
,SystemPropertiesPropertySource
public abstract class ContextAwarePropertySource extends Object implements PropertySource
The original version of PropertySource did not support context aware PropertySources, so a call to getProperty(contextName, key) must resolve to getProperty(key). However, when a PropertySource is context aware it is desirable to have getProperty(key) resolve to getProperty(SYSTEM_CONTEXT, key).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.util.PropertySource
PropertySource.Comparator, PropertySource.Util
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,Properties>
propertiesMap
-
Fields inherited from interface org.apache.logging.log4j.util.PropertySource
DEFAULT_PRIORITY, MAPPING_FILE, PREFIX, SYSTEM_CONTEXT
-
-
Constructor Summary
Constructors Constructor Description ContextAwarePropertySource(Map<String,String> properties)
Used only for System Environment properties.ContextAwarePropertySource(Properties properties, String contextName, boolean includeInvalid)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsProperty(String key)
For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.boolean
containsProperty(String contextName, String key)
Map<String,Properties>
getPropertiesMap()
String
getProperty(String key)
For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.String
getProperty(String contextName, String key)
Collection<String>
getPropertyNames()
Returns the list of all property names for the System Context.Collection<String>
getPropertyNames(String contextName)
protected Map<String,Properties>
parseProperties(Map<String,String> properties)
Used to parse environment variables.protected Map<String,Properties>
parseProperties(Properties properties)
protected Map<String,Properties>
parseProperties(Properties properties, String contextName, boolean includeInvalid)
Used to parse properties in Properties objects.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.logging.log4j.util.PropertySource
forEach, getNormalForm, getPriority
-
-
-
-
Field Detail
-
propertiesMap
protected final Map<String,Properties> propertiesMap
-
-
Constructor Detail
-
ContextAwarePropertySource
public ContextAwarePropertySource(Properties properties, String contextName, boolean includeInvalid)
-
-
Method Detail
-
getPropertyNames
public Collection<String> getPropertyNames()
Description copied from interface:PropertySource
Returns the list of all property names for the System Context.- Specified by:
getPropertyNames
in interfacePropertySource
- Returns:
- list of property names
-
getPropertyNames
public Collection<String> getPropertyNames(String contextName)
-
getProperty
public String getProperty(String key)
Description copied from interface:PropertySource
For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.- Specified by:
getProperty
in interfacePropertySource
- Parameters:
key
- The key to search for.- Returns:
- The value or null;
-
containsProperty
public boolean containsProperty(String key)
Description copied from interface:PropertySource
For PropertySources that cannot iterate over all the potential properties this provides a direct lookup.- Specified by:
containsProperty
in interfacePropertySource
- Parameters:
key
- The key to search for.- Returns:
- The value or null;
-
getPropertiesMap
public Map<String,Properties> getPropertiesMap()
-
parseProperties
protected Map<String,Properties> parseProperties(Map<String,String> properties)
Used to parse environment variables.- Parameters:
properties
- The map of properties.- Returns:
- The Properties Map.
-
parseProperties
protected Map<String,Properties> parseProperties(Properties properties)
-
parseProperties
protected Map<String,Properties> parseProperties(Properties properties, String contextName, boolean includeInvalid)
Used to parse properties in Properties objects.- Parameters:
properties
- The input properties.contextName
- The context name.includeInvalid
- stores properties that do not match the Log4j2 convention.- Returns:
- The Properties Map.
-
-