Package org.spdx.core

Class ModelRegistry


  • public class ModelRegistry
    extends Object
    Singleton class which contains a registry of SPDX model versions

    Each model version implements a model interface ISpdxModelInfo which supports inflating an SPDX type specific to that version

    Author:
    Gary O'Neall
    • Method Detail

      • getModelRegistry

        public static ModelRegistry getModelRegistry()
        Retrieve the singleton instance of the ModelRegistry
        Returns:
        the singleton instance of ModelRegistry
      • registerModel

        public void registerModel​(ISpdxModelInfo modelInfo)
        Register a model in the registry

        Each specification version supported by the model will be added to the registry.

        Parameters:
        modelInfo - The model information to register
      • containsSpecVersion

        public boolean containsSpecVersion​(String specVersion)
        Check if the specified SPDX specification version is supported by the registry
        Parameters:
        specVersion - The version of the SPDX specification to check.
        Returns:
        true if the specified specVersion is supported, false otherwise.
      • uriToEnum

        @Nullable
        public Enum<?> uriToEnum​(String uri,
                                 String specVersion)
                          throws 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:
        ModelRegistryException - if the spec version does not exist
      • getExternalElement

        public Object getExternalElement​(IModelStore store,
                                         String uri,
                                         @Nullable
                                         IModelCopyManager copyManager,
                                         Class<?> type,
                                         String specVersion)
                                  throws 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 to create the appropriate external element type
        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:
        InvalidSPDXAnalysisException - on any SPDX related error
      • uriToIndividual

        public Object uriToIndividual​(String individualUri,
                                      String specVersion,
                                      @Nullable
                                      Class<?> type)
                               throws ModelRegistryException
        Parameters:
        individualUri - URI for the individual
        specVersion - version of the SPDX spec the object complies with
        type - optional type hint - used for individuals where the type may be ambiguous
        Returns:
        Individual represented by the URI
        Throws:
        ModelRegistryException - if the registry does not support the specVersion
      • inflateModelObject

        public CoreModelObject inflateModelObject​(IModelStore modelStore,
                                                  String objectUri,
                                                  String type,
                                                  IModelCopyManager copyManager,
                                                  String specVersion,
                                                  boolean create,
                                                  String idPrefix)
                                           throws 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 external element
        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:
        InvalidSPDXAnalysisException - on any SPDX related exception
      • typeToClass

        @Nullable
        public Class<?> typeToClass​(String type,
                                    String specVersion)
                             throws ModelRegistryException
        Parameters:
        type - String representation of the SPDX type
        specVersion - version of the SPDX spec
        Returns:
        the class representing the SPDX type, null if it does not exist in the model
        Throws:
        ModelRegistryException - if the spec version isn't found
      • clearAll

        public void clearAll()
        Removes all the registered models - should only be used in testing
      • getSupportedVersions

        public List<String> getSupportedVersions()
        Retrieve a list of all supported SPDX specification versions
        Returns:
        An unmodifiable list of all supported specification versions.
      • canBeExternal

        public boolean canBeExternal​(Class<?> clazz,
                                     String specVersion)
                              throws ModelRegistryException
        Determine if the specified class can be represented as external to the model store for the given SPDX specification version
        Parameters:
        clazz - The model class to check.
        specVersion - The version of the SPDX specification.
        Returns:
        true if the class can be represented as external to the store, false otherwise.
        Throws:
        ModelRegistryException - If the registry does not support the specified specVersion.