Package org.spdx.core
Class ModelObjectHelper
- java.lang.Object
-
- org.spdx.core.ModelObjectHelper
-
public class ModelObjectHelper extends Object
A set of static methods to help with common ModelObject functions- Author:
- Gary O'Neall
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddValueToCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, Object value, IModelCopyManager copyManager, String idPrefix)Add a value to a collection of values associated with a property.static voidclearValueCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor)Clears a collection of values associated with a property creating the property if it does not existstatic Optional<Object>getObjectPropertyValue(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, IModelCopyManager copyManager, String specVersion, Class<?> type, String idPrefix)Get an object value for a propertystatic booleanimplementsIndividualUriValue(Class<?> clazz)static Class<?>modelClassToStoredClass(Class<?> clazz)Convert the class to the appropriate stored classstatic ObjectmodelObjectToStoredObject(Object value, IModelStore modelStore, IModelCopyManager copyManager, String idPrefix)Converts a model object to the object to be storedstatic Optional<Object>optionalStoredObjectToModelObject(Optional<Object> value, IModelStore modelStore, IModelCopyManager copyManager, String specVersion, Class<?> type, String idPrefix)Converts any typed value or IndividualValue objects to a ModelObject, returning an existing ModelObject if it exists or creates a new ModelObjectstatic voidremoveProperty(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor)Removes a property and its value from the model store if it existsstatic voidremovePropertyValueFromCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, Object value)Remove a property value from a collectionstatic voidreplacePropertyValueCollection(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, Collection<?> values, IModelCopyManager copyManager, String idPrefix)Replace the entire value collection for a property.static voidsetPropertyValue(IModelStore modelStore, String objectUri, PropertyDescriptor propertyDescriptor, Object value, IModelCopyManager copyManager, String idPrefix)Set a property value for a property descriptor, creating the property if necessarystatic ObjectstoredObjectToModelObject(Object value, IModelStore modelStore, IModelCopyManager copyManager, String specVersion, Class<?> type, String idPrefix)Converts any typed value or individual value objects to a ModelObject, returning an existing ModelObject if it exists or creates a new ModelObjectstatic List<String>verifyCollection(Collection<? extends CoreModelObject> collection, String warningPrefix, Set<String> verifiedIds, String specVersion)Verifies all elements in a collection
-
-
-
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 objectobjectUri- the Object URI or anonymous IDpropertyDescriptor- property descriptor for the propertycopyManager- if non null, any ModelObject property value not stored in the modelStore under the stDocumentUri will be copied to make it availablespecVersion- version of the SPDX spec the object complies withtype- optional type hint - used for individuals where the type may be ambiguousidPrefix- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- Descriptor for the property associated with this objectvalue- Value to associate with the propertycopyManager- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- Descriptor for the propertyvalue- to addcopyManager- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- Descriptor for the propertyvalues- collection of new propertiescopyManager- 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 propertiesobjectUri- URI or anonymous ID for the objectpropertyDescriptor- descriptor for the propertyvalue- 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 TypedValuemodelStore- ModelStore to use in fetching or creatingcopyManager- if not null, copy any referenced ID's outside of this document/model storespecVersion- version of the SPDX spec the object complies withtype- optional type hint - used for individuals where the type may be ambiguousidPrefix- 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 TypedValuemodelStore- ModelStore to use in fetching or creatingcopyManager- if not null, copy any referenced ID's outside of this document/model storeidPrefix- 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 TypedValuemodelStore- ModelStore to use in fetching or creatingcopyManager- if not null, copy any referenced ID's outside of this document/model storespecVersion- version of the SPDX spec the object complies withtype- optional type hint - used for individuals where the type may be ambiguousidPrefix- 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 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
-
-