Class PropertyValueParser

  • Direct Known Subclasses:
    CredentialConfigParser

    public class PropertyValueParser
    extends Object
    Parses the configuration data associated with classes that contain setter properties. The format of the property string should be like:
       MyClass{{propertyOne=foo}{propertyTwo=bar}}
     

    If the class name is supplied to the constructor, the property string need not contain the class declaration.

    • Field Detail

      • CONFIG_PATTERN

        protected static final Pattern CONFIG_PATTERN
        Property string containing configuration.
      • PARAMS_ONLY_CONFIG_PATTERN

        protected static final Pattern PARAMS_ONLY_CONFIG_PATTERN
        Property string for configuring a config where the class is known.
      • PROPERTY_PATTERN

        protected static final Pattern PROPERTY_PATTERN
        Pattern for finding properties.
      • logger

        protected final Logger logger
        Logger for this class.
      • className

        private String className
        Class found in the config.
      • properties

        private final Map<String,​String> properties
        Properties found in the config to set on the class.
    • Constructor Detail

      • PropertyValueParser

        protected PropertyValueParser()
        Default constructor.
      • PropertyValueParser

        public PropertyValueParser​(String config)
        Creates a new config parser.
        Parameters:
        config - containing configuration data
      • PropertyValueParser

        public PropertyValueParser​(String config,
                                   String clazz)
        Creates a new config parser.
        Parameters:
        config - containing configuration data
        clazz - fully qualified class name
    • Method Detail

      • initializeProperties

        protected void initializeProperties​(Matcher matcher)
        Finds all the matches in the supplied matcher puts them into the properties map. Properties are split on '='.
        Parameters:
        matcher - to find matches
      • getClassName

        public String getClassName()
        Returns the class name of the object to initialize.
        Returns:
        class name
      • setClassName

        protected void setClassName​(String name)
        Sets the class name of the object to initialize.
        Parameters:
        name - of the object class type
      • getProperties

        public Map<String,​String> getProperties()
        Returns the properties from the configuration.
        Returns:
        map of property name to value
      • isConfig

        public static boolean isConfig​(String config)
        Returns whether the supplied configuration data contains a config.
        Parameters:
        config - containing configuration data
        Returns:
        whether the supplied configuration data contains a config
      • isParamsOnlyConfig

        public static boolean isParamsOnlyConfig​(String config)
        Returns whether the supplied configuration data contains a params only config.
        Parameters:
        config - containing configuration data
        Returns:
        whether the supplied configuration data contains a params only config
      • initializeType

        public Object initializeType()
        Initialize an instance of the class type with the properties contained in this config.
        Returns:
        object of the type the config parsed
      • setProperties

        protected void setProperties​(Class<?> c,
                                     Object o)
        Sets the properties on the supplied object.
        Parameters:
        c - type of the supplied object
        o - to invoke properties on