com.ibm.wsspi.kernel.service.utils

Class MetatypeUtils

  1. java.lang.Object
  2. extended bycom.ibm.wsspi.kernel.service.utils.MetatypeUtils

  1. public class MetatypeUtils
  2. extends java.lang.Object
Utility class to simplify retrieving values from injected config.

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 Summary

Constructor and Description
MetatypeUtils()

Method Summary

Modifier and Type Method and Description
  1. static
  2. 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.
  1. static
  2. 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.
  1. static
  2. 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
  1. static
  2. 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
  1. static
  2. 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
  1. static
  2. 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.
  1. static
  2. 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
  1. static
  2. 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.
  1. static
  2. 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.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

MetatypeUtils

  1. public MetatypeUtils()

Method Detail

parseBoolean

  1. public static boolean parseBoolean( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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.

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.

Parameters:
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.
Returns:
boolean parsed from obj, the default value if obj is null.
Throws:
java.lang.IllegalArgumentException - If value is not a String/Boolean, or if the String boolean is not "true" or "false" (ignoring case)

parseStringArray

  1. public static java.lang.String[] parseStringArray( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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.

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.

Parameters:
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.
Returns:
An array of strings parsed from the obj parameter, or default value if obj is null
Throws:
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.

parseStringCollection

  1. public static java.util.Collection<java.lang.String> parseStringCollection( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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.

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.

Parameters:
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.
Returns:
Collection of strings parsed/retrieved from obj, or default value if obj is null
Throws:
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.

parseLong

  1. public static long parseLong(java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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

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.

Parameters:
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.
Returns:
Long parsed/retrieved from obj, or default value if obj is null
Throws:
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.

parseInteger

  1. public static int parseInteger( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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

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.

Parameters:
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.
Returns:
Integer parsed/retrieved from obj, or default value if obj is null
Throws:
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.

parseIntegerArray

  1. public static int[] parseIntegerArray( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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.

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.

Parameters:
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.
Returns:
An array of strings parsed from the obj parameter, or default value if obj is null
Throws:
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.

parseDuration

  1. public static long parseDuration( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. 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

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.

Parameters:
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.
Returns:
Long parsed/retrieved from obj, or default value if obj is null
Throws:
java.lang.IllegalArgumentException - If value is not a Long, or if an error occurs while converting/casting the object to the return parameter type.

parseDuration

  1. public static long parseDuration( java.lang.Object configAlias,
  2. java.lang.String propertyKey,
  3. java.lang.Object obj,
  4. long defaultValue,
  5. 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

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.

Parameters:
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.
Returns:
Long parsed/retrieved from obj, or default value if obj is null
Throws:
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.

evaluateDuration

  1. public static java.lang.Long evaluateDuration( java.lang.String strVal,
  2. java.util.concurrent.TimeUnit endUnit)
Converts a string value representing a unit of time into a Long value.
Parameters:
strVal - A String representing a unit of time.
Returns:
Long The value of the string in the desired time unit