Package org.spdx.core
Class ModelRegistry
- java.lang.Object
-
- org.spdx.core.ModelRegistry
-
public class ModelRegistry extends Object
Singleton class which contains a registry of SPDX model versionsEach model version implements a model interface
ISpdxModelInfo
which supports inflating an SPDX type specific to that version- Author:
- Gary O'Neall
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBeExternal(Class<?> clazz, String specVersion)
void
clearAll()
Removes all the registered models - should only be used in testingboolean
containsSpecVersion(String specVersion)
Object
getExternalElement(IModelStore store, String uri, IModelCopyManager copyManager, Class<?> type, String specVersion)
static ModelRegistry
getModelRegistry()
List<String>
getSupportedVersions()
CoreModelObject
inflateModelObject(IModelStore modelStore, String objectUri, String type, IModelCopyManager copyManager, String specVersion, boolean create, String idPrefix)
If the object exists in the model store, it will be "inflated" back to the Java object.void
registerModel(ISpdxModelInfo modelInfo)
Class<?>
typeToClass(String type, String specVersion)
Enum<?>
uriToEnum(String uri, String specVersion)
Converts a URI to enumObject
uriToIndividual(String individualUri, String specVersion, Class<?> type)
-
-
-
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 individualspecVersion
- 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 objecturi
- URI of the external elementcopyManager
- if non-null, implicitly copy any referenced properties from other model storestype
- type hint to create the appropriate external element typespecVersion
- 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 individualspecVersion
- version of the SPDX spec the object complies withtype
- 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 objectobjectUri
- URI of the external elementtype
- Type of the object to createcopyManager
- if non-null, implicitly copy any referenced properties from other model storesspecVersion
- version of the SPDX spec the object complies withcreate
- if true, create the model object ONLY if it does not already existidPrefix
- 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 typespecVersion
- 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 classspecVersion
- version of the spec- Returns:
- true if clazz can be represented as external to the store
- Throws:
ModelRegistryException
- on uninitialized registry
-
-