Package org.linuxforhealth.fhir.config
Class PropertyGroup
- java.lang.Object
-
- org.linuxforhealth.fhir.config.PropertyGroup
-
public class PropertyGroup extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PropertyGroup.PropertyEntry
This class represents a single property contained within a PropertyGroup.
-
Field Summary
Fields Modifier and Type Field Description protected jakarta.json.JsonObject
jsonObj
static java.lang.String
PATH_ELEMENT_SEPARATOR
This constant represents the separator character used within a hierarchical property name.
-
Constructor Summary
Constructors Constructor Description PropertyGroup(jakarta.json.JsonObject jsonObj)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
convertJsonValue(jakarta.json.JsonValue jsonValue)
Converts the specified JsonValue into the appropriate java.lang.* type.java.lang.Object[]
getArrayProperty(java.lang.String propertyName)
Returns the value (as an array of Object) of the specified array property.java.lang.Boolean
getBooleanProperty(java.lang.String propertyName)
Returns the value of the specified boolean property or null if it wasn't found.java.lang.Boolean
getBooleanProperty(java.lang.String propertyName, java.lang.Boolean defaultValue)
Returns the value of the specified boolean property.java.lang.Double
getDoubleProperty(java.lang.String propertyName)
Returns the value of the specified double property or null if it wasn't found.java.lang.Double
getDoubleProperty(java.lang.String propertyName, java.lang.Double defaultValue)
Returns the value of the specified double property.java.lang.Integer
getIntProperty(java.lang.String propertyName)
Returns the value of the specified int property or null if it wasn't found.java.lang.Integer
getIntProperty(java.lang.String propertyName, java.lang.Integer defaultValue)
Returns the value of the specified int property.jakarta.json.JsonObject
getJsonObj()
jakarta.json.JsonValue
getJsonValue(java.lang.String propertyName)
Finds the specified property and returns it as a generic JsonValue.protected java.lang.String[]
getPathElements(java.lang.String propertyName)
Splits a potentially hierarchical property name into the individual path elementsjava.util.List<PropertyGroup.PropertyEntry>
getProperties()
Returns the properties contained in the PropertyGroup in the form of a list of PropertyEntry instances.PropertyGroup
getPropertyGroup(java.lang.String propertyName)
Returns a PropertyGroup associated with the specified property.protected jakarta.json.JsonObject
getPropertySubGroup(java.lang.String[] pathElements)
This function will find the JSON "sub object" rooted at "this.jsonObj" that is associated with the specified hierarchical property name.java.util.List<java.lang.String>
getStringListProperty(java.lang.String propertyName)
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.java.lang.String
getStringProperty(java.lang.String propertyName)
Returns the value of the specified String property or null if it wasn't found.java.lang.String
getStringProperty(java.lang.String propertyName, java.lang.String defaultValue)
Returns the value of the specified String property.protected void
setJsonObj(jakarta.json.JsonObject jsonObj)
java.lang.String
toString()
Returns the String representation of the PropertyGroup instance.
-
-
-
Field Detail
-
PATH_ELEMENT_SEPARATOR
public static final java.lang.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
-
-
Method Detail
-
getJsonObj
public jakarta.json.JsonObject getJsonObj()
-
setJsonObj
protected void setJsonObj(jakarta.json.JsonObject jsonObj)
-
getPropertyGroup
public PropertyGroup getPropertyGroup(java.lang.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 java.lang.String getStringProperty(java.lang.String propertyName) throws java.lang.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:
java.lang.Exception
-
getStringProperty
public java.lang.String getStringProperty(java.lang.String propertyName, java.lang.String defaultValue) throws java.lang.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:
java.lang.Exception
-
getStringListProperty
public java.util.List<java.lang.String> getStringListProperty(java.lang.String propertyName)
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
-
getIntProperty
public java.lang.Integer getIntProperty(java.lang.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 java.lang.Integer getIntProperty(java.lang.String propertyName, java.lang.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 java.lang.Double getDoubleProperty(java.lang.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 java.lang.Double getDoubleProperty(java.lang.String propertyName, java.lang.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 java.lang.Boolean getBooleanProperty(java.lang.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 java.lang.Boolean getBooleanProperty(java.lang.String propertyName, java.lang.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 java.lang.Object[] getArrayProperty(java.lang.String propertyName)
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
-
getProperties
public java.util.List<PropertyGroup.PropertyEntry> getProperties()
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. Properties with a value of null will be omitted from the list.
-
toString
public java.lang.String toString()
Returns the String representation of the PropertyGroup instance.- Overrides:
toString
in classjava.lang.Object
-
convertJsonValue
public static java.lang.Object convertJsonValue(jakarta.json.JsonValue jsonValue)
Converts the specified JsonValue into the appropriate java.lang.* type.- Parameters:
jsonValue
- the JsonValue instance to be converted- Returns:
- either null or an instance of Boolean, Integer, String, PropertyGroup, or List
-
getJsonValue
public jakarta.json.JsonValue getJsonValue(java.lang.String propertyName)
Finds the specified property and returns it as a generic JsonValue.- Parameters:
propertyName
- the possibly hierarchical property name.- Returns:
- the property value as a JsonValue or null if the property is either missing or has a null value
-
getPathElements
protected java.lang.String[] getPathElements(java.lang.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(java.lang.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.
-
-