Class ExtensionSlotManager

java.lang.Object
org.incenp.obofoundry.sssom.ExtensionSlotManager

public class ExtensionSlotManager extends Object
A helper class to deal with non-standard metadata slots and their definitions.
  • Field Details

    • UNDEFINED_EXTENSION_NAMESPACE

      public static final String UNDEFINED_EXTENSION_NAMESPACE
      The default namespace for auto-generated properties for undefined extensions.
      See Also:
    • DEFAULT_TYPE_HINT

      public static final String DEFAULT_TYPE_HINT
      The default type for extensions that are either undefined or that do not have an explicit type.
  • Constructor Details

    • ExtensionSlotManager

      public ExtensionSlotManager(ExtraMetadataPolicy policy)
      Creates a new instance without a prefix manager. Such an instance can be used when working with full-length identifiers only.
      Parameters:
      policy - The policy that determines how to deal with non-standard metadata slots. When the policy is set to ExtraMetadataPolicy.NONE, most operations of this object are no-op.
    • ExtensionSlotManager

      public ExtensionSlotManager(ExtraMetadataPolicy policy, PrefixManager prefixManager)
      Creates a new instance.
      Parameters:
      policy - The policy that determines how to deal with non-standard metadata slots. When the policy is set to ExtraMetadataPolicy.NONE, most operations of this object are no-op.
      prefixManager - The prefix manager used to resolve any compact IRI encountered in extension definitions.
  • Method Details

    • addDefinition

      public boolean addDefinition(String slotName, String property, String typeHint)
      Defines a new extension slot.
      Parameters:
      slotName - The name of the slot, as it appears in the YAML metadata block (for set-level extensions) or as a column header (for mapping-level extensions).
      property - The property associated with the slot.
      typeHint - The expected type of values for this slot. May be null, in which case the default is xsd:string.
      Returns:
      true if the new slot has been defined correctly. or false if either the slot_name or the property is null, or if the slot name is invalid.
    • getDefinitionForSlot

      public ExtensionDefinition getDefinitionForSlot(String slotName)
      Looks up for an existing definition for the specified slot name. If no definition exists and the policy is set to ExtraMetadataPolicy.UNDEFINED, then a new definition is automatically generated on the fly.
      Parameters:
      slotName - The name of the slot for which a definition is requested.
      Returns:
      The slot definition. May be null if the policy is set to ExtraMetadataPolicy.NONE, or if it is set to ExtraMetadataPolicy.DEFINED and no prior definition exists.
    • getDefinitionForProperty

      public ExtensionDefinition getDefinitionForProperty(String property)
      Looks up for an existing definition for the specified property.
      Parameters:
      property - The property of the slot for which a definition is requested.
      Returns:
      The slot definition. May be null if the policy is set to ExtraMetadataPolicy.NONE, or if no definition for the specified property exists.
    • fillFromExistingExtensions

      public void fillFromExistingExtensions(MappingSet ms)
      Gets definitions for all extensions used in the specified mapping set. Existing definitions found in the set itself will be used when available, otherwise definitions will be auto-generated when needed. Note that existing definitions in the set that are never used throughout the set are ignored.
      Parameters:
      ms - The mapping set to get extension definitions from.
    • getUsedPrefixes

      public Set<String> getUsedPrefixes()
      Gets all the prefix names used in extensions and extension definitions.

      When this object is initialised from a mapping set (through fillFromExistingExtensions(MappingSet)), all prefix names used throughout all extension values and all extension definition will be collected. This allows to know which prefixes are required to compact all IRIs present in extensions. The prefix names are those from the prefix manager used by this object.

      Returns:
      The set of all prefix names used in extensions.
    • isEmpty

      public boolean isEmpty()
      Indicates whether this object contains any extension definition.
      Returns:
      true if this object knows of no extension, otherwise true.
    • isExtensionSlotNameValid

      public static boolean isExtensionSlotNameValid(String name)
      Checks whether the specified name is usable as an extension slot name.
      Parameters:
      name - The name to check.
      Returns:
      true if the name is a valid extension slot name, false otherwise.
    • getDefinitions

      public List<ExtensionDefinition> getDefinitions(boolean sorted, boolean mappingLevelOnly)
      Gets the definitions known to this manager.
      Parameters:
      sorted - true to get a list where the definitions are sorted on their properties; if false, the order of definitions in the returned list is unspecified.
      mappingLevelOnly - If true, returns only the definitions for extensions that are used at the mapping level, excluding any definition for extensions that are only found at the set level; otherwise, returns all definitions.
      Returns:
      The list of definitions. This is a copy of the internal list, any change on the returned list will not affect the state of this object.