Class Artifact

java.lang.Object
org.apache.sling.feature.Artifact
All Implemented Interfaces:
Serializable, Comparable<Artifact>

public class Artifact extends Object implements Comparable<Artifact>, Serializable
An artifact consists of
  • An id
  • metadata
  • optional alias and start order properties (which are part of the metadata)
This class is not thread-safe.
See Also:
  • Field Details

    • KEY_ALIAS

      public static final String KEY_ALIAS
      Can be used in artifact metadata to specify an alias. Multiple aliases can be comma-separated.
      See Also:
    • KEY_START_ORDER

      public static final String KEY_START_ORDER
      This key might be used by bundles to define the start order.
      See Also:
    • KEY_FEATURE_ORIGINS

      public static final String KEY_FEATURE_ORIGINS
      See Also:
  • Constructor Details

    • Artifact

      public Artifact(ArtifactId id)
      Construct a new artifact
      Parameters:
      id - The id of the artifact.
      Throws:
      IllegalArgumentException - If id is null.
    • Artifact

      public Artifact(jakarta.json.JsonValue json)
      Construct a new artifact
      Parameters:
      json - The json for the artifact
      Throws:
      IllegalArgumentException - If json is null or wrongly formatted.
      Since:
      1.4
  • Method Details

    • getId

      public ArtifactId getId()
      Get the id of the artifact.
      Returns:
      The id.
    • getMetadata

      public Map<String,String> getMetadata()
      Get the metadata of the artifact. The metadata can be modified.
      Returns:
      The metadata.
    • getAliases

      public Set<ArtifactId> getAliases(boolean includeMain)
      Obtain the alias or aliases for the artifact.
      Parameters:
      includeMain - Whether to include the main ID in the result.
      Returns:
      The aliases or an empty set if there are none.
    • getStartOrder

      public int getStartOrder()
      Get the start order of the artifact. This is a convenience method which gets the value for the property named #KEY_START_ORDER from the metadata.
      Returns:
      The start order, if no start order is defined, 0 is returned.
      Throws:
      NumberFormatException - If the stored metadata is not a number
      IllegalStateException - If the stored metadata is a negative number
    • setStartOrder

      public void setStartOrder(int startOrder)
      Set the start order of the artifact This is a convenience method which sets the value of the property named #KEY_START_ORDER from the metadata.
      Parameters:
      startOrder - The start order
      Throws:
      IllegalArgumentException - If the number is negative
    • getFeatureOrigins

      public ArtifactId[] getFeatureOrigins()
      Get the feature origins - if recorded
      Returns:
      A array of feature artifact ids - array might be empty
      Throws:
      IllegalArgumentException - If the stored values are not valid artifact ids
    • getFeatureOrigins

      public ArtifactId[] getFeatureOrigins(ArtifactId self)
      Get the feature origins If no origins are recorded, the provided artifact id is returned
      Parameters:
      self - The id of the current feature
      Returns:
      An array of feature artifact ids
      Throws:
      IllegalArgumentException - If the stored values are not valid artifact ids
      Since:
      1.7.0
    • setFeatureOrigins

      public void setFeatureOrigins(ArtifactId... featureOrigins)
      Set the feature origins
      Parameters:
      featureOrigins - the array of artifact ids or null to remove the info from this object
    • compareTo

      public int compareTo(Artifact o)
      Specified by:
      compareTo in interface Comparable<Artifact>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • copy

      public Artifact copy(ArtifactId id)
      Create a copy of the artifact with a different id
      Parameters:
      id - The new id
      Returns:
      The copy of the feature with the new id
    • toString

      public String toString()
      Overrides:
      toString in class Object