Package org.apache.sling.feature.extension.apiregions.api.artifacts

# 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 final String`
`EXTENSION_NAME`
The name of the feature model extension.

## Constructor Summary

Constructors
Constructor
Description
`ArtifactRules()`
Create a new rules object

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
Clear the object and reset to defaults
`jakarta.json.JsonObjectBuilder`
`createJson()`
Convert this object into JSON
`void`
`fromJSONObject(jakarta.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 feature
`protected 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### EXTENSION_NAME

public static final String EXTENSION_NAME
The name of the feature model extension.

See Also:
  - Constant Field Values

## Constructor Details

### ArtifactRules

public ArtifactRules()
Create a new rules object

## Method Details

### 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 is `null`.
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 feature
  `rules` - The rules. If `null` the extension will be removed.
Throws:
  `IllegalStateException` - If the feature has already an extension of a wrong type
  `IllegalArgumentException` - 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 class `AttributeableEntity`

### clear

public void clear()
Clear the object and reset to defaults

Overrides:
  `clear` in class `AttributeableEntity`

### createJson

public jakarta.json.JsonObjectBuilder createJson() throws IOException
Convert this object into JSON

Overrides:
  `createJson` in class `AttributeableEntity`
Returns:
  The json object builder
Throws:
  `IOException` - If generating the JSON fails

### fromJSONObject

public void fromJSONObject(jakarta.json.JsonObject jsonObj) throws IOException
Extract the metadata from the JSON object. This method first calls `clear()`.

Overrides:
  `fromJSONObject` in class `AttributeableEntity`
Parameters:
  `jsonObj` - The JSON Object
Throws:
  `IOException` - If JSON parsing fails

### getMode

public Mode getMode()
Get the validation mode. The default is `Mode.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.