Package org.apache.sling.testing.mock.osgi.config

# Class ConfigTypeContext

java.lang.Object
org.apache.sling.testing.mock.osgi.config.ConfigTypeContext

public final class ConfigTypeContext extends Object
Performs configuration management and component property type construction for `ConfigType` and `SetConfig` annotations.

## Constructor Summary

Constructors
Constructor
Description
`ConfigTypeContext(OsgiContextImpl osgiContext)`

## Method Summary

Modifier and Type
Method
Description
`Object`
`constructConfigType(@NotNull ConfigType annotation)`
Return a concrete instance of the OSGi config / Component Property Type represented by the given `ConfigType` annotation discovered via reflection.
`Object`
`constructConfigType(@NotNull ConfigType annotation, @Nullable String applyPid)`
Return a concrete instance of the OSGi config / Component Property Type represented by the given `ConfigType` annotation discovered via reflection.
`Optional<String>`
`getConfigurationPid(@NotNull String pid, @NotNull Class component)`
Construct a configuration pid for use with `ConfigurationAdmin.getConfiguration(String)`.
`TypedConfig`
`newTypedConfig(@NotNull Annotation annotation)`
Construct a collection typed config for the provided annotation.
`TypedConfig`
`newTypedConfig(@NotNull Annotation annotation, @Nullable String applyPid)`
Construct a collection typed config for the provided annotation.
`void`
`updateConfiguration(@NotNull String pid, @NotNull Map<String,Object> propertyMap)`
Updates a `Configuration` from the provided pid and property map.
`void`
`updateConfiguration(@NotNull SetConfig annotation)`
Updates a `Configuration` from the provided annotation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ConfigTypeContext

public ConfigTypeContext(OsgiContextImpl osgiContext)

## Method Details

### getConfigurationPid

public Optional<String> getConfigurationPid(@NotNull @NotNull String pid, @NotNull @NotNull Class component)
Construct a configuration pid for use with `ConfigurationAdmin.getConfiguration(String)`. If `pid` is not empty and not equal to `Component.NAME` ("$"), return `pid`. Otherwise, return `component.getName()`, except in the case of `Void`, in which case return `empty()`.

Parameters:
  `pid` - an explicit pid name, "$", or the empty string
  `component` - a class whose name to use when pid is "$", unless `Void`
Returns:
  a useful configuration pid or none

### updateConfiguration

public void updateConfiguration(@NotNull @NotNull SetConfig annotation)
Updates a `Configuration` from the provided annotation.

Parameters:
  `annotation` - an `SetConfig` annotation

### updateConfiguration

public void updateConfiguration(@NotNull @NotNull String pid, @NotNull @NotNull Map<String,Object> propertyMap)
Updates a `Configuration` from the provided pid and property map.

Parameters:
  `pid` - the configuration pid
  `propertyMap` - config properties to set on the configuration

### constructConfigType

public Object constructConfigType(@NotNull @NotNull ConfigType annotation)
Return a concrete instance of the OSGi config / Component Property Type represented by the given `ConfigType` annotation discovered via reflection.

Parameters:
  `annotation` - the `ConfigType`
Returns:
  a concrete instance of the type specified by the provided `ConfigType.type()`

### constructConfigType

public Object constructConfigType(@NotNull @NotNull ConfigType annotation, @Nullable @Nullable String applyPid)
Return a concrete instance of the OSGi config / Component Property Type represented by the given `ConfigType` annotation discovered via reflection.

Parameters:
  `annotation` - the `ConfigType`
  `applyPid` - if not empty, override any specified `ConfigType.pid()`.
Returns:
  a concrete instance of the type specified by the provided `ConfigType.type()`

### newTypedConfig

public TypedConfig newTypedConfig(@NotNull @NotNull Annotation annotation)
Construct a collection typed config for the provided annotation.

Parameters:
  `annotation` - a component property type annotation or `ConfigType` annotation
Returns:
  a typed config

### newTypedConfig

public TypedConfig newTypedConfig(@NotNull @NotNull Annotation annotation, @Nullable @Nullable String applyPid)
Construct a collection typed config for the provided annotation.

Parameters:
  `annotation` - a component property type annotation or `ConfigType` annotation
  `applyPid` - optional non-empty configuration pid to apply if annotation is a `ConfigType`
Returns:
  a typed config