Class AttributeableEntity
- java.lang.Object
-
- org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
-
- Direct Known Subclasses:
ArtifactRules,ConfigurableEntityAddition,ConfigurationApi,DescribableEntity,PropertyDescriptionAddition,Range,VersionRule
public abstract class AttributeableEntity extends Object
Abstract class used by all entities which allow additional attributes to be stored. This class is not thread safe.
-
-
Constructor Summary
Constructors Constructor Description AttributeableEntity()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the object and reset to defaultsprotected jakarta.json.JsonObjectBuildercreateJson()Convert this object into JSONvoidfromJSONObject(jakarta.json.JsonObject jsonObj)Extract the metadata from the JSON object.Map<String,jakarta.json.JsonValue>getAttributes()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 NumbergetNumber(String attributeName)Helper method to get a number value from an attributeprotected StringgetString(jakarta.json.JsonValue jsonValue)Helper method to get a string value from a JsonValueprotected StringgetString(String attributeName)Helper method to get a string value from an attributeprotected String[]getStringArray(String attributeName)Helper method to get a string array from an attributeprotected voidsetDefaults()Apply the non-null default values.protected voidsetString(jakarta.json.JsonObjectBuilder builder, String attributeName, String value)Helper method to set a string valueprotected voidsetStringArray(jakarta.json.JsonObjectBuilder builder, String attributeName, String[] value)Helper method to set a string arrayjakarta.json.JsonObjecttoJSONObject()Convert this object into JSON
-
-
-
Method Detail
-
setDefaults
protected void setDefaults()
Apply the non-null default values.
-
clear
public void clear()
Clear the object and reset to defaults
-
toJSONObject
public jakarta.json.JsonObject toJSONObject() throws IOExceptionConvert this object into JSON- Returns:
- The json object
- Throws:
IOException- If generating the JSON fails
-
fromJSONObject
public void fromJSONObject(jakarta.json.JsonObject jsonObj) throws IOExceptionExtract the metadata from the JSON object. This method first callsclear()- Parameters:
jsonObj- The JSON Object- Throws:
IOException- If JSON parsing fails
-
getAttributes
public Map<String,jakarta.json.JsonValue> getAttributes()
Get the attributes- Returns:
- Mutable map of attributes, by attribute name
-
createJson
protected jakarta.json.JsonObjectBuilder createJson() throws IOExceptionConvert this object into JSON- Returns:
- The json object builder
- Throws:
IOException- If generating the JSON fails
-
getString
protected String getString(jakarta.json.JsonValue jsonValue)
Helper method to get a string value from a JsonValue- Parameters:
jsonValue- The json value- Returns:
- The string value or
null.
-
getString
protected String getString(String attributeName)
Helper method to get a string value from an attribute- Parameters:
attributeName- The attribute name- Returns:
- The string value or
null.
-
getStringArray
protected String[] getStringArray(String attributeName) throws IOException
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
protected Number getNumber(String attributeName) throws IOException
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
protected int getInteger(String attributeName, int defaultValue)
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
protected boolean getBoolean(String attributeName, boolean defaultValue) throws IOException
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
-
-