Class RdfStore

java.lang.Object
org.spdx.spdxRdfStore.RdfStore
All Implemented Interfaces:
AutoCloseable, org.spdx.storage.IModelStore, org.spdx.storage.ISerializableModelStore

public class RdfStore extends Object implements org.spdx.storage.IModelStore, org.spdx.storage.ISerializableModelStore
Model Store implemented using RDF
Author:
Gary O'Neall
  • Constructor Details

    • RdfStore

      public RdfStore(InputStream stream) throws org.spdx.core.InvalidSPDXAnalysisException
      Create an RDF store and initialize it with an SPDX document deserialized from stream Note that the stream must contain one and only one SPDX document in SPDX version 2.X format
      Parameters:
      stream - input stream of a model
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
    • RdfStore

      public RdfStore()
      Creates an uninitialized RDF store - the documentUri must be set or a stream deserialized before any other methods are called
    • RdfStore

      public RdfStore(InputStream stream, String documentUri) throws org.spdx.core.InvalidSPDXAnalysisException
      Create an RDF store and initialize it with a data deserialized from stream using the documentUri for ID prefixes
      Parameters:
      stream - stream of an RDF model
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
    • RdfStore

      public RdfStore(String documentUri)
      Parameters:
      documentUri - URI for the SPDX document used in this store
  • Method Details

    • getOutputFormat

      public OutputFormat getOutputFormat()
      Returns:
      the outputFormat
    • getDocumentUri

      @Nullable public String getDocumentUri()
      Returns:
      the document URI
    • setDocumentUri

      public void setDocumentUri(@Nullable String documentUri, boolean overwrite) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      documentUri - document URI to set
      overwrite - setting a different document URI will overwrite an existing model - this flag will allow it to be overwritten
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - if the document URI already exists and override is set to false
    • setOutputFormat

      public void setOutputFormat(OutputFormat outputFormat)
      Parameters:
      outputFormat - the outputFormat to set
    • isDontStoreLicenseDetails

      public boolean isDontStoreLicenseDetails()
      Returns:
      the dontStoreLicenseDetails - if true, listed license properties will not be stored in the RDF store
    • setDontStoreLicenseDetails

      public void setDontStoreLicenseDetails(boolean dontStoreLicenseDetails)
      Parameters:
      dontStoreLicenseDetails - the dontStoreLicenseDetails to set - if true, listed license properties will not be stored in the RDF store
    • exists

      public boolean exists(String objectUri)
      Specified by:
      exists in interface org.spdx.storage.IModelStore
    • isAnon

      public boolean isAnon(String objectUri)
      Specified by:
      isAnon in interface org.spdx.storage.IModelStore
    • getIdType

      public org.spdx.storage.IModelStore.IdType getIdType(String objectUri)
      Specified by:
      getIdType in interface org.spdx.storage.IModelStore
    • create

      public void create(org.spdx.core.TypedValue typedValue) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      create in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • getPropertyValueDescriptors

      public List<org.spdx.storage.PropertyDescriptor> getPropertyValueDescriptors(String objectUri) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      getPropertyValueDescriptors in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • setValue

      public void setValue(String objectUri, org.spdx.storage.PropertyDescriptor prop, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      setValue in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • getValue

      public Optional<Object> getValue(String objectUri, org.spdx.storage.PropertyDescriptor prop) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      getValue in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • getNextId

      public String getNextId(org.spdx.storage.IModelStore.IdType idType) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      getNextId in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • removeProperty

      public void removeProperty(String objectUri, org.spdx.storage.PropertyDescriptor prop) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      removeProperty in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • getAllItems

      public Stream<org.spdx.core.TypedValue> getAllItems(@Nullable String prefix, String typeFilter) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      getAllItems in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • removeValueFromCollection

      public boolean removeValueFromCollection(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      removeValueFromCollection in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • collectionSize

      public int collectionSize(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      collectionSize in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • collectionContains

      public boolean collectionContains(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      collectionContains in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • clearValueCollection

      public void clearValueCollection(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      clearValueCollection in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • addValueToCollection

      public boolean addValueToCollection(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor, Object value) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      addValueToCollection in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • listValues

      public Iterator<Object> listValues(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      listValues in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • isCollectionMembersAssignableTo

      public boolean isCollectionMembersAssignableTo(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor, Class<?> clazz) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      isCollectionMembersAssignableTo in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • isPropertyValueAssignableTo

      public boolean isPropertyValueAssignableTo(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      isPropertyValueAssignableTo in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • isCollectionProperty

      public boolean isCollectionProperty(String objectUri, org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      isCollectionProperty in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • leaveCriticalSection

      public void leaveCriticalSection(org.spdx.storage.IModelStore.IModelStoreLock lock)
      Specified by:
      leaveCriticalSection in interface org.spdx.storage.IModelStore
    • enterCriticalSection

      public org.spdx.storage.IModelStore.IModelStoreLock enterCriticalSection(boolean readLockRequested) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      enterCriticalSection in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • loadModelFromFile

      public String loadModelFromFile(String fileNameOrUrl, boolean overwrite) throws org.spdx.core.InvalidSPDXAnalysisException, IOException
      Load a document from a file or URL
      Parameters:
      fileNameOrUrl - file name or URL of a serialized RDF model
      overwrite - if true, overwrite any existing documents with the same document URI
      Returns:
      the DocumentURI of the SPDX document
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
      IOException - on IO error
    • getSpdxDocNodes

      public static List<org.apache.jena.graph.Node> getSpdxDocNodes(org.apache.jena.rdf.model.Model model)
      Returns:
      the spdx doc nodes from the model
    • getDocumentNamespaces

      public static List<String> getDocumentNamespaces(org.apache.jena.rdf.model.Model model) throws org.spdx.core.InvalidSPDXAnalysisException
      Parameters:
      model - model containing a single document
      Returns:
      the document namespace for the document stored in the model
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
    • serialize

      public void serialize(OutputStream stream) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      serialize in interface org.spdx.storage.ISerializableModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • serialize

      public void serialize(OutputStream stream, @Nullable org.spdx.core.CoreModelObject spdxDocument) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      serialize in interface org.spdx.storage.ISerializableModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • deSerialize

      public org.spdx.library.model.v2.SpdxDocument deSerialize(InputStream stream, boolean overwrite) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      deSerialize in interface org.spdx.storage.ISerializableModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • deSerialize

      public void deSerialize(InputStream stream, boolean overwrite, String documentNamespace) throws org.spdx.core.InvalidSPDXAnalysisException
      Deserialize an RDF stream without an enclosing document
      Parameters:
      stream - stream containing the SPDX data
      documentNamespace - document namespace to use
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException - on SPDX parsing errors
    • getCaseSensitiveId

      public Optional<String> getCaseSensitiveId(String documentUri, String caseInsensisitiveId)
      Specified by:
      getCaseSensitiveId in interface org.spdx.storage.IModelStore
    • getTypedValue

      public Optional<org.spdx.core.TypedValue> getTypedValue(String objectUri) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      getTypedValue in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • delete

      public void delete(String objectUri) throws org.spdx.core.InvalidSPDXAnalysisException
      Specified by:
      delete in interface org.spdx.storage.IModelStore
      Throws:
      org.spdx.core.InvalidSPDXAnalysisException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable