Package io.microsphere.spring.config
Class ConfigurationPropertyRepository
- java.lang.Object
-
- io.microsphere.spring.config.ConfigurationPropertyRepository
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.EnvironmentAware
public class ConfigurationPropertyRepository extends java.lang.Object implements org.springframework.context.EnvironmentAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBeanA repository for managingConfigurationPropertyinstances with support for configuration via Spring'sEnvironment.This class provides methods to add, remove, retrieve, and manage configuration properties. It also allows integration with Spring's lifecycle management through the
InitializingBeanandDisposableBeaninterfaces, as well as environment-based property configuration through theEnvironmentAwareinterface.Configuration Properties
- "microsphere.spring.config-property-repository.max-size": Sets the maximum number of properties that can be stored in the repository. Defaults to "99999" if not specified.
Example Usage
// Create a new repository instance ConfigurationPropertyRepository repository = new ConfigurationPropertyRepository(); // Set the environment to load max size from configuration ConfigurableEnvironment environment = new StandardEnvironment(); repository.setEnvironment(environment); // Initialize the repository (usually done automatically by Spring) repository.afterPropertiesSet(); // Add a configuration property ConfigurationProperty property = new ConfigurationProperty("my.property.name"); property.setValue("exampleValue"); repository.add(property); // Retrieve the property ConfigurationProperty retrieved = repository.get("my.property.name"); System.out.println(retrieved.getValue()); // Output: exampleValue // Clean up resources when done repository.destroy();- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
ConfigurationProperty
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBEAN_NAMEstatic intDEFAULT_MAX_SIZE_PROPERTY_VALUEThe default max size ofConfigurationPropertyRepositorystatic java.lang.StringMAX_SIZE_PROPERTY_NAMEThe max size ofConfigurationPropertyRepositorystatic java.lang.StringPROPERTY_NAME_PREFIX
-
Constructor Summary
Constructors Constructor Description ConfigurationPropertyRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(io.microsphere.beans.ConfigurationProperty configurationProperty)Add aConfigurationPropertyinstancevoidafterPropertiesSet()booleancontains(java.lang.String name)Determine whether the repository contains the specified nameio.microsphere.beans.ConfigurationPropertycreateIfAbsent(java.lang.String name)Create aConfigurationPropertyinstance if absentvoiddestroy()clear the repositoryio.microsphere.beans.ConfigurationPropertyget(java.lang.String name)Get aConfigurationPropertyinstance by namejava.util.Collection<io.microsphere.beans.ConfigurationProperty>getAll()Get allConfigurationPropertyinstancesintgetMaxSize()Get the max size of the repositoryprotected java.util.Map<java.lang.String,io.microsphere.beans.ConfigurationProperty>getRepository()io.microsphere.beans.ConfigurationPropertyremove(java.lang.String name)Remove aConfigurationPropertyinstance by namevoidsetEnvironment(org.springframework.core.env.Environment environment)
-
-
-
Field Detail
-
BEAN_NAME
public static final java.lang.String BEAN_NAME
- See Also:
- Constant Field Values
-
PROPERTY_NAME_PREFIX
public static final java.lang.String PROPERTY_NAME_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_MAX_SIZE_PROPERTY_VALUE
public static final int DEFAULT_MAX_SIZE_PROPERTY_VALUE
The default max size ofConfigurationPropertyRepository
-
MAX_SIZE_PROPERTY_NAME
@ConfigurationProperty(type=int.class, description="The max size of the repository for ConfigurationProperty instances", defaultValue="99999") public static final java.lang.String MAX_SIZE_PROPERTY_NAMEThe max size ofConfigurationPropertyRepository- See Also:
- Constant Field Values
-
-
Method Detail
-
add
public void add(io.microsphere.beans.ConfigurationProperty configurationProperty)
Add aConfigurationPropertyinstance- Parameters:
configurationProperty- aConfigurationPropertyinstance
-
remove
public io.microsphere.beans.ConfigurationProperty remove(java.lang.String name)
Remove aConfigurationPropertyinstance by name- Parameters:
name-the name of ConfigurationProperty
-
get
public io.microsphere.beans.ConfigurationProperty get(java.lang.String name)
Get aConfigurationPropertyinstance by name- Parameters:
name-the name of ConfigurationProperty- Returns:
nullif not found
-
contains
public boolean contains(java.lang.String name)
Determine whether the repository contains the specified name- Parameters:
name-the name of ConfigurationProperty- Returns:
trueif contains, otherwisefalse
-
createIfAbsent
public io.microsphere.beans.ConfigurationProperty createIfAbsent(java.lang.String name)
Create aConfigurationPropertyinstance if absent- Parameters:
name-the name of ConfigurationProperty- Returns:
- the
ConfigurationPropertyinstance
-
getAll
public java.util.Collection<io.microsphere.beans.ConfigurationProperty> getAll()
Get allConfigurationPropertyinstances- Returns:
- never
null
-
getMaxSize
public int getMaxSize()
Get the max size of the repository- Returns:
- max size
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment)
- Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
public void destroy() throws java.lang.Exceptionclear the repository- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
java.lang.Exception
-
getRepository
protected java.util.Map<java.lang.String,io.microsphere.beans.ConfigurationProperty> getRepository()
-
-