Package org.spdx.storage
Interface IModelStore
-
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
ISerializableModelStore
- All Known Implementing Classes:
NullModelStore
public interface IModelStore extends AutoCloseable
Service Provider Interface for storing and retrieving SPDX properties from the underlying store.The interface uses the URI to identify specific objects stored.
Each object can have property values and property value lists associated with them.
A property value is an object of a primitive type (e.g. String or Boolean) or is another object which includes its own ID and must also have a type described in the SPDX model.
A property list is just a list of values.
- Author:
- Gary O'Neall
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
IModelStore.IdType
Different types of ID'sstatic interface
IModelStore.IModelStoreLock
static interface
IModelStore.ModelUpdate
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description boolean
addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
Adds a value to a property collection creating the propertyDescriptor if it does not existvoid
clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor)
Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not existboolean
collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
int
collectionSize(String objectUri, PropertyDescriptor propertyDescriptor)
void
create(TypedValue typedValue)
Create a new object with objectUri, type and version from the typedValuevoid
delete(String objectUri)
Deletes an item from the documentIModelStore.IModelStoreLock
enterCriticalSection(boolean readLockRequested)
Enter a critical section.boolean
exists(String objectUri)
Stream<TypedValue>
getAllItems(String nameSpace, String typeFilter)
default Optional<String>
getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId)
Deprecated.As of release 1.0, replaced bygetCaseSensitiveId(String, String)
default Optional<String>
getCaseSensitiveId(String nameSpace, String caseInsensitiveId)
In SPDX 2.2 license refs are allowed to be matched case-insensitive.IModelStore.IdType
getIdType(String objectUri)
String
getNextId(IModelStore.IdType idType)
Generate a unique ID within the model store - Note: for a full URI, the id should be prepended with a URI prefixList<PropertyDescriptor>
getPropertyValueDescriptors(String objectUri)
Optional<TypedValue>
getTypedValue(String objectUri)
Optional<Object>
getValue(String objectUri, PropertyDescriptor propertyDescriptor)
boolean
isAnon(String objectUri)
boolean
isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz)
boolean
isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor)
boolean
isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion)
void
leaveCriticalSection(IModelStore.IModelStoreLock lock)
Leave a critical section.Iterator<Object>
listValues(String objectUri, PropertyDescriptor propertyDescriptor)
void
removeProperty(String objectUri, PropertyDescriptor propertyDescriptor)
Removes a property from the document for the given ID if the property exists.boolean
removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
Removes a value from a collection of values associated with a propertyvoid
setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value)
Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Method Detail
-
exists
boolean exists(String objectUri)
- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Returns:
- true if the objectUri already exists for the document
-
create
void create(TypedValue typedValue) throws InvalidSPDXAnalysisException
Create a new object with objectUri, type and version from the typedValue- Parameters:
typedValue
- TypedValue of the item to create- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getPropertyValueDescriptors
List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Returns:
- Property descriptors for all properties having a value for a given objectUri within a document
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
setValue
void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyvalue
- value to set- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getValue
Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Returns:
- the single value associated with the objectUri, propertyDescriptor and document
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getNextId
String getNextId(IModelStore.IdType idType) throws InvalidSPDXAnalysisException
Generate a unique ID within the model store - Note: for a full URI, the id should be prepended with a URI prefix- Parameters:
idType
- Type of ID- Returns:
- next available unique ID for the specific idType - Note: for a full URI, the id should be prepended with a URI prefix
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
removeProperty
void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Removes a property from the document for the given ID if the property exists. Does not raise any exception if the propertyDescriptor does not exist- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getAllItems
Stream<TypedValue> getAllItems(@Nullable String nameSpace, @Nullable String typeFilter) throws InvalidSPDXAnalysisException
- Parameters:
nameSpace
- Optional SPDX namespace to filter items bytypeFilter
- Optional parameter to specify the type of objects to be retrieved- Returns:
- Stream of all items store within the document
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
enterCriticalSection
IModelStore.IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException
Enter a critical section. leaveCriticalSection must be called.- Parameters:
readLockRequested
- true implies a read lock, false implies write lock.- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
leaveCriticalSection
void leaveCriticalSection(IModelStore.IModelStoreLock lock)
Leave a critical section. Releases the lock form the matching enterCriticalSection
-
removeValueFromCollection
boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Removes a value from a collection of values associated with a property- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyvalue
- Value to be removed- Returns:
- true if the value was removed
- Throws:
InvalidSPDXAnalysisException
-
collectionSize
int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Returns:
- size of a collection associated with a property. 0 if the property does not exist.
- Throws:
InvalidSPDXAnalysisException
-
collectionContains
boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyvalue
- value to check for contains- Returns:
- true if the collection associated with a property contains the value
- Throws:
InvalidSPDXAnalysisException
-
clearValueCollection
void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
addValueToCollection
boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Adds a value to a property collection creating the propertyDescriptor if it does not exist- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyvalue
- value to add- Returns:
- true if the collection was modified
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
listValues
Iterator<Object> listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Returns:
- Iterator over the list of values associated with the objectUri, propertyDescriptor and document
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
isCollectionMembersAssignableTo
boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyclazz
- Class to test compatibility with- Returns:
- true if all members of a collection associated with the objectUri and propertyDescriptor can be assigned to the clazz
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
isPropertyValueAssignableTo
boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the propertyclazz
- Class to test compatibility withspecVersion
- version of the SPDX to check against- Returns:
- true if the value associated with the objectUri and propertyDescriptor can be assigned to the clazz
- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
isCollectionProperty
boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Returns:
- true if the propertyDescriptor represents multiple values
- Throws:
InvalidSPDXAnalysisException
-
getIdType
IModelStore.IdType getIdType(String objectUri)
- Parameters:
objectUri
- URI for the object or the anon. ID- Returns:
- The type of ID based on the string format
-
getCaseSensisitiveId
@Deprecated default Optional<String> getCaseSensisitiveId(String nameSpace, String caseInsensisitiveId)
Deprecated.As of release 1.0, replaced bygetCaseSensitiveId(String, String)
Alias for getCaseSensitiveId- Parameters:
nameSpace
- the nameSpace used for the ID - the URI is formed by the nameSpace + "#" + caseInsensisitiveIdcaseInsensisitiveId
- ID - case will be ignored- Returns:
- the case-sensitive ID if it exists
-
getCaseSensitiveId
default Optional<String> getCaseSensitiveId(String nameSpace, String caseInsensitiveId)
In SPDX 2.2 license refs are allowed to be matched case-insensitive. This function will return the case-sensitive ID (e.g. if you have LicenseRef-ABC, calling this function with licenseref-abc will return LicenseRef-ABC- Parameters:
nameSpace
- the nameSpace used for the ID - the URI is formed by the nameSpace + "#" + caseInsensitiveIdcaseInsensitiveId
- ID - case will be ignored- Returns:
- the case-sensitive ID if it exists
-
getTypedValue
Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAnalysisException
- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Returns:
- type TypedValue containing the type of the ModelObject related to the ID
- Throws:
InvalidSPDXAnalysisException
-
delete
void delete(String objectUri) throws InvalidSPDXAnalysisException
Deletes an item from the document- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
isAnon
boolean isAnon(String objectUri)
- Parameters:
objectUri
- ID or URI for an item- Returns:
- true if the ID is anonymous
-
-