Class PropertyHelper


  • public class PropertyHelper
    extends java.lang.Object
    Author:
    Daniel Meyer
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertyHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void applyProperties​(java.lang.Object configuration, java.util.Map<java.lang.String,​java.lang.String> properties)
      Sets an objects fields via reflection from String values.
      static void applyProperties​(java.lang.Object configuration, java.util.Map<java.lang.String,​java.lang.String> properties, java.lang.String namingStrategy)
      Sets an objects fields via reflection from String values.
      static void applyProperty​(java.lang.Object configuration, java.lang.String key, java.lang.String stringValue)  
      protected static java.lang.String convertToCamelCase​(java.lang.String value, java.lang.String token)  
      static java.lang.Object convertToClass​(java.lang.String value, java.lang.Class<?> clazz)
      Converts a value to the type of the given field.
      static boolean getBooleanProperty​(java.util.Map<java.lang.String,​java.lang.String> properties, java.lang.String name, boolean defaultValue)  
      static java.lang.String resolveProperty​(java.util.Properties props, java.lang.String original)
      Replaces Ant-style property references if the corresponding keys exist in the provided Properties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PropertyHelper

        public PropertyHelper()
    • Method Detail

      • getBooleanProperty

        public static boolean getBooleanProperty​(java.util.Map<java.lang.String,​java.lang.String> properties,
                                                 java.lang.String name,
                                                 boolean defaultValue)
      • convertToClass

        public static java.lang.Object convertToClass​(java.lang.String value,
                                                      java.lang.Class<?> clazz)
        Converts a value to the type of the given field.
        Parameters:
        value -
        field -
        Returns:
      • applyProperty

        public static void applyProperty​(java.lang.Object configuration,
                                         java.lang.String key,
                                         java.lang.String stringValue)
      • applyProperties

        public static void applyProperties​(java.lang.Object configuration,
                                           java.util.Map<java.lang.String,​java.lang.String> properties,
                                           java.lang.String namingStrategy)
        Sets an objects fields via reflection from String values. Depending on the field's type the respective values are converted to int or boolean. This method allows to specify a property naming strategy, i.e., if a property is written in camelCase, kebab-case, or snake_case.
        Parameters:
        configuration -
        properties -
        namingStrategy - can be either KEBAB_CASE, SNAKE_CASE, or CAMEL_CASE.
        Throws:
        ProcessEngineException - if a property is supplied that matches no field or if the field's type is not String, nor int, nor boolean.
      • applyProperties

        public static void applyProperties​(java.lang.Object configuration,
                                           java.util.Map<java.lang.String,​java.lang.String> properties)
        Sets an objects fields via reflection from String values. Depending on the field's type the respective values are converted to int or boolean.
        Parameters:
        configuration -
        properties -
        Throws:
        ProcessEngineException - if a property is supplied that matches no field or if the field's type is not String, nor int, nor boolean.
      • resolveProperty

        public static java.lang.String resolveProperty​(java.util.Properties props,
                                                       java.lang.String original)
        Replaces Ant-style property references if the corresponding keys exist in the provided Properties.
        Parameters:
        props - contains possible replacements
        original - may contain Ant-style templates
        Returns:
        the original string with replaced properties or the unchanged original string if no placeholder found.
      • convertToCamelCase

        protected static java.lang.String convertToCamelCase​(java.lang.String value,
                                                             java.lang.String token)