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()
      • registerModel

        public void registerModel​(ISpdxModelInfo modelInfo)
        Parameters:
        modelInfo - model info to register
      • containsSpecVersion

        public boolean containsSpecVersion​(String specVersion)
        Parameters:
        specVersion - version of the spc
        Returns:
        true if the specVersion is supported in one of the registered model infos
      • 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()
        Returns:
        a list of all supported versions
      • canBeExternal

        public boolean canBeExternal​(Class<?> clazz,
                                     String specVersion)
                              throws ModelRegistryException
        Parameters:
        clazz - model class
        specVersion - version of the spec
        Returns:
        true if clazz can be represented as external to the store
        Throws:
        ModelRegistryException - on uninitialized registry