Package org.spdx.core

Class ModelObjectHelper


  • public class ModelObjectHelper
    extends Object
    A set of static methods to help with common ModelObject functions
    Author:
    Gary O'Neall
    • Method Detail

      • getObjectPropertyValue

        public static Optional<Object> getObjectPropertyValue​(IModelStore modelStore,
                                                              String objectUri,
                                                              PropertyDescriptor propertyDescriptor,
                                                              IModelCopyManager copyManager,
                                                              String specVersion,
                                                              @Nullable
                                                              Class<?> type,
                                                              String idPrefix)
                                                       throws InvalidSPDXAnalysisException
        Get an object value for a property
        Parameters:
        modelStore - Model store for the object
        objectUri - the Object URI or anonymous ID
        propertyDescriptor - property descriptor for the property
        copyManager - if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available
        specVersion - version of the SPDX spec the object complies with
        type - optional type hint - used for individuals where the type may be ambiguous
        idPrefix - prefix to be used when generating new SPDX IDs
        Returns:
        value associated with a property
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • setPropertyValue

        public static void setPropertyValue​(IModelStore modelStore,
                                            String objectUri,
                                            PropertyDescriptor propertyDescriptor,
                                            @Nullable
                                            Object value,
                                            IModelCopyManager copyManager,
                                            String idPrefix)
                                     throws InvalidSPDXAnalysisException
        Set a property value for a property descriptor, creating the property if necessary
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - Descriptor for the property associated with this object
        value - Value to associate with the property
        copyManager - if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • removeProperty

        public static void removeProperty​(IModelStore modelStore,
                                          String objectUri,
                                          PropertyDescriptor propertyDescriptor)
                                   throws InvalidSPDXAnalysisException
        Removes a property and its value from the model store if it exists
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - Descriptor for the property associated with this object to be removed
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • clearValueCollection

        public static void clearValueCollection​(IModelStore modelStore,
                                                String objectUri,
                                                PropertyDescriptor propertyDescriptor)
                                         throws InvalidSPDXAnalysisException
        Clears a collection of values associated with a property creating the property if it does not exist
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - Descriptor for the property
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • addValueToCollection

        public static void addValueToCollection​(IModelStore modelStore,
                                                String objectUri,
                                                PropertyDescriptor propertyDescriptor,
                                                Object value,
                                                IModelCopyManager copyManager,
                                                String idPrefix)
                                         throws InvalidSPDXAnalysisException
        Add a value to a collection of values associated with a property. If a value is a ModelObject and does not belong to the document, it will be copied into the object store
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - Descriptor for the property
        value - to add
        copyManager - copyManager for any copying of properties
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • replacePropertyValueCollection

        public static void replacePropertyValueCollection​(IModelStore modelStore,
                                                          String objectUri,
                                                          PropertyDescriptor propertyDescriptor,
                                                          Collection<?> values,
                                                          IModelCopyManager copyManager,
                                                          String idPrefix)
                                                   throws InvalidSPDXAnalysisException
        Replace the entire value collection for a property. If a value is a ModelObject and does not belong to the document, it will be copied into the object store
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - Descriptor for the property
        values - collection of new properties
        copyManager - if non-null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it available
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • removePropertyValueFromCollection

        public static void removePropertyValueFromCollection​(IModelStore modelStore,
                                                             String objectUri,
                                                             PropertyDescriptor propertyDescriptor,
                                                             Object value)
                                                      throws InvalidSPDXAnalysisException
        Remove a property value from a collection
        Parameters:
        modelStore - Model store for the properties
        objectUri - URI or anonymous ID for the object
        propertyDescriptor - descriptor for the property
        value - Value to be removed
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • optionalStoredObjectToModelObject

        public static Optional<Object> optionalStoredObjectToModelObject​(Optional<Object> value,
                                                                         IModelStore modelStore,
                                                                         IModelCopyManager copyManager,
                                                                         String specVersion,
                                                                         @Nullable
                                                                         Class<?> type,
                                                                         String idPrefix)
                                                                  throws InvalidSPDXAnalysisException
        Converts any typed value or IndividualValue objects to a ModelObject, returning an existing ModelObject if it exists or creates a new ModelObject
        Parameters:
        value - Value which may be a TypedValue
        modelStore - ModelStore to use in fetching or creating
        copyManager - if not null, copy any referenced ID's outside of this document/model store
        specVersion - version of the SPDX spec the object complies with
        type - optional type hint - used for individuals where the type may be ambiguous
        idPrefix - Prefix to be used if any new object URI's are generated
        Returns:
        the object itself unless it is a TypedValue, in which case a ModelObject is returned
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • modelObjectToStoredObject

        public static Object modelObjectToStoredObject​(Object value,
                                                       IModelStore modelStore,
                                                       IModelCopyManager copyManager,
                                                       String idPrefix)
                                                throws InvalidSPDXAnalysisException
        Converts a model object to the object to be stored
        Parameters:
        value - Value which may be a TypedValue
        modelStore - ModelStore to use in fetching or creating
        copyManager - if not null, copy any referenced ID's outside of this document/model store
        idPrefix - Prefix to be used if any new object URI's are generated
        Returns:
        Model Object appropriate type
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • storedObjectToModelObject

        public static Object storedObjectToModelObject​(Object value,
                                                       IModelStore modelStore,
                                                       IModelCopyManager copyManager,
                                                       String specVersion,
                                                       @Nullable
                                                       Class<?> type,
                                                       String idPrefix)
                                                throws InvalidSPDXAnalysisException
        Converts any typed value or individual value objects to a ModelObject, returning an existing ModelObject if it exists or creates a new ModelObject
        Parameters:
        value - Value which may be a TypedValue
        modelStore - ModelStore to use in fetching or creating
        copyManager - if not null, copy any referenced ID's outside of this document/model store
        specVersion - version of the SPDX spec the object complies with
        type - optional type hint - used for individuals where the type may be ambiguous
        idPrefix - Prefix to be used if any new object URI's are generated
        Returns:
        the object itself unless it is a TypedValue, in which case a ModelObject is returned
        Throws:
        InvalidSPDXAnalysisException - on any SPDX related error
      • modelClassToStoredClass

        public static Class<?> modelClassToStoredClass​(Class<?> clazz)
        Convert the class to the appropriate stored class
        Parameters:
        clazz - Model class
        Returns:
        class compatible with stored classes
      • implementsIndividualUriValue

        public static boolean implementsIndividualUriValue​(Class<?> clazz)
        Parameters:
        clazz - class to check
        Returns:
        true if the clazz implements the IndividualUriValue interface
      • verifyCollection

        public static 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 against
        collection - collection to be verifies
        verifiedIds - verifiedIds list of all Id's which have already been verified - prevents infinite recursion
        warningPrefix - String to prefix any warning messages