Class 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 the apply() method. A convenience method Write.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
    • 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 objects
        documentUri - SPDX Document URI for a document associated with this model
        identifier - ID for this object - must be unique within the SPDX document
        copyManager - - if supplied, model objects will be implicitly copied into this model store and document URI when referenced by setting methods
        create - - 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 class org.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 against
        verifiedElementIds - 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 class org.spdx.core.CoreModelObject
        Parameters:
        specVersion - Version of the SPDX spec to verify against
        verifiedIElementds - 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 class org.spdx.core.CoreModelObject
        Returns:
        ID for the object
      • isRelatedElement

        public boolean isRelatedElement​(org.spdx.storage.PropertyDescriptor propertyDescriptor)
        Specified by:
        isRelatedElement in class org.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 class org.spdx.core.CoreModelObject
      • equals

        public boolean equals​(Object o)
        Overrides:
        equals in class org.spdx.core.CoreModelObject
      • toTypedValue

        public org.spdx.core.TypedValue toTypedValue()
                                              throws org.spdx.core.InvalidSPDXAnalysisException
        Overrides:
        toTypedValue in class org.spdx.core.CoreModelObject
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • isNoAssertion

        public boolean isNoAssertion​(Object value)
        Specified by:
        isNoAssertion in class org.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 related
        relationshipType - Type of relationship - See the specification for a description of the types
        comment - 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 algorithm
        value - 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 value
        excludedFileNames - 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 document
        checksum - Checksum of the external Document
        externalDocumentId - 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 category
        referenceType - Reference type
        locator - Reference locator
        comment - 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 type
        name - - File name
        concludedLicense - license concluded
        seenLicense - collection of seen licenses
        copyrightText - Copyright text
        sha1 - 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 type
        name - - File name
        concludedLicense - license concluded
        copyrightText - Copyright text
        licenseDeclared - 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 type
        name - - File name
        concludedLicense - license concluded
        seenLicense - collection of seen licenses
        copyrightText - Copyright text
        snippetFromFile - File where the snippet is located
        startByte - first byte of the snippet in the file
        endByte - 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
        Constructs ExtractedLicenseInfo 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 to
        text - license text corresponding to the id
        Returns:
        returns a constructed object
        Throws:
        org.spdx.core.InvalidSPDXAnalysisException
      • toString

        public String toString()
        Overrides:
        toString in class org.spdx.core.CoreModelObject
      • isEquivalentToNull

        protected boolean isEquivalentToNull​(Object propertyValue,
                                             org.spdx.storage.PropertyDescriptor descriptor)
        Overrides:
        isEquivalentToNull in class org.spdx.core.CoreModelObject