Package org.apache.sling.feature

# Class Extension

java.lang.Object
org.apache.sling.feature.Extension

All Implemented Interfaces:
  `Serializable`

public class Extension extends Object implements Serializable
An Extension can either be of type

- Artifacts : it contains a list of artifacts
- Text : it contains text
- JSON : it contains a blob of JSON

An extension can be in one of these states

- Required : Required extensions need to be processed by tooling
- Optional : Optional extensions might be processed by tooling, for example they might contain environment specific parts
- Transient: Transient extensions are cache like extensions where tooling can store additional information to avoid reprocessing of down stream tooling. However such tooling must work without the transient extension being available.

This class is not thread-safe.

See Also:
  - `ExtensionType`
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`EXTENSION_NAME_ASSEMBLED_FEATURES`
Extension name containing the assembled features as produced by `FeatureBuilder.assemble(ArtifactId, BuilderContext, Feature...)`.
`static final String`
`EXTENSION_NAME_CONTENT_PACKAGES`
Common extension name to specify the content packages for Apache Sling.
`static final String`
`EXTENSION_NAME_INTERNAL_DATA`
Extension name containing internal data.
`static final String`
`EXTENSION_NAME_REPOINIT`
Common extension name to specify the repoinit part for Apache Sling.

## Constructor Summary

Constructors
Constructor
Description
`Extension(ExtensionType type, String name, ExtensionState state)`
Create a new extension

## Method Summary

Modifier and Type
Method
Description
`Extension`
`copy()`
Create a copy of the Extension
`boolean`
`equals(Object obj)`
`Artifacts`
`getArtifacts()`
Get the artifacts of the extension
`String`
`getJSON()`
Get the JSON of the extension
`jakarta.json.JsonStructure`
`getJSONStructure()`
Get the JSON structure of the extension
`String`
`getName()`
Get the extension name
`ExtensionState`
`getState()`
Get the extension state
`String`
`getText()`
Get the text of the extension
`ExtensionType`
`getType()`
Get the extension type
`int`
`hashCode()`
`void`
`setJSON(String text)`
Set the JSON of the extension
`void`
`setJSONStructure(jakarta.json.JsonStructure struct)`
Set the JSON structure of the extension
`void`
`setText(String text)`
Set the text of the extension
`String`
`toString()`

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

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### EXTENSION_NAME_REPOINIT

public static final String EXTENSION_NAME_REPOINIT
Common extension name to specify the repoinit part for Apache Sling. This extension is of type `ExtensionType.TEXT` and is required.

See Also:
  - Constant Field Values

### EXTENSION_NAME_CONTENT_PACKAGES

public static final String EXTENSION_NAME_CONTENT_PACKAGES
Common extension name to specify the content packages for Apache Sling. This extension is of type `ExtensionType.ARTIFACTS` and is required.

See Also:
  - Constant Field Values

### EXTENSION_NAME_ASSEMBLED_FEATURES

public static final String EXTENSION_NAME_ASSEMBLED_FEATURES
Extension name containing the assembled features as produced by `FeatureBuilder.assemble(ArtifactId, BuilderContext, Feature...)`. This extension is of type `ExtensionType.ARTIFACTS` and is optional.

See Also:
  - Constant Field Values

### EXTENSION_NAME_INTERNAL_DATA

public static final String EXTENSION_NAME_INTERNAL_DATA
Extension name containing internal data. An extension with this name must not be created by hand, it is managed by the feature model implementation. This extension is of type `ExtensionType.JSON` and is optional.

Since:
  1.7.0
See Also:
  - Constant Field Values

## Constructor Details

### Extension

public Extension(ExtensionType type, String name, ExtensionState state)
Create a new extension

Parameters:
  `type` - The type of the extension
  `name` - The name of the extension
  `state` - The state of the extension
Throws:
  `IllegalArgumentException` - If name, type or state is `null`
Since:
  1.1

## Method Details

### getType

public ExtensionType getType()
Get the extension type

Returns:
  The type

### getState

public ExtensionState getState()
Get the extension state

Returns:
  The state
Since:
  1.1

### getName

public String getName()
Get the extension name

Returns:
  The name

### getText

public String getText()
Get the text of the extension

Returns:
  The text
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#TEXT`

### setText

public void setText(String text)
Set the text of the extension

Parameters:
  `text` - The text
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#TEXT`

### getJSON

public String getJSON()
Get the JSON of the extension

Returns:
  The JSON or `null`
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#JSON`

### setJSON

public void setJSON(String text)
Set the JSON of the extension

Parameters:
  `text` - The JSON
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#JSON`
  `IllegalArgumentException` - If the structure is not valid

### getJSONStructure

public jakarta.json.JsonStructure getJSONStructure()
Get the JSON structure of the extension

Returns:
  The JSON object or `null`
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#JSON`
Since:
  1.1

### setJSONStructure

public void setJSONStructure(jakarta.json.JsonStructure struct)
Set the JSON structure of the extension

Parameters:
  `struct` - The JSON structure
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#JSON`
  `IllegalArgumentException` - If the structure is not valid
Since:
  1.1

### getArtifacts

public Artifacts getArtifacts()
Get the artifacts of the extension

Returns:
  The artifacts
Throws:
  `IllegalStateException` - if the type is not `ExtensionType#ARTIFACTS`

### copy

public Extension copy()
Create a copy of the Extension

Returns:
  A copy of the Extension

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`