Class CoreModelObject
- java.lang.Object
-
- org.spdx.core.CoreModelObject
-
public abstract class CoreModelObject extends Object
Superclass for all SPDX model objectsProvides the primary interface to the storage class that access and stores the data for the model objects.
This class includes several helper methods to manage the storage and retrieval of properties.
Each model object is in itself stateless. All state is maintained in the Model Store.
The concrete classes are expected to implement getters for the model class properties which translate into calls to the getTYPEPropertyValue where TYPE is the type of value to be returned and the property descriptor is passed as a parameter.
There are 2 methods of setting values:
- Call the setPropertyValue, clearValueCollection or addValueToCollection methods. This will call the modelStore and store the value immediately.
- Gather a list of updates by calling the updatePropertyValue, updateClearValueList, or updateAddPropertyValue
methods. These methods return a ModelUpdate which can be applied later by calling the
apply()
method. A convenience methodWrite.applyUpdatesInOneTransaction
will perform all updates within a single transaction. This method may result in higher performance updates for some Model Store implementations. Note that none of the updates will be applied until the storage manager update method is invoked.
Property values are restricted to the following types:
- String - Java Strings
- Boolean - Java Boolean or primitive boolean types
- CoreModelObject - A concrete subclass of this type
- Collection<T> - A Collection of type T where T is one of the supported non-collection types
This class also handles the conversion of a CoreModelObject to and from a TypeValue for storage in the ModelStore.
- Author:
- Gary O'Neall
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CoreModelObject.CoreModelObjectBuilder
Base builder class for all model objects
-
Field Summary
Fields Modifier and Type Field Description protected IModelCopyManager
copyManager
If non-null, a reference made to a model object stored in a different modelStore and/or document will be copied to this modelStore and documentUriprotected String
idPrefix
protected IModelStore
modelStore
protected String
objectUri
protected String
specVersion
protected boolean
strict
if true, checks input values for setters to verify valid SPDX inputs
-
Constructor Summary
Constructors Modifier Constructor Description protected
CoreModelObject(String specVersion)
Create a new Model Object using an Anonymous ID with the default store and default document URIprotected
CoreModelObject(String objectUri, String specVersion)
Open or create a model object with the default storeprotected
CoreModelObject(CoreModelObject.CoreModelObjectBuilder builder, String specVersion)
protected
CoreModelObject(IModelStore modelStore, String objectUri, IModelCopyManager copyManager, boolean create, String specVersion, String idPrefix)
Creates a new model object
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract List<String>
_verify(Set<String> verifiedElementIds, String specVersion, List<IndividualUriValue> profiles)
Implementation of the specific verifications for this model objectvoid
addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value)
Add a value to a collection of values associated with a property.void
clearValueCollection(PropertyDescriptor propertyDescriptor)
Clears a collection of values associated with a propertyCoreModelObject
clone(IModelStore modelStore)
Clone a new object using a different model storevoid
copyFrom(CoreModelObject source)
Copy all the properties from the source objectIModelStore.IModelStoreLock
enterCriticalSection(boolean readLockRequested)
Enter a critical section.boolean
equals(Object o)
boolean
equivalent(CoreModelObject compare)
boolean
equivalent(CoreModelObject compare, boolean ignoreRelatedElements)
Optional<Boolean>
getBooleanPropertyValue(PropertyDescriptor propertyDescriptor)
IModelCopyManager
getCopyManager()
Optional<Double>
getDoublePropertyValue(PropertyDescriptor propertyDescriptor)
Optional<Enum<?>>
getEnumPropertyValue(PropertyDescriptor propertyDescriptor)
String
getId()
String
getIdPrefix()
Optional<Integer>
getIntegerPropertyValue(PropertyDescriptor propertyDescriptor)
IModelStore
getModelStore()
Optional<Object>
getObjectPropertyValue(PropertyDescriptor propertyDescriptor)
Get an object value for a propertyOptional<Object>
getObjectPropertyValue(PropertyDescriptor propertyDescriptor, Class<?> type)
Get an object value for a propertyModelCollection<?>
getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class<?> type)
ModelSet<?>
getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class<?> type)
String
getObjectUri()
List<PropertyDescriptor>
getPropertyValueDescriptors()
String
getSpecVersion()
Collection<String>
getStringCollection(PropertyDescriptor propertyDescriptor)
Optional<String>
getStringPropertyValue(PropertyDescriptor propertyDescriptor)
abstract String
getType()
int
hashCode()
boolean
isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class<?> clazz)
protected boolean
isEquivalentToNull(Object propertyValue, PropertyDescriptor descriptor)
boolean
isExternal()
NOTE: Subclasses the represent model object not stored in the modelStore should override this method and set it to trueprotected abstract boolean
isNoAssertion(Object propertyValue)
abstract boolean
isRelatedElement(PropertyDescriptor propertyDescriptor)
boolean
isStrict()
void
leaveCriticalSection(IModelStore.IModelStoreLock lock)
Leave a critical section.void
removeProperty(PropertyDescriptor propertyDescriptor)
Removes a property and its value from the model store if it existsvoid
removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value)
Remove a property value from a collectionvoid
setCopyManager(IModelCopyManager copyManager)
Set the copy managervoid
setIdPrefix(String idPrefix)
Sets the idPrefixvoid
setPropertyValue(PropertyDescriptor propertyDescriptor, Object value)
Set a property value for a property descriptor, creating the property if necessaryvoid
setStrict(boolean strict)
String
toString()
TypedValue
toTypedValue()
IModelStore.ModelUpdate
updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied, adds a value to a collection of values associated with a property.IModelStore.ModelUpdate
updateClearValueCollection(PropertyDescriptor propertyDescriptor)
Create an update when, when applied by the ModelStore, clears a collection of values associated with a propertyIModelStore.ModelUpdate
updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessaryIModelStore.ModelUpdate
updateRemoveProperty(PropertyDescriptor propertyDescriptor)
Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it existsIModelStore.ModelUpdate
updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied, removes a property value from a collectionList<String>
verify()
List<String>
verify(String specVersion)
abstract List<String>
verify(Set<String> verifiedIds, String specVersion)
List<String>
verifyCollection(Collection<? extends CoreModelObject> collection, String warningPrefix, Set<String> verifiedIds, String specVersion)
Verifies all elements in a collection
-
-
-
Field Detail
-
modelStore
protected IModelStore modelStore
-
objectUri
protected String objectUri
-
specVersion
protected String specVersion
-
idPrefix
protected String idPrefix
-
copyManager
protected IModelCopyManager copyManager
If non-null, a reference made to a model object stored in a different modelStore and/or document will be copied to this modelStore and documentUri
-
strict
protected boolean strict
if true, checks input values for setters to verify valid SPDX inputs
-
-
Constructor Detail
-
CoreModelObject
protected CoreModelObject(String specVersion) throws InvalidSPDXAnalysisException
Create a new Model Object using an Anonymous ID with the default store and default document URI- Parameters:
specVersion
- version of the SPDX spec the object complies with- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
CoreModelObject
protected CoreModelObject(String objectUri, String specVersion) throws InvalidSPDXAnalysisException
Open or create a model object with the default store- Parameters:
objectUri
- Anonymous ID or URI for the model objectspecVersion
- Version of the SPDX spec the object complies with- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
CoreModelObject
protected CoreModelObject(IModelStore modelStore, String objectUri, @Nullable IModelCopyManager copyManager, boolean create, String specVersion, String idPrefix) throws InvalidSPDXAnalysisException
Creates a new model object- Parameters:
modelStore
- Storage for the model objects - Must support model V3 classesobjectUri
- Anonymous ID or URI for the model objectcopyManager
- if supplied, model objects will be implicitly copied into this model store and document URI when referenced by setting methodscreate
- if true, the object will be created in the store if it is not already presentspecVersion
- version of the SPDX spec the object complies withidPrefix
- prefix to be used when generating new SPDX IDs- Throws:
InvalidSPDXAnalysisException
- invalid parameters or duplicate objectUri
-
CoreModelObject
protected CoreModelObject(CoreModelObject.CoreModelObjectBuilder builder, String specVersion) throws InvalidSPDXAnalysisException
- Parameters:
builder
- base builder to create the CoreModelObject fromspecVersion
- version of the SPDX spec the object complies with- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
-
Method Detail
-
isExternal
public boolean isExternal()
NOTE: Subclasses the represent model object not stored in the modelStore should override this method and set it to true- Returns:
- true if this model object is external to the store
-
getType
public abstract String getType()
- Returns:
- The class name for this object. Class names are defined in the constants file
-
enterCriticalSection
public 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 any SPDX related exception
-
leaveCriticalSection
public void leaveCriticalSection(IModelStore.IModelStoreLock lock)
Leave a critical section. Releases the lock form the matching enterCriticalSection
-
_verify
public abstract List<String> _verify(Set<String> verifiedElementIds, String specVersion, List<IndividualUriValue> profiles)
Implementation of the specific verifications for this model object- Parameters:
specVersion
- Version of the SPDX spec to verify againstverifiedElementIds
- list of all Element Id's which have already been verified - prevents infinite recursionprofiles
- List of profiles to validate against- Returns:
- Any verification errors or warnings associated with this object
-
verify
public abstract List<String> verify(Set<String> verifiedIds, String specVersion)
- Parameters:
specVersion
- Version of the SPDX spec to verify againstverifiedIds
- verifiedIds list of all Id's which have already been verified - prevents infinite recursion- Returns:
- Any verification errors or warnings associated with this object
-
verify
public List<String> verify(String specVersion)
- Parameters:
specVersion
- Version of the SPDX spec to verify against- Returns:
- Any verification errors or warnings associated with this object
-
verify
public List<String> verify()
- Returns:
- Any verification errors or warnings associated with this object
-
verifyCollection
public List<String> verifyCollection(Collection<? extends CoreModelObject> collection, String warningPrefix, Set<String> verifiedIds, String specVersion)
Verifies all elements in a collection- Parameters:
specVersion
- version of the SPDX specification to verify againstcollection
- collection to be verifiesverifiedIds
- verifiedIds list of all Id's which have already been verified - prevents infinite recursionwarningPrefix
- String to prefix any warning messages
-
getObjectUri
public String getObjectUri()
- Returns:
- the Object URI or anonymous ID
-
getModelStore
public IModelStore getModelStore()
- Returns:
- the model store for this object
-
isStrict
public boolean isStrict()
- Returns:
- if strict input checking is enabled
-
setStrict
public void setStrict(boolean strict)
- Parameters:
strict
- if true, inputs will be validated against the SPDX spec
-
getPropertyValueDescriptors
public List<PropertyDescriptor> getPropertyValueDescriptors() throws InvalidSPDXAnalysisException
- Returns:
- all names of property descriptors currently associated with this object
- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
getObjectPropertyValue
public Optional<Object> getObjectPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Get an object value for a property- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- value associated with a property
- Throws:
InvalidSPDXAnalysisException
-
getObjectPropertyValue
public Optional<Object> getObjectPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Class<?> type) throws InvalidSPDXAnalysisException
Get an object value for a property- Parameters:
propertyDescriptor
- Descriptor for the propertytype
- optional type hint - used for individuals where the type may be ambiguous- Returns:
- value associated with a property
- Throws:
InvalidSPDXAnalysisException
-
setPropertyValue
public void setPropertyValue(PropertyDescriptor propertyDescriptor, @Nullable Object value) throws InvalidSPDXAnalysisException
Set a property value for a property descriptor, creating the property if necessary- Parameters:
propertyDescriptor
- Descriptor for the property associated with this objectvalue
- Value to associate with the property- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
updatePropertyValue
public IModelStore.ModelUpdate updatePropertyValue(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied by the ModelStore, sets a property value for a property descriptor, creating the property if necessary- Parameters:
propertyDescriptor
- Descriptor for the property associated with this objectvalue
- Value to associate with the property- Returns:
- an update which can be applied by invoking the apply method
-
getStringPropertyValue
public Optional<String> getStringPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for a property- Returns:
- the Optional String value associated with a property, null if no value is present
- Throws:
SpdxInvalidTypeException
- on any SPDX related exceptionInvalidSPDXAnalysisException
-
getIntegerPropertyValue
public Optional<Integer> getIntegerPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for a property- Returns:
- the Optional Integer value associated with a property, null if no value is present
- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
getDoublePropertyValue
public Optional<Double> getDoublePropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for a property- Returns:
- the Optional Double value associated with a property, null if no value is present
- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
getEnumPropertyValue
public Optional<Enum<?>> getEnumPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- descriptor for the property- Returns:
- an enumeration value for the property
- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
getBooleanPropertyValue
public Optional<Boolean> getBooleanPropertyValue(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- the Optional Boolean value for a property
- Throws:
SpdxInvalidTypeException
- if the stored object is not a Boolean typeInvalidSPDXAnalysisException
-
removeProperty
public void removeProperty(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Removes a property and its value from the model store if it exists- Parameters:
propertyDescriptor
- Descriptor for the property associated with this object to be removed- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
updateRemoveProperty
public IModelStore.ModelUpdate updateRemoveProperty(PropertyDescriptor propertyDescriptor)
Create an update when, when applied by the ModelStore, removes a property and its value from the model store if it exists- Parameters:
propertyDescriptor
- Descriptor for the property associated with this object to be removed- Returns:
- an update which can be applied by invoking the apply method
-
clearValueCollection
public void clearValueCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
Clears a collection of values associated with a property- Parameters:
propertyDescriptor
- Descriptor for the property- Throws:
InvalidSPDXAnalysisException
-
updateClearValueCollection
public IModelStore.ModelUpdate updateClearValueCollection(PropertyDescriptor propertyDescriptor)
Create an update when, when applied by the ModelStore, clears a collection of values associated with a property- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- an update which can be applied by invoking the apply method
-
addPropertyValueToCollection
public void addPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Add a value to a collection of values associated with a property. If a value is a CoreModelObject and does not belong to the document, it will be copied into the object store- Parameters:
propertyDescriptor
- Descriptor for the propertyvalue
- to add- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
updateAddPropertyValueToCollection
public IModelStore.ModelUpdate updateAddPropertyValueToCollection(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied, adds a value to a collection of values associated with a property. If a value is a CoreModelObject and does not belong to the document, it will be copied into the object store- Parameters:
propertyDescriptor
- Descriptor for the propertyvalue
- to add- Returns:
- an update which can be applied by invoking the apply method
-
removePropertyValueFromCollection
public void removePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value) throws InvalidSPDXAnalysisException
Remove a property value from a collection- Parameters:
propertyDescriptor
- Descriptor for the propertyvalue
- Value to be removed- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
updateRemovePropertyValueFromCollection
public IModelStore.ModelUpdate updateRemovePropertyValueFromCollection(PropertyDescriptor propertyDescriptor, Object value)
Create an update when, when applied, removes a property value from a collection- Parameters:
propertyDescriptor
- descriptor for the propertyvalue
- Value to be removed- Returns:
- an update which can be applied by invoking the apply method
-
getObjectPropertyValueSet
public ModelSet<?> getObjectPropertyValueSet(PropertyDescriptor propertyDescriptor, Class<?> type) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- Set of values associated with a property
- Throws:
InvalidSPDXAnalysisException
-
getObjectPropertyValueCollection
public ModelCollection<?> getObjectPropertyValueCollection(PropertyDescriptor propertyDescriptor, Class<?> type) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- Collection of values associated with a property
- Throws:
InvalidSPDXAnalysisException
-
getStringCollection
public Collection<String> getStringCollection(PropertyDescriptor propertyDescriptor) throws InvalidSPDXAnalysisException
- Parameters:
propertyDescriptor
- Descriptor for property- Returns:
- Collection of Strings associated with the property
- Throws:
SpdxInvalidTypeException
- on any SPDX related exceptionInvalidSPDXAnalysisException
-
isCollectionMembersAssignableTo
public boolean isCollectionMembersAssignableTo(PropertyDescriptor propertyDescriptor, Class<?> clazz) throws InvalidSPDXAnalysisException
- Throws:
InvalidSPDXAnalysisException
-
equivalent
public boolean equivalent(CoreModelObject compare) throws InvalidSPDXAnalysisException
- Parameters:
compare
- model object to compare this model object to- Returns:
- true if all the properties have the same or equivalent values
- Throws:
InvalidSPDXAnalysisException
-
equivalent
public boolean equivalent(CoreModelObject compare, boolean ignoreRelatedElements) throws InvalidSPDXAnalysisException
- Parameters:
compare
- model object to compare this model object toignoreRelatedElements
- if true, do not compare properties relatedSpdxElement - used to prevent infinite recursion- Returns:
- true if all the properties have the same or equivalent values
- Throws:
InvalidSPDXAnalysisException
-
isEquivalentToNull
protected boolean isEquivalentToNull(Object propertyValue, PropertyDescriptor descriptor)
- Parameters:
propertyValue
- value to check- Returns:
- true if the value is equivalent to null
-
isRelatedElement
public abstract boolean isRelatedElement(PropertyDescriptor propertyDescriptor)
- Parameters:
propertyDescriptor
- property descriptor for the object in question- Returns:
- true if the object is "to" part of a relationship
-
isNoAssertion
protected abstract boolean isNoAssertion(Object propertyValue)
- Parameters:
propertyValue
- value to check- Returns:
- true if the propertyValue is a no assertion value
-
clone
public CoreModelObject clone(IModelStore modelStore)
Clone a new object using a different model store- Parameters:
modelStore
- model store to store the copy in- Returns:
- a copy of this model object
-
copyFrom
public void copyFrom(CoreModelObject source) throws InvalidSPDXAnalysisException
Copy all the properties from the source object- Parameters:
source
- source model object- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
setCopyManager
public void setCopyManager(IModelCopyManager copyManager)
Set the copy manager- Parameters:
copyManager
- copy manager to set
-
getCopyManager
public IModelCopyManager getCopyManager()
- Returns:
- the copy manager - value may be null if copies are not allowed
-
toTypedValue
public TypedValue toTypedValue() throws InvalidSPDXAnalysisException
- Returns:
- a typed value representation of this object suitable for storage in the model store
- Throws:
InvalidSPDXAnalysisException
- on any SPDX related exception
-
getSpecVersion
public String getSpecVersion() throws InvalidSPDXAnalysisException
- Returns:
- the version of the SPDX specification this object complies with
- Throws:
InvalidSPDXAnalysisException
- - this is here just for compatibility with overridden methods
-
getIdPrefix
@Nullable public String getIdPrefix()
- Returns:
- prefix to be used when generating new IDs
-
setIdPrefix
public void setIdPrefix(@Nullable String idPrefix)
Sets the idPrefix- Parameters:
idPrefix
- prefix to be used when generating new IDs
-
getId
public String getId()
- Returns:
- if the objectUri is prefixed by the idPrefix, returns just the id portion of the objectUri, otherwise returns the objectUri
-
-