Class AttributeableEntity
- java.lang.Object
-
- org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
-
- Direct Known Subclasses:
ArtifactRules
,ConfigurationApi
,DescribableEntity
,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 void
clear()
Clear the object and reset to defaultsprotected javax.json.JsonObjectBuilder
createJson()
Convert this object into JSONvoid
fromJSONObject(javax.json.JsonObject jsonObj)
Extract the metadata from the JSON object.Map<String,javax.json.JsonValue>
getAttributes()
Get the attributesprotected boolean
getBoolean(String attributeName, boolean defaultValue)
Helper method to get a boolean value from an attributeprotected int
getInteger(String attributeName, int defaultValue)
Helper method to get a integer value from an attributeprotected Number
getNumber(String attributeName)
Helper method to get a number value from an attributeprotected String
getString(String attributeName)
Helper method to get a string value from an attributeprotected String
getString(javax.json.JsonValue jsonValue)
Helper method to get a string value from a JsonValueprotected String[]
getStringArray(String attributeName)
Helper method to get a string array from an attributeprotected void
setDefaults()
Apply the non-null default values.protected void
setString(javax.json.JsonObjectBuilder builder, String attributeName, String value)
Helper method to set a string valueprotected void
setStringArray(javax.json.JsonObjectBuilder builder, String attributeName, String[] value)
Helper method to set a string arrayjavax.json.JsonObject
toJSONObject()
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 javax.json.JsonObject toJSONObject() throws IOException
Convert this object into JSON- Returns:
- The json object
- Throws:
IOException
- If generating the JSON fails
-
fromJSONObject
public void fromJSONObject(javax.json.JsonObject jsonObj) throws IOException
Extract 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,javax.json.JsonValue> getAttributes()
Get the attributes- Returns:
- Mutable map of attributes, by attribute name
-
createJson
protected javax.json.JsonObjectBuilder createJson() throws IOException
Convert this object into JSON- Returns:
- The json object builder
- Throws:
IOException
- If generating the JSON fails
-
getString
protected String getString(javax.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(javax.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(javax.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
-
-