Interface IModelStore

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
IListedLicenseStore, ISerializableModelStore
All Known Implementing Classes:
ExtendedSpdxStore, InMemSpdxStore, SpdxListedLicenseLocalStore, SpdxListedLicenseModelStore, SpdxListedLicenseWebStore

public interface IModelStore extends AutoCloseable
Service Provider Interface for storing and retrieving SPDX properties for SPDX documents. The interface uses the SPDX document URI and an ID to identify specific objects stored. Each object can have property values and property value lists associated with them. A property value is an object of a primitive type (e.g. String or Boolean) or is another object which includes it's own ID and must also have a type described in the SPDX model. A property list is just a list of values.
Author:
Gary O'Neall
  • Method Details

    • exists

      boolean exists(String documentUri, String id)
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      Returns:
      true if the id already exists for the document
    • create

      void create(String documentUri, String id, String type) throws InvalidSPDXAnalysisException
      Create a new object with ID
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      type - SPDX model type as defined in the CLASS constants in SpdxConstants
      Throws:
      InvalidSPDXAnalysisException
    • getPropertyValueNames

      List<String> getPropertyValueNames(String documentUri, String id) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      Returns:
      Property names for all properties having a value for a given id within a document
      Throws:
      InvalidSPDXAnalysisException
    • setValue

      void setValue(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException
      Sets a property value for a String or Boolean type of value creating the propertyName if it does not exist
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      value - value to set
      Throws:
      InvalidSPDXAnalysisException
    • getValue

      Optional<Object> getValue(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      Returns:
      the single value associated with the id, propertyName and document
      Throws:
      InvalidSPDXAnalysisException
    • getNextId

      String getNextId(IModelStore.IdType idType, String documentUri) throws InvalidSPDXAnalysisException
      Generate a unique ID for use within the document
      Parameters:
      idType - Type of ID
      documentUri - the SPDX Document URI
      Returns:
      next available unique ID for the specific idType
      Throws:
      InvalidSPDXAnalysisException
    • removeProperty

      void removeProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyName does not exist
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      Throws:
      InvalidSPDXAnalysisException
    • getDocumentUris

      List<String> getDocumentUris()
      Returns:
      a list of all Document URI's stored in the model store
    • getAllItems

      Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeFilter) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - SPDX Document URI for a document associated with this model
      typeFilter - Optional parameter to specify the type of objects to be retrieved
      Returns:
      Stream of all items store within the document
      Throws:
      InvalidSPDXAnalysisException
    • enterCriticalSection

      IModelStore.IModelStoreLock enterCriticalSection(String documentUri, boolean readLockRequested) throws InvalidSPDXAnalysisException
      Enter a critical section. leaveCriticialSection must be called.
      Parameters:
      readLockRequested - true implies a read lock, false implies write lock.
      Throws:
      InvalidSPDXAnalysisException
    • leaveCriticalSection

      void leaveCriticalSection(IModelStore.IModelStoreLock lock)
      Leave a critical section. Releases the lock form the matching enterCriticalSection
    • removeValueFromCollection

      boolean removeValueFromCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException
      Removes a value from a collection of values associated with a property
      Parameters:
      documentUri - Unique document URI
      id - ID of the item to associate the property with
      propertyName - name of the property
      value - Value to be removed
      Returns:
      Throws:
      InvalidSPDXAnalysisException
    • collectionSize

      int collectionSize(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - Unique document URI
      id - ID of the item to associate the property with
      propertyName - name of the property
      Returns:
      size of a collection associated with a property. 0 if the property does not exist.
      Throws:
      InvalidSPDXAnalysisException
    • collectionContains

      boolean collectionContains(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - Unique document URI
      id - ID of the item to associate the property with
      propertyName - name of the property
      value -
      Returns:
      true if the collection associated with a property contains the value
      Throws:
      InvalidSPDXAnalysisException
    • clearValueCollection

      void clearValueCollection(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Sets the value collection for the property to an empty collection creating the propertyName if it does not exist
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      Throws:
      InvalidSPDXAnalysisException
    • addValueToCollection

      boolean addValueToCollection(String documentUri, String id, String propertyName, Object value) throws InvalidSPDXAnalysisException
      Adds a value to a property collection creating the propertyName if it does not exist
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      value - value to add
      Returns:
      true if the collection was modified
      Throws:
      InvalidSPDXAnalysisException
    • listValues

      Iterator<Object> listValues(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      Returns:
      Iterator over the list of values associated with the id, propertyName and document
      Throws:
      InvalidSPDXAnalysisException
    • isCollectionMembersAssignableTo

      boolean isCollectionMembersAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      clazz - Class to test compatibility with
      Returns:
      true if all members of a collection associated with the id and propertyName can be assigned to the clazz
      Throws:
      InvalidSPDXAnalysisException
    • isPropertyValueAssignableTo

      boolean isPropertyValueAssignableTo(String documentUri, String id, String propertyName, Class<?> clazz) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      clazz - Class to test compatibility with
      Returns:
      true if the value associated with the id and propertyName can be assigned to the clazz
      Throws:
      InvalidSPDXAnalysisException
    • isCollectionProperty

      boolean isCollectionProperty(String documentUri, String id, String propertyName) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      propertyName - Name of the property
      Returns:
      true if the propertyName represents multiple values
      Throws:
      InvalidSPDXAnalysisException
    • getIdType

      IModelStore.IdType getIdType(String id)
      Parameters:
      id -
      Returns:
      The type of ID based on the string format
    • getCaseSensisitiveId

      Optional<String> getCaseSensisitiveId(String documentUri, String caseInsensisitiveId)
      In SPDX 2.2 license refs are allowed to be matched case insensitive. This function will return the case sensitivie ID (e.g. if you have LicenseRef-ABC, calling this function with licenseref-abc will return LicenseRef-ABC
      Parameters:
      documentUri - the SPDX Document URI
      caseInsensisitiveId -
      Returns:
      the case sensitive ID if it exists
    • getTypedValue

      Optional<TypedValue> getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      Returns:
      type TypedValue containing the type of the ModelObject related to the ID
      Throws:
      InvalidSPDXAnalysisException
    • delete

      void delete(String documentUri, String id) throws InvalidSPDXAnalysisException
      Deletes an item from the document
      Parameters:
      documentUri - the SPDX Document URI
      id - unique ID within the SPDX document
      Throws:
      InvalidSPDXAnalysisException