Class Resources
- java.lang.Object
-
- com.sodius.oslc.core.model.Resources
-
public class Resources extends Object
Provides helper methods to handle resources.- Since:
- 3.7.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends IExtendedResource>
Tclone(T resource)
Creates and returns a clone of this resource.static Object
getExtendedProperty(IExtendedResource resource, String propertyDefinition)
Returns the value in extended properties associated to the property definition, if any.static Object
getExtendedProperty(IExtendedResource resource, URI propertyDefinition)
Returns the value in extended properties associated to the property definition, if any.static Object
getExtendedProperty(IExtendedResource resource, QName qname)
Returns the value in extended properties associated to the property definition, if any.static void
setExtendedProperty(IExtendedResource resource, QName qname, Object value)
Changes the value in extended properties associated to the property definition.
-
-
-
Method Detail
-
getExtendedProperty
public static Object getExtendedProperty(IExtendedResource resource, QName qname)
Returns the value in extended properties associated to the property definition, if any.This method gracefully handles the case
getExtendedProperties()
returnsnull
. Usage should be limited to checking theMap
returned bygetExtendedProperties()
. Prefer usingResourceProperties
for accessing a property value when it's uncertain whether property definition is mapped to a field or stored as an extended property.- Parameters:
resource
- the resource having extended propertiesqname
- the qualified name of the OSLC property (e.g.Dcterms.qname("title")
).- Returns:
- the value associated,
null
if none. - Throws:
NullPointerException
- if resource or qname isnull
.
-
getExtendedProperty
public static Object getExtendedProperty(IExtendedResource resource, URI propertyDefinition)
Returns the value in extended properties associated to the property definition, if any.This method gracefully handles the case
getExtendedProperties()
returnsnull
. Usage should be limited to checking theMap
returned bygetExtendedProperties()
. Prefer usingResourceProperties
for accessing a property value when it's uncertain whether property definition is mapped to a field or stored as an extended property.- Parameters:
resource
- the resource having extended propertiespropertyDefinition
- the URI of the OSLC property (e.g.URI.create("http://purl.org/dc/terms/title")
).- Returns:
- the value associated,
null
if none. - Throws:
NullPointerException
- if resource or propertyDefinition isnull
.
-
getExtendedProperty
public static Object getExtendedProperty(IExtendedResource resource, String propertyDefinition)
Returns the value in extended properties associated to the property definition, if any.This method gracefully handles the case
getExtendedProperties()
returnsnull
. Usage should be limited to checking theMap
returned bygetExtendedProperties()
. Prefer usingResourceProperties
for accessing a property value when it's uncertain whether property definition is mapped to a field or stored as an extended property.- Parameters:
resource
- the resource having extended propertiespropertyDefinition
- the qualified name of the OSLC property (e.g."http://purl.org/dc/terms/title"
).- Returns:
- the value associated,
null
if none. - Throws:
NullPointerException
- if resource or propertyDefinition isnull
-
setExtendedProperty
public static void setExtendedProperty(IExtendedResource resource, QName qname, Object value)
Changes the value in extended properties associated to the property definition. Usingnull
as value removes the extended property, if any.This method gracefully handles the case
getExtendedProperties()
returnsnull
. In such case, and if the value to assign is notnull
, a newMap
is assigned as extended properties. Usage should be limited to changing explicitly theMap
returned bygetExtendedProperties()
. Prefer usingResourceProperties
for changing a property value when it's uncertain whether property definition is mapped to a field or stored as an extended property.- Parameters:
resource
- the resource having extended propertiesqname
- the qualified name of the OSLC property (e.g.Dcterms.qname("title")
).value
- the new value to assign (possiblynull
)
-
clone
public static <T extends IExtendedResource> T clone(T resource)
Creates and returns a clone of this resource.Cloning is implemented by serializing the given resource to RDF content and de-serializing it back. The only subtle difference between the original resource and the clone is that the latter has an explicit
rdf:type
value (inIExtendedResource.getTypes()
result), which comes from the serialization of theOslcResourceShape
annotation of the resource class. Both forms are semantically equivalent.- Type Parameters:
T
- the type of resource to clone- Parameters:
resource
- the resource to clone- Returns:
- the cloned resource
- Throws:
NullPointerException
- if resource is null
-
-