Class Resources


  • public class Resources
    extends Object
    Provides helper methods to handle resources.
    Since:
    3.7.0
    • 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() returns null. Usage should be limited to checking the Map returned by getExtendedProperties(). Prefer using ResourceProperties 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 properties
        qname - 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 is null.
      • 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() returns null. Usage should be limited to checking the Map returned by getExtendedProperties(). Prefer using ResourceProperties 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 properties
        propertyDefinition - 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 is null.
      • 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() returns null. Usage should be limited to checking the Map returned by getExtendedProperties(). Prefer using ResourceProperties 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 properties
        propertyDefinition - 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 is null
      • setExtendedProperty

        public static void setExtendedProperty​(IExtendedResource resource,
                                               QName qname,
                                               Object value)
        Changes the value in extended properties associated to the property definition. Using null as value removes the extended property, if any.

        This method gracefully handles the case getExtendedProperties() returns null. In such case, and if the value to assign is not null, a new Map is assigned as extended properties. Usage should be limited to changing explicitly the Map returned by getExtendedProperties(). Prefer using ResourceProperties 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 properties
        qname - the qualified name of the OSLC property (e.g. Dcterms.qname("title")).
        value - the new value to assign (possibly null)
      • 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 (in IExtendedResource.getTypes() result), which comes from the serialization of the OslcResourceShape 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