public class MetatypeUtils
extends java.lang.Object
The presence of the Metatype service will cause ConfigAdmin to use real types (in addition to String) as values in the the configuration properties provided to declarative services components.
This class provides utility methods for retrieving a desired type (a boolean, a long, an array of strings.. ) from a component's configuration properties. They handle objects of either type (those already created/populated as the right type, or values that are still encoded as strings).
Constructor and Description |
---|
MetatypeUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Long |
evaluateDuration(java.lang.String strVal,
java.util.concurrent.TimeUnit endUnit)
Converts a string value representing a unit of time into a Long value.
|
static java.lang.String |
evaluateToken(java.lang.String strVal)
Converts a String value into a token value by collapsing whitespace.
|
static boolean |
parseBoolean(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
boolean defaultValue)
Parse a boolean from the provided config value: checks for whether or not
the object read from the Service/Component configuration is a String
or a Metatype converted boolean.
|
static long |
parseDuration(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
long defaultValue)
Parse a duration from the provided config value: checks for whether or not
the object read from the Service/Component configuration is a String
or a Metatype converted long duration value
|
static long |
parseDuration(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
long defaultValue,
java.util.concurrent.TimeUnit units)
Parse a duration from the provided config value: checks for whether or not
the object read from the Service/Component configuration is a String
or a Metatype converted long duration value
|
static int |
parseInteger(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
int defaultValue)
Parse a int from the provided config value: checks for whether or not
the object read from the Service/Component configuration is a String
or a Metatype converted int
|
static int[] |
parseIntegerArray(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
int[] defaultValue)
Parse a string array from the provided config value: returns
an array of strings generated from either a comma-separated single
string value, or a metatype generated string array.
|
static long |
parseLong(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
long defaultValue)
Parse a long from the provided config value: checks for whether or not
the object read from the Service/Component configuration is a String
or a Metatype converted long
|
static java.lang.String[] |
parseStringArray(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
java.lang.String[] defaultValue)
Parse a string array from the provided config value: returns
an array of strings generated from either a comma-separated single
string value, or a metatype generated string array.
|
static java.util.Collection<java.lang.String> |
parseStringCollection(java.lang.Object configAlias,
java.lang.String propertyKey,
java.lang.Object obj,
java.util.Collection<java.lang.String> defaultValue)
Parse a string collection from the provided config value: returns
a collection of strings generated from either a comma-separated single
string value, or a metatype provided string collection.
|
public static boolean parseBoolean(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, boolean defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.java.lang.IllegalArgumentException
- If value is not a String/Boolean, or if the String
boolean is not "true" or "false" (ignoring case)public static java.lang.String[] parseStringArray(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, java.lang.String[] defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a String or String array, or if an error
occurs while converting/casting the object to the return parameter type.public static java.util.Collection<java.lang.String> parseStringCollection(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, java.util.Collection<java.lang.String> defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a String, String collection, or String array, or if an error
occurs while converting/casting the object to the return parameter type.public static long parseLong(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, long defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a String/Short/Integer/Long, or if an error
occurs while converting/casting the object to the return parameter type.public static int parseInteger(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, int defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a String/Short/Integer/Long, or if an error
occurs while converting/casting the object to the return parameter type.public static int[] parseIntegerArray(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, int[] defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a String or String array, or if an error
occurs while converting/casting the object to the return parameter type.public static long parseDuration(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, long defaultValue)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.java.lang.IllegalArgumentException
- If value is not a Long, or if an error
occurs while converting/casting the object to the return parameter type.public static long parseDuration(java.lang.Object configAlias, java.lang.String propertyKey, java.lang.Object obj, long defaultValue, java.util.concurrent.TimeUnit units)
If an exception occurs converting the object parameter: A translated warning message will be issued using the provided propertyKey and object as parameters. FFDC for the exception is suppressed: Callers should handle the thrown IllegalArgumentException as appropriate.
configAlias
- Name of config (pid or alias) associated with a registered service
or DS component.propertyKey
- The key used to retrieve the property value from the map.
Used in the warning message if the value is badly formed.obj
- The object retrieved from the configuration property map/dictionary.defaultValue
- The default value that should be applied if the object is null.units
- The unit of time for the duration value. This is only used when
converting from a String value.java.lang.IllegalArgumentException
- If value is not a String/Short/Integer/Long, or if an error
occurs while converting/casting the object to the return parameter type.public static java.lang.Long evaluateDuration(java.lang.String strVal, java.util.concurrent.TimeUnit endUnit)
strVal
- A String representing a unit of time.unit
- The unit of time that the string value should be converted intopublic static java.lang.String evaluateToken(java.lang.String strVal)
strVal
- A String to be trimmed