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 booleanaddValueToCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value)Adds a value to a property collection creating the propertyDescriptor if it does not existvoidclearValueCollection(String objectUri, PropertyDescriptor propertyDescriptor)Sets the value collection for the property to an empty collection creating the propertyDescriptor if it does not existvoidclose()booleancollectionContains(String objectUri, PropertyDescriptor propertyDescriptor, Object value)intcollectionSize(String objectUri, PropertyDescriptor propertyDescriptor)voidcreate(TypedValue typedValue)Create a new object with objectUri, type and version from the typedValuevoiddelete(String objectUri)Deletes an item from the documentIModelStore.IModelStoreLockenterCriticalSection(boolean readLockRequested)Enter a critical section. leaveCriticalSection must be called.booleanexists(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.IdTypegetIdType(String objectUri)StringgetNextId(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)booleanisAnon(String objectUri)booleanisCollectionMembersAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz)booleanisCollectionProperty(String objectUri, PropertyDescriptor propertyDescriptor)booleanisPropertyValueAssignableTo(String objectUri, PropertyDescriptor propertyDescriptor, Class<?> clazz, String specVersion)voidleaveCriticalSection(IModelStore.IModelStoreLock lock)Leave a critical section.Iterator<Object>listValues(String objectUri, PropertyDescriptor propertyDescriptor)voidremoveProperty(String objectUri, PropertyDescriptor propertyDescriptor)Removes a property from the document for the given ID if the property exists.booleanremoveValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value)Removes a value from a collection of values associated with a propertyvoidsetValue(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:
closein interfaceAutoCloseable- Throws:
Exception
-
exists
public boolean exists(String objectUri)
- Specified by:
existsin 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:IModelStoreCreate a new object with objectUri, type and version from the typedValue- Specified by:
createin 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:
getPropertyValueDescriptorsin 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:IModelStoreSets a property value for a String or Boolean type of value creating the propertyDescriptor if it does not exist- Specified by:
setValuein 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:
getValuein 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:IModelStoreGenerate a unique ID within the model store - Note: for a full URI, the id should be prepended with a URI prefix- Specified by:
getNextIdin 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:IModelStoreRemoves 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:
removePropertyin 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:
getAllItemsin 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:IModelStoreEnter a critical section. leaveCriticalSection must be called.- Specified by:
enterCriticalSectionin 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:IModelStoreLeave a critical section. Releases the lock form the matching enterCriticalSection- Specified by:
leaveCriticalSectionin interfaceIModelStore
-
removeValueFromCollection
public boolean removeValueFromCollection(String objectUri, PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Description copied from interface:IModelStoreRemoves a value from a collection of values associated with a property- Specified by:
removeValueFromCollectionin 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:
collectionSizein 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:
collectionContainsin 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:IModelStoreSets the value collection for the property to an empty collection creating the propertyDescriptor if it does not exist- Specified by:
clearValueCollectionin 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:IModelStoreAdds a value to a property collection creating the propertyDescriptor if it does not exist- Specified by:
addValueToCollectionin 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:
listValuesin 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:
isCollectionMembersAssignableToin 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:
isPropertyValueAssignableToin 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:
isCollectionPropertyin 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:
getIdTypein 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:IModelStoreIn 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:
getCaseSensitiveIdin 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:
getTypedValuein 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:IModelStoreDeletes an item from the document- Specified by:
deletein 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:
isAnonin interfaceIModelStore- Parameters:
objectUri- ID or URI for an item- Returns:
- true if the ID is anonymous
-
-