Class SpdxModelFactory


  • public class SpdxModelFactory
    extends Object
    Main entrypoint for the SPDX Java Library This is a static class used to manage the different versions of the SPDX spec by creating different model classes based on the version of the spec. Since the release of the SPDX spec version 3.0, the Java classes were generated. Each generated set of classes generated for a specific version are in a separate library / Jar file. These generated classes are registered in the Core model registry The inflateModelObject methods will create an initial object based on the name of the type
    Author:
    Gary O'Neall
    • Method Detail

      • getLatestSpecVersion

        public static String getLatestSpecVersion()
        Returns:
        the latest version of the spec supported by the library
      • init

        public static void init()
        This static method is a convenience to load this class and initialize the supported model versions. It should be called before using any other functionality from the library
      • inflateModelObject

        public static org.spdx.core.CoreModelObject inflateModelObject​(org.spdx.storage.IModelStore modelStore,
                                                                       String objectUri,
                                                                       String type,
                                                                       org.spdx.core.IModelCopyManager copyManager,
                                                                       String specVersion,
                                                                       boolean create,
                                                                       @Nullable
                                                                       String idPrefix)
                                                                throws org.spdx.core.InvalidSPDXAnalysisException
        If the object exists in the model store, it will be "inflated" back to the Java object. If the object does not exist AND the create parameter is true, a new object will be created and its inflated form will be returned
        Parameters:
        modelStore - store to use for the inflated object
        objectUri - URI of the element or SPDX object
        type - Type of the object to create
        copyManager - if non-null, implicitly copy any referenced properties from other model stores
        specVersion - version of the SPDX spec the object complies with
        create - if true, create the model object ONLY if it does not already exist
        idPrefix - optional prefix used for any new object URI's created in support of this model object
        Returns:
        model object of type type
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • inflateModelObject

        public static org.spdx.core.CoreModelObject inflateModelObject​(org.spdx.storage.IModelStore modelStore,
                                                                       String objectUri,
                                                                       String type,
                                                                       org.spdx.core.IModelCopyManager copyManager,
                                                                       boolean create,
                                                                       @Nullable
                                                                       String idPrefix)
                                                                throws org.spdx.core.InvalidSPDXAnalysisException
        For the most recent spec version supported: If the object exists in the model store, it will be "inflated" back to the Java object. If the object does not exist AND the create parameter is true, a new object will be created and its inflated form will be returned
        Parameters:
        modelStore - store to use for the inflated object
        objectUri - URI of the external element
        type - Type of the object to create
        copyManager - if non-null, implicitly copy any referenced properties from other model stores
        create - if true, create the model object ONLY if it does not already exist
        idPrefix - optional prefix used for any new object URI's created in support of this model object
        Returns:
        model object of type type
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • getExternalElement

        public static Object getExternalElement​(org.spdx.storage.IModelStore store,
                                                String uri,
                                                @Nullable
                                                org.spdx.core.IModelCopyManager copyManager,
                                                Class<?> type,
                                                String specVersion)
                                         throws org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        store - store to use for the inflated object
        uri - URI of the external element
        copyManager - if non-null, implicitly copy any referenced properties from other model stores
        type - type hint for creating the correct external element
        specVersion - version of the SPDX spec the object complies with
        Returns:
        a java object representing an SPDX element external to model store, collection or document
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • getExternalElement

        public static Object getExternalElement​(org.spdx.storage.IModelStore store,
                                                String uri,
                                                @Nullable
                                                org.spdx.core.IModelCopyManager copyManager,
                                                Class<?> type)
                                         throws org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        store - store to use for the inflated object
        uri - URI of the external element
        copyManager - if non-null, implicitly copy any referenced properties from other model stores
        type - type hint for creating the correct external element
        Returns:
        a java object representing an SPDX element external to model store, collection or document for the most recent version of the spec supported
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • uriToEnum

        @Nullable
        public static Enum<?> uriToEnum​(String uri,
                                        String specVersion)
                                 throws org.spdx.core.ModelRegistryException
        Converts a URI to enum
        Parameters:
        uri - URI for the Enum individual
        specVersion - Version of the spec the enum belongs to
        Returns:
        the Enum represented by the individualURI if it exists within the spec model
        Throws:
        org.spdx.core.ModelRegistryException - if the spec version does not exist
      • uriToEnum

        @Nullable
        public static Enum<?> uriToEnum​(String uri)
                                 throws org.spdx.core.ModelRegistryException
        Converts a URI to enum for the latest supported version of the spec
        Parameters:
        uri - URI for the Enum individual
        Returns:
        the Enum represented by the individualURI if it exists within the spec model
        Throws:
        org.spdx.core.ModelRegistryException - if the spec version does not exist
      • getSpdxObjects

        public static Stream<?> getSpdxObjects​(org.spdx.storage.IModelStore store,
                                               @Nullable
                                               org.spdx.core.IModelCopyManager copyManager,
                                               @Nullable
                                               String typeFilter,
                                               @Nullable
                                               String objectUriPrefixFilter,
                                               @Nullable
                                               String idPrefix)
                                        throws org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        store - model store
        copyManager - optional copy manager
        typeFilter - type to filter on
        objectUriPrefixFilter - only return objects with URI's starting with this string
        idPrefix - optional prefix used for any new object URI's created in support of this model object
        Returns:
        stream of objects stored in the model store - an object being any non primitive type
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException