Class ArtifactRules
- java.lang.Object
-
- org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
-
- org.apache.sling.feature.extension.apiregions.api.artifacts.ArtifactRules
-
public class ArtifactRules extends AttributeableEntity
Artifact rules define additional rules for artifacts in a feature model. The rules are stored as an extension in the feature model. This class is not thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXTENSION_NAME
The name of the feature model extension.
-
Constructor Summary
Constructors Constructor Description ArtifactRules()
Create a new rules object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clear the object and reset to defaultsjavax.json.JsonObjectBuilder
createJson()
Convert this object into JSONvoid
fromJSONObject(javax.json.JsonObject jsonObj)
Extract the metadata from the JSON object.static ArtifactRules
getArtifactRules(org.apache.sling.feature.Extension ext)
Get the artifact rules from the extension - if it exists.static ArtifactRules
getArtifactRules(org.apache.sling.feature.Feature feature)
Get the artifact rules from the feature - if it exists.List<VersionRule>
getArtifactVersionRules()
Return the list of version rules for artifacts.List<VersionRule>
getBundleVersionRules()
Return the list of version rules for bundles.Mode
getMode()
Get the validation mode.static void
setArtifactRules(org.apache.sling.feature.Feature feature, ArtifactRules rules)
Set the rules as an extension to the featureprotected void
setDefaults()
Apply the non-null default values.void
setMode(Mode value)
Set the validation mode-
Methods inherited from class org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
getAttributes, getBoolean, getInteger, getNumber, getString, getString, getStringArray, setString, setStringArray, toJSONObject
-
-
-
-
Field Detail
-
EXTENSION_NAME
public static final String EXTENSION_NAME
The name of the feature model extension.- See Also:
- Constant Field Values
-
-
Method Detail
-
getArtifactRules
public static ArtifactRules getArtifactRules(org.apache.sling.feature.Feature feature)
Get the artifact rules from the feature - if it exists. If the rules are updated, the containing feature is left untouched.setArtifactRules(Feature, ArtifactRules)
can be used to update the feature.- Parameters:
feature
- The feature- Returns:
- The rules or
null
. - Throws:
IllegalArgumentException
- If the extension is wrongly formatted
-
getArtifactRules
public static ArtifactRules getArtifactRules(org.apache.sling.feature.Extension ext)
Get the artifact rules from the extension - if it exists. If the rules are updated, the containing feature is left untouched.setArtifactRules(Feature, ArtifactRules)
can be used to update the feature.- Parameters:
ext
- The extension- Returns:
- The rules or
null
if the extension isnull
. - Throws:
IllegalArgumentException
- If the extension is wrongly formatted
-
setArtifactRules
public static void setArtifactRules(org.apache.sling.feature.Feature feature, ArtifactRules rules)
Set the rules as an extension to the feature- Parameters:
feature
- The featurerules
- The rules. Ifnull
the extension will be removed.- Throws:
IllegalStateException
- If the feature has already an extension of a wrong typeIllegalArgumentException
- If the rules can't be serialized to JSON
-
setDefaults
protected void setDefaults()
Description copied from class:AttributeableEntity
Apply the non-null default values.- Overrides:
setDefaults
in classAttributeableEntity
-
clear
public void clear()
Clear the object and reset to defaults- Overrides:
clear
in classAttributeableEntity
-
createJson
public javax.json.JsonObjectBuilder createJson() throws IOException
Convert this object into JSON- Overrides:
createJson
in classAttributeableEntity
- Returns:
- The json object builder
- 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()
.- Overrides:
fromJSONObject
in classAttributeableEntity
- Parameters:
jsonObj
- The JSON Object- Throws:
IOException
- If JSON parsing fails
-
getMode
public Mode getMode()
Get the validation mode. The default isMode.STRICT
- Returns:
- The mode
-
setMode
public void setMode(Mode value)
Set the validation mode- Parameters:
value
- The validation mode
-
getBundleVersionRules
public List<VersionRule> getBundleVersionRules()
Return the list of version rules for bundles. The returned list is mutable.- Returns:
- The list of rules, might be empty.
-
getArtifactVersionRules
public List<VersionRule> getArtifactVersionRules()
Return the list of version rules for artifacts. The returned list is mutable.- Returns:
- the list of rules, might be empty.
-
-