Package org.spdx.library.model.v2
Class ModelObjectV2
- java.lang.Object
-
- org.spdx.core.CoreModelObject
-
- org.spdx.library.model.v2.ModelObjectV2
-
- Direct Known Subclasses:
Annotation
,AnyLicenseInfo
,Checksum
,CompoundPointer
,CrossRef
,ExternalDocumentRef
,ExternalRef
,GenericModelObject
,LicenseException
,Relationship
,SinglePointer
,SpdxCreatorInformation
,SpdxElement
,SpdxPackageVerificationCode
public abstract class ModelObjectV2 extends org.spdx.core.CoreModelObject
Superclass for all SPDX spec version 2 model objects Provides 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 Document URI uniquely identifies the document containing the model object. The concrete classes are expected to implements 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 theapply()
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 - ModelObjectV2 - 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 ModelObjectV2 to and from a TypeValue for storage in the ModelStore.- Author:
- Gary O'Neall
-
-
Field Summary
Fields Modifier and Type Field Description static String
LATEST_SPDX_2_VERSION
-
Constructor Summary
Constructors Constructor Description ModelObjectV2()
ModelObjectV2(String id)
Open or create a model object with the default store and default document URIModelObjectV2(org.spdx.core.CoreModelObject.CoreModelObjectBuilder builder)
ModelObjectV2(org.spdx.storage.IModelStore modelStore, String documentUri, String identifier, org.spdx.core.IModelCopyManager copyManager, boolean create)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract List<String>
_verify(Set<String> verifiedElementIds, String specVersion)
Implementation of the specific verifications for this model objectList<String>
_verify(Set<String> verifiedElementIds, String specVersion, List<org.spdx.core.IndividualUriValue> profiles)
Annotation
createAnnotation(String annotator, AnnotationType annotationType, String date, String comment)
ByteOffsetPointer
createByteOffsetPointer(SpdxElement referencedElement, int offset)
Checksum
createChecksum(ChecksumAlgorithm algorithm, String value)
ConjunctiveLicenseSet
createConjunctiveLicenseSet(Collection<AnyLicenseInfo> members)
SpdxCreatorInformation
createCreationInfo(List<String> creators, String date)
CrossRef.CrossRefBuilder
createCrossRef(String url)
Create a CrossRef Builder with an Anonymous ID type using the same model store and document URIDisjunctiveLicenseSet
createDisjunctiveLicenseSet(Collection<AnyLicenseInfo> members)
ExternalDocumentRef
createExternalDocumentRef(String externalDocumentId, String externalDocumentUri, Checksum checksum)
ExternalRef
createExternalRef(ReferenceCategory category, ReferenceType referenceType, String locator, String comment)
ExtractedLicenseInfo
createExtractedLicense(String id, String text)
ConstructsExtractedLicenseInfo
with text set.LineCharPointer
createLineCharPointer(SpdxElement referencedElement, int lineNumber)
SpdxPackage.SpdxPackageBuilder
createPackage(String id, String name, AnyLicenseInfo concludedLicense, String copyrightText, AnyLicenseInfo licenseDeclared)
Create an SpdxPackageBuilder with all required fields for a filesAnalyzed=false using this objects model store and document URISpdxPackageVerificationCode
createPackageVerificationCode(String value, Collection<String> excludedFileNames)
Relationship
createRelationship(SpdxElement relatedElement, RelationshipType relationshipType, String comment)
SpdxFile.SpdxFileBuilder
createSpdxFile(String id, String name, AnyLicenseInfo concludedLicense, Collection<AnyLicenseInfo> seenLicense, String copyrightText, Checksum sha1)
Create an SpdxFileBuilder with all of the required properties - the build() method will build the fileSpdxSnippet.SpdxSnippetBuilder
createSpdxSnippet(String id, String name, AnyLicenseInfo concludedLicense, Collection<AnyLicenseInfo> seenLicense, String copyrightText, SpdxFile snippetFromFile, int startByte, int endByte)
Create an SpdxSnippetBuilder with all of the required properties - the build() method will build the fileStartEndPointer
createStartEndPointer(SinglePointer startPointer, SinglePointer endPointer)
boolean
equals(Object o)
Optional<AnyLicenseInfo>
getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor propertyDescriptor)
Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate licenseString
getDocumentUri()
protected Optional<SpdxElement>
getElementPropertyValue(org.spdx.storage.PropertyDescriptor propertyDescriptor)
Converts property values to an SpdxElement if possible - if NONE or NOASSERTION URI value, convert to the appropriate SpdxElementString
getId()
int
hashCode()
protected boolean
isEquivalentToNull(Object propertyValue, org.spdx.storage.PropertyDescriptor descriptor)
boolean
isNoAssertion(Object value)
boolean
isRelatedElement(org.spdx.storage.PropertyDescriptor propertyDescriptor)
String
toString()
org.spdx.core.TypedValue
toTypedValue()
List<String>
verify(Set<String> verifiedIElementds, String specVersion)
-
Methods inherited from class org.spdx.core.CoreModelObject
addPropertyValueToCollection, clearValueCollection, clone, copyFrom, enterCriticalSection, equivalent, equivalent, getBooleanPropertyValue, getCopyManager, getDoublePropertyValue, getEnumPropertyValue, getIdPrefix, getIntegerPropertyValue, getModelStore, getObjectPropertyValue, getObjectPropertyValue, getObjectPropertyValueCollection, getObjectPropertyValueSet, getObjectUri, getPropertyValueDescriptors, getSpecVersion, getStringCollection, getStringPropertyValue, getType, isCollectionMembersAssignableTo, isExternal, isStrict, leaveCriticalSection, removeProperty, removePropertyValueFromCollection, setCopyManager, setIdPrefix, setPropertyValue, setStrict, updateAddPropertyValueToCollection, updateClearValueCollection, updatePropertyValue, updateRemoveProperty, updateRemovePropertyValueFromCollection, verify, verify, verifyCollection
-
-
-
-
Field Detail
-
LATEST_SPDX_2_VERSION
public static final String LATEST_SPDX_2_VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ModelObjectV2
public ModelObjectV2() throws org.spdx.core.InvalidSPDXAnalysisException
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
ModelObjectV2
public ModelObjectV2(String id) throws org.spdx.core.InvalidSPDXAnalysisException
Open or create a model object with the default store and default document URI- Parameters:
id
- ID for this object - must be unique within the SPDX document- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
ModelObjectV2
public ModelObjectV2(org.spdx.storage.IModelStore modelStore, String documentUri, String identifier, @Nullable org.spdx.core.IModelCopyManager copyManager, boolean create) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
modelStore
- Storage for the model objectsdocumentUri
- SPDX Document URI for a document associated with this modelidentifier
- ID for this object - must be unique within the SPDX documentcopyManager
- - 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 present- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
ModelObjectV2
public ModelObjectV2(org.spdx.core.CoreModelObject.CoreModelObjectBuilder builder) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
builder
-- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
-
Method Detail
-
_verify
public List<String> _verify(Set<String> verifiedElementIds, String specVersion, List<org.spdx.core.IndividualUriValue> profiles)
- Specified by:
_verify
in classorg.spdx.core.CoreModelObject
-
_verify
protected abstract List<String> _verify(Set<String> verifiedElementIds, String specVersion)
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 recursion- Returns:
- Any verification errors or warnings associated with this object
-
verify
public List<String> verify(Set<String> verifiedIElementds, String specVersion)
- Specified by:
verify
in classorg.spdx.core.CoreModelObject
- Parameters:
specVersion
- Version of the SPDX spec to verify againstverifiedIElementds
- list of all element Id's which have already been verified - prevents infinite recursion- Returns:
- Any verification errors or warnings associated with this object
-
getDocumentUri
public String getDocumentUri()
- Returns:
- the Document URI for this object
-
getId
public String getId()
- Overrides:
getId
in classorg.spdx.core.CoreModelObject
- Returns:
- ID for the object
-
isRelatedElement
public boolean isRelatedElement(org.spdx.storage.PropertyDescriptor propertyDescriptor)
- Specified by:
isRelatedElement
in classorg.spdx.core.CoreModelObject
- Parameters:
propertyDescriptor
- property descriptor for the object in question- Returns:
- true if the object is "to" part of a relationship
-
getAnyLicenseInfoPropertyValue
public Optional<AnyLicenseInfo> getAnyLicenseInfoPropertyValue(org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
Converts property values to an AnyLicenseInfo if possible - if NONE or NOASSERTION URI value, convert to the appropriate license- Parameters:
propertyDescriptor
- descriptor for the property- Returns:
- AnyLicenseInfo license info for the property
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
getElementPropertyValue
protected Optional<SpdxElement> getElementPropertyValue(org.spdx.storage.PropertyDescriptor propertyDescriptor) throws org.spdx.core.InvalidSPDXAnalysisException
Converts property values to an SpdxElement if possible - if NONE or NOASSERTION URI value, convert to the appropriate SpdxElement- Parameters:
propertyDescriptor
- Descriptor for the property- Returns:
- SpdxElement stored
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classorg.spdx.core.CoreModelObject
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classorg.spdx.core.CoreModelObject
-
toTypedValue
public org.spdx.core.TypedValue toTypedValue() throws org.spdx.core.InvalidSPDXAnalysisException
- Overrides:
toTypedValue
in classorg.spdx.core.CoreModelObject
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
isNoAssertion
public boolean isNoAssertion(Object value)
- Specified by:
isNoAssertion
in classorg.spdx.core.CoreModelObject
-
createAnnotation
public Annotation createAnnotation(String annotator, AnnotationType annotationType, String date, String comment) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
annotator
- This field identifies the person, organization or tool that has commented on a file, package, or the entire document.annotationType
- This field describes the type of annotation. Annotations are usually created when someone reviews the file, and if this is the case the annotation type should be REVIEW. If the author wants to store extra information about one of the elements during creation, it is recommended to use the type of OTHER.date
- Identify when the comment was made. This is to be specified according to the combined date and time in the UTC format, as specified in the ISO 8601 standard.comment
-- Returns:
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createRelationship
public Relationship createRelationship(SpdxElement relatedElement, RelationshipType relationshipType, @Nullable String comment) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
relatedElement
- The SPDX Element that is relatedrelationshipType
- Type of relationship - See the specification for a description of the typescomment
- optional comment for the relationship- Returns:
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createChecksum
public Checksum createChecksum(ChecksumAlgorithm algorithm, String value) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
algorithm
- Checksum algorithmvalue
- Checksum value- Returns:
- Checksum using the same model store and document URI as this Model Object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createPackageVerificationCode
public SpdxPackageVerificationCode createPackageVerificationCode(String value, Collection<String> excludedFileNames) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
value
- Verification code calculated valueexcludedFileNames
- file names of files excluded from the verification code calculation- Returns:
- Package verification code using the same model store and document URI as this Model Object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createExternalDocumentRef
public ExternalDocumentRef createExternalDocumentRef(String externalDocumentId, String externalDocumentUri, Checksum checksum) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
externalDocumentUri
- Document URI for the external documentchecksum
- Checksum of the external DocumentexternalDocumentId
- ID to be used internally within this SPDX document- Returns:
- ExternalDocumentRef using the same model store and document URI as this Model Object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createCreationInfo
public SpdxCreatorInformation createCreationInfo(List<String> creators, String date) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
creators
- Creators Identify who (or what, in the case of a tool) created the SPDX file. If the SPDX file was created by an individual, indicate the person's name.date
- When the SPDX file was originally created. The date is to be specified according to combined date and time in UTC format as specified in ISO 8601 standard.- Returns:
- creationInfo using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createExternalRef
public ExternalRef createExternalRef(ReferenceCategory category, ReferenceType referenceType, String locator, @Nullable String comment) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
category
- Reference categoryreferenceType
- Reference typelocator
- Reference locatorcomment
- Optional comment- Returns:
- ExternalRef using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createSpdxFile
public SpdxFile.SpdxFileBuilder createSpdxFile(String id, String name, AnyLicenseInfo concludedLicense, Collection<AnyLicenseInfo> seenLicense, String copyrightText, Checksum sha1) throws org.spdx.core.InvalidSPDXAnalysisException
Create an SpdxFileBuilder with all of the required properties - the build() method will build the file- Parameters:
id
- - ID - must be an SPDX ID typename
- - File nameconcludedLicense
- license concludedseenLicense
- collection of seen licensescopyrightText
- Copyright textsha1
- Sha1 checksum- Returns:
- SPDX file using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createPackage
public SpdxPackage.SpdxPackageBuilder createPackage(String id, String name, AnyLicenseInfo concludedLicense, String copyrightText, AnyLicenseInfo licenseDeclared)
Create an SpdxPackageBuilder with all required fields for a filesAnalyzed=false using this objects model store and document URI- Parameters:
id
- - ID - must be an SPDX ID typename
- - File nameconcludedLicense
- license concludedcopyrightText
- Copyright textlicenseDeclared
- Declared license for the package- Returns:
- SpdxPackageBuilder with all required fields for a filesAnalyzed=false
-
createByteOffsetPointer
public ByteOffsetPointer createByteOffsetPointer(SpdxElement referencedElement, int offset) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
referencedElement
-offset
-- Returns:
- ByteOffsetPointer using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createLineCharPointer
public LineCharPointer createLineCharPointer(SpdxElement referencedElement, int lineNumber) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
referencedElement
-lineNumber
-- Returns:
- LineCharPointer using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createStartEndPointer
public StartEndPointer createStartEndPointer(SinglePointer startPointer, SinglePointer endPointer) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
startPointer
-endPointer
-- Returns:
- StartEndPointer using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createSpdxSnippet
public SpdxSnippet.SpdxSnippetBuilder createSpdxSnippet(String id, String name, AnyLicenseInfo concludedLicense, Collection<AnyLicenseInfo> seenLicense, String copyrightText, SpdxFile snippetFromFile, int startByte, int endByte) throws org.spdx.core.InvalidSPDXAnalysisException
Create an SpdxSnippetBuilder with all of the required properties - the build() method will build the file- Parameters:
id
- - ID - must be an SPDX ID typename
- - File nameconcludedLicense
- license concludedseenLicense
- collection of seen licensescopyrightText
- Copyright textsnippetFromFile
- File where the snippet is locatedstartByte
- first byte of the snippet in the fileendByte
- last byte of the snippet in the file- Returns:
- SPDX snippet using the same modelStore and documentUri as this object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createConjunctiveLicenseSet
public ConjunctiveLicenseSet createConjunctiveLicenseSet(Collection<AnyLicenseInfo> members) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
members
-- Returns:
- ConjunctiveLicenseSet with default model store and document URI initialized with members
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createDisjunctiveLicenseSet
public DisjunctiveLicenseSet createDisjunctiveLicenseSet(Collection<AnyLicenseInfo> members) throws org.spdx.core.InvalidSPDXAnalysisException
- Parameters:
members
-- Returns:
- DisjunctiveLicenseSet with default model store and document URI initialized with members
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createCrossRef
public CrossRef.CrossRefBuilder createCrossRef(String url) throws org.spdx.core.InvalidSPDXAnalysisException
Create a CrossRef Builder with an Anonymous ID type using the same model store and document URI- Parameters:
url
- URL for the cross reference- Returns:
- a CrossRefBuilder which you can call
build()
on to build the CrossRef - Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
createExtractedLicense
public ExtractedLicenseInfo createExtractedLicense(String id, String text) throws org.spdx.core.InvalidSPDXAnalysisException
ConstructsExtractedLicenseInfo
with text set.Note that object construction has side-effects relating to a document and modelStore, requiring document context. This may bind usage of
ExtractedLicenseInfo
instances to the document that they were created by!- Parameters:
id
- id that the text relates totext
- license text corresponding to the id- Returns:
- returns a constructed object
- Throws:
org.spdx.core.InvalidSPDXAnalysisException
-
toString
public String toString()
- Overrides:
toString
in classorg.spdx.core.CoreModelObject
-
isEquivalentToNull
protected boolean isEquivalentToNull(Object propertyValue, org.spdx.storage.PropertyDescriptor descriptor)
- Overrides:
isEquivalentToNull
in classorg.spdx.core.CoreModelObject
-
-