Class PropertyGroup


  • public class PropertyGroup
    extends Object
    This class represents a collection of properties - a property group. This could be the entire set of properties resulting from loading the configuration, or it could be just a sub-structure within the overall config hierarchy, as a property group can contain other property groups. Internally, there is a JsonObject which holds the actual group of properties and this class provides a high-level API for accessing properties in a hierarchical manner.
    • Field Detail

      • PATH_ELEMENT_SEPARATOR

        public static final String PATH_ELEMENT_SEPARATOR
        This constant represents the separator character used within a hierarchical property name. Example: fhir-server/server-core/truststoreLocation
        See Also:
        Constant Field Values
      • jsonObj

        protected jakarta.json.JsonObject jsonObj
    • Constructor Detail

      • PropertyGroup

        public PropertyGroup​(jakarta.json.JsonObject jsonObj)
    • Method Detail

      • getJsonObj

        public jakarta.json.JsonObject getJsonObj()
      • setJsonObj

        protected void setJsonObj​(jakarta.json.JsonObject jsonObj)
      • getPropertyGroup

        public PropertyGroup getPropertyGroup​(String propertyName)
        Returns a PropertyGroup associated with the specified property.
        Parameters:
        propertyName - a hierarchical property name (e.g. "level1/level2/level3") that refers to a property group.
        Returns:
        a PropertyGroup that holds the sub-structure associated with the specified property.
      • getStringProperty

        public String getStringProperty​(String propertyName)
                                 throws Exception
        Returns the value of the specified String property or null if it wasn't found. If the value is encoded, then it will be decoded.
        Parameters:
        propertyName - the name of the property to retrieved
        Throws:
        Exception
      • getStringProperty

        public String getStringProperty​(String propertyName,
                                        String defaultValue)
                                 throws Exception
        Returns the value of the specified String property. If not found, then 'defaultValue' is returned instead. If the value is encoded, then it will be decoded.
        Parameters:
        propertyName - the name of the property to retrieve
        Throws:
        Exception
      • getStringListProperty

        public List<String> getStringListProperty​(String propertyName)
                                           throws Exception
        This is a convenience function that will retrieve an array property, then convert it to a list of Strings by calling toString() on each array element.
        Parameters:
        propertyName - the name of the property to retrieve
        Returns:
        a List containing the elements from the JSON array property; possibly null
        Throws:
        Exception
      • getIntProperty

        public Integer getIntProperty​(String propertyName)
        Returns the value of the specified int property or null if it wasn't found.
        Parameters:
        propertyName - the name of the property to retrieve
      • getIntProperty

        public Integer getIntProperty​(String propertyName,
                                      Integer defaultValue)
        Returns the value of the specified int property. If not found, then 'defaultValue' is returned instead.
        Parameters:
        propertyName - the name of the property to retrieve
      • getDoubleProperty

        public Double getDoubleProperty​(String propertyName)
        Returns the value of the specified double property or null if it wasn't found.
        Parameters:
        propertyName - the name of the property to retrieve
      • getDoubleProperty

        public Double getDoubleProperty​(String propertyName,
                                        Double defaultValue)
        Returns the value of the specified double property. If not found, then 'defaultValue' is returned instead.
        Parameters:
        propertyName - the name of the property to retrieve
      • getBooleanProperty

        public Boolean getBooleanProperty​(String propertyName)
        Returns the value of the specified boolean property or null if it wasn't found.
        Parameters:
        propertyName - the name of the property to retrieve
      • getBooleanProperty

        public Boolean getBooleanProperty​(String propertyName,
                                          Boolean defaultValue)
        Returns the value of the specified boolean property. If not found, then 'defaultValue' is returned instead.
        Parameters:
        propertyName - the name of the property to retrieve
      • getArrayProperty

        public Object[] getArrayProperty​(String propertyName)
                                  throws Exception
        Returns the value (as an array of Object) of the specified array property. Each element of the returned array will be an instance of Boolean, Integer, Double, String or PropertyGroup, depending on the value type associated with the property within the underlying JsonObject.
        Parameters:
        propertyName - the name of the property to retrieve
        Returns:
        an array of values from the specified array property or null if the property doesn't exist
        Throws:
        Exception
      • getProperties

        public List<PropertyGroup.PropertyEntry> getProperties()
                                                        throws Exception
        Returns the properties contained in the PropertyGroup in the form of a list of PropertyEntry instances. If no properties exist, then an empty list will be returned.
        Throws:
        Exception
      • toString

        public String toString()
        Returns the String representation of the PropertyGroup instance.
        Overrides:
        toString in class Object
      • convertJsonValue

        public static Object convertJsonValue​(jakarta.json.JsonValue jsonValue)
                                       throws Exception
        Converts the specified JsonValue into the appropriate java.lang.* type.
        Parameters:
        jsonValue - the JsonValue instance to be converted
        Returns:
        an instance of Boolean, Integer, String, PropertyGroup, or List
        Throws:
        Exception
        • getJsonValue

          public jakarta.json.JsonValue getJsonValue​(String propertyName)
          Finds the specified property and returns it as a generic JsonValue.
          Parameters:
          propertyName - the possibly hierarchical property name.
        • getPathElements

          protected String[] getPathElements​(String propertyName)
          Splits a potentially hierarchical property name into the individual path elements
          Parameters:
          propertyName - a hierarchical property name (e.g. "level1/level2/myProperty"
          Returns:
        • getPropertySubGroup

          protected jakarta.json.JsonObject getPropertySubGroup​(String[] pathElements)
          This function will find the JSON "sub object" rooted at "this.jsonObj" that is associated with the specified hierarchical property name.

          For example, consider the following JSON structure:

           {
               "level1":{
                   "level2":{
                       "myProperty":"myValue"
                   }
               }
           }
           
          If this function was invoked with a property name of "level1/level2/myProperty", then the result will be the JsonObject associated with the "level2" field within the JSON structure above.
          Parameters:
          pathElements - an array of path elements that make up the hierarchical property name (e.g. {"level1", "level2", "myProperty"})
          Returns:
          the JsonObject sub-structure that contains the specified property.