Package org.spdx.storage
Class NullModelStore
- java.lang.Object
-
- org.spdx.storage.NullModelStore
-
- All Implemented Interfaces:
AutoCloseable
,IModelStore
public class NullModelStore extends Object implements IModelStore
Null model store to be used with constants and individuals- Author:
- Gary O'Neall
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.spdx.storage.IModelStore
IModelStore.IdType, IModelStore.IModelStoreLock, IModelStore.ModelUpdate
-
-
Constructor Summary
Constructors Constructor Description NullModelStore()
-
Method Summary
All Methods Instance Methods Concrete 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 existvoid
close()
boolean
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)
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.spdx.storage.IModelStore
getCaseSensisitiveId
-
-
-
-
Method Detail
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
exists
public boolean exists(String objectUri)
- Specified by:
exists
in interfaceIModelStore
- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Returns:
- true if the objectUri already exists for the document
-
create
public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Create a new object with objectUri, type and version from the typedValue- Specified by:
create
in interfaceIModelStore
- Parameters:
typedValue
- TypedValue of the item to create- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getPropertyValueDescriptors
public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException
- Specified by:
getPropertyValueDescriptors
in interfaceIModelStore
- 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
public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Sets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist- Specified by:
setValue
in interfaceIModelStore
- 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
public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Specified by:
getValue
in interfaceIModelStore
- 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
public String getNextId(IModelStore.IdType idType) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Generate a unique ID within the model store - Note: for a full URI, the id should be prepended with a URI prefix- Specified by:
getNextId
in interfaceIModelStore
- 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
public void removeProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
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- Specified by:
removeProperty
in interfaceIModelStore
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
getAllItems
public Stream<TypedValue> getAllItems(String nameSpace, String typeFilter) throws InvalidSPDXAnalysisException
- Specified by:
getAllItems
in interfaceIModelStore
- 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
public IModelStore.IModelStoreLock enterCriticalSection(boolean readLockRequested) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Enter a critical section. leaveCriticalSection must be called.- Specified by:
enterCriticalSection
in interfaceIModelStore
- Parameters:
readLockRequested
- true implies a read lock, false implies write lock.- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
leaveCriticalSection
public void leaveCriticalSection(IModelStore.IModelStoreLock lock)
Description copied from interface:IModelStore
Leave a critical section. Releases the lock form the matching enterCriticalSection- Specified by:
leaveCriticalSection
in interfaceIModelStore
-
removeValueFromCollection
public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Removes a value from a collection of values associated with a property- Specified by:
removeValueFromCollection
in interfaceIModelStore
- 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
public int collectionSize(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Specified by:
collectionSize
in interfaceIModelStore
- 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
public boolean collectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
- Specified by:
collectionContains
in interfaceIModelStore
- 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
public void clearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist- Specified by:
clearValueCollection
in interfaceIModelStore
- Parameters:
objectUri
- unique URI within the SPDX model store for the objectspropertyDescriptor
- descriptor for the property- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
addValueToCollection
public boolean addValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Adds a value to a property collection creating the propertyDescriptor if it does not exist- Specified by:
addValueToCollection
in interfaceIModelStore
- 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
public Iterator<Object> listValues(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Specified by:
listValues
in interfaceIModelStore
- 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
public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz) throws InvalidSPDXAnalysisException
- Specified by:
isCollectionMembersAssignableTo
in interfaceIModelStore
- 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
public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion) throws InvalidSPDXAnalysisException
- Specified by:
isPropertyValueAssignableTo
in interfaceIModelStore
- 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
public boolean isCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Specified by:
isCollectionProperty
in interfaceIModelStore
- 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
public IModelStore.IdType getIdType(String objectUri)
- Specified by:
getIdType
in interfaceIModelStore
- Parameters:
objectUri
- URI for the object or the anon. ID- Returns:
- The type of ID based on the string format
-
getCaseSensitiveId
public Optional<String> getCaseSensitiveId(String nameSpace, String caseInsensitiveId)
Description copied from interface:IModelStore
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- Specified by:
getCaseSensitiveId
in interfaceIModelStore
- 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
public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAnalysisException
- Specified by:
getTypedValue
in interfaceIModelStore
- 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
public void delete(String objectUri) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStore
Deletes an item from the document- Specified by:
delete
in interfaceIModelStore
- Parameters:
objectUri
- unique URI within the SPDX model store for the objects- Throws:
InvalidSPDXAnalysisException
- on model store errors
-
isAnon
public boolean isAnon(String objectUri)
- Specified by:
isAnon
in interfaceIModelStore
- Parameters:
objectUri
- ID or URI for an item- Returns:
- true if the ID is anonymous
-
-