Class AttributeableEntity
java.lang.Object
org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
- Direct Known Subclasses:
ArtifactRules,ConfigurableEntityAddition,ConfigurationApi,DescribableEntity,PropertyDescriptionAddition,Range,VersionRule
Abstract class used by all entities which allow additional attributes to be stored.
This class is not thread safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the object and reset to defaultsprotected jakarta.json.JsonObjectBuilderConvert this object into JSONvoidfromJSONObject(jakarta.json.JsonObject jsonObj) Extract the metadata from the JSON object.Get the attributesprotected booleangetBoolean(String attributeName, boolean defaultValue) Helper method to get a boolean value from an attributeprotected intgetInteger(String attributeName, int defaultValue) Helper method to get a integer value from an attributeprotected NumberHelper method to get a number value from an attributeprotected StringgetString(jakarta.json.JsonValue jsonValue) Helper method to get a string value from a JsonValueprotected StringHelper method to get a string value from an attributeprotected String[]getStringArray(String attributeName) Helper method to get a string array from an attributeprotected voidApply the non-null default values.protected voidHelper method to set a string valueprotected voidsetStringArray(jakarta.json.JsonObjectBuilder builder, String attributeName, String[] value) Helper method to set a string arrayjakarta.json.JsonObjectConvert this object into JSON
-
Constructor Details
-
AttributeableEntity
public AttributeableEntity()
-
-
Method Details
-
setDefaults
protected void setDefaults()Apply the non-null default values. -
clear
public void clear()Clear the object and reset to defaults -
toJSONObject
Convert this object into JSON- Returns:
- The json object
- Throws:
IOException- If generating the JSON fails
-
fromJSONObject
Extract the metadata from the JSON object. This method first callsclear()- Parameters:
jsonObj- The JSON Object- Throws:
IOException- If JSON parsing fails
-
getAttributes
Get the attributes- Returns:
- Mutable map of attributes, by attribute name
-
createJson
Convert this object into JSON- Returns:
- The json object builder
- Throws:
IOException- If generating the JSON fails
-
getString
Helper method to get a string value from a JsonValue- Parameters:
jsonValue- The json value- Returns:
- The string value or
null.
-
getString
Helper method to get a string value from an attribute- Parameters:
attributeName- The attribute name- Returns:
- The string value or
null.
-
getStringArray
Helper method to get a string array from an attribute- Parameters:
attributeName- The attribute name- Returns:
- The string array or
null. - Throws:
IOException- Since:
- 1.6.0
-
getNumber
Helper method to get a number value from an attribute- Parameters:
attributeName- The attribute name- Returns:
- The string value or
null. - Throws:
IOException- If the attribute value is not of type boolean
-
setString
protected void setString(jakarta.json.JsonObjectBuilder builder, String attributeName, String value) Helper method to set a string value- Parameters:
builder- The json object builderattributeName- The name of the attributevalue- The string value
-
setStringArray
protected void setStringArray(jakarta.json.JsonObjectBuilder builder, String attributeName, String[] value) Helper method to set a string array- Parameters:
builder- The json object builderattributeName- The name of the attributevalue- The string array- Since:
- 1.6.0
-
getInteger
Helper method to get a integer value from an attribute- Parameters:
attributeName- The attribute namedefaultValue- default value- Returns:
- The integer value or the default value
-
getBoolean
Helper method to get a boolean value from an attribute- Parameters:
attributeName- The attribute namedefaultValue- default value- Returns:
- The boolean value or the default value
- Throws:
IOException- If the attribute value is not of type boolean
-