Class ResourceDescriptor


  • public class ResourceDescriptor
    extends Object
    Encapsulates a Resource with its properties definitions.
    Since:
    3.3.0
    • Constructor Detail

      • ResourceDescriptor

        public ResourceDescriptor​(com.sodius.oslc.core.rdf.Resource resource,
                                  ResourceShape shape,
                                  ConfigContext context)
        Constructs an instance specifying the resource, its shape and context.
        Parameters:
        resource - the resource.
        shape - the resource shape.
        context - the configuration context.
        Throws:
        NullPointerException - if resource or context are null.
    • Method Detail

      • getResource

        public static com.sodius.oslc.core.rdf.Resource getResource​(URI uri,
                                                                    com.sodius.oslc.core.rdf.Model model)
        Convenient method to resolve a Resource within a Model.

        This method assumes that the context, if any, is included already in uri.

        Parameters:
        uri - the resource URI.
        model - the containing model.
        Returns:
        the corresponding resource.
      • getResource

        public com.sodius.oslc.core.rdf.Resource getResource()
        Gets the resource.
        Returns:
        the resource.
      • getShape

        public Optional<ResourceShape> getShape()
        Gets the resource shape.
        Returns:
        the resource shape.
      • getOrCreateShape

        public ResourceShape getOrCreateShape()
        Gets or creates the resource shape of described resource.

        Unlike getShape() this method creates a shape based on the property definitions, if no oslc:instanceShape property was present.

        Returns:
        the actual resource shape of the resource if the oslc:instanceShape property is present, a made-up shape otherwise.
      • getConfigContext

        public ConfigContext getConfigContext()
        Gets the configuration context used by the resource.
        Returns:
        the configuration context used by the resource.
      • getValuedProperties

        public Map<URI,​Property> getValuedProperties()
        Gets the properties having a value.
        Returns:
        URI property definitions mapped to the corresponding Property.
      • getPropertyValues

        public List<Object> getPropertyValues​(URI definition,
                                              Optional<OslcClient> client)
        Retrieves all the values of a given property.

        If a statement object is a Literal, the method Literal.getValue() is used to extract the value in its Java-equivalent type; otherwise, if the statement object is a Resource, the object is converted to a URI and that is what is returned unless the parameter client is provided. If an OSLC client is provided, the object URI is fetched looking for the dcterms:title or rdfs:label properties. If they are not present in the resulting resource, or any exception is thrown when trying to fetch it, the original object URI is used. This behavior is convenient when, for example, the object of a statement refers to a enumeration resource.

        Parameters:
        definition - the property definition.
        client - optional OSLC client to resolve, if present, the referenced resource of an statement object looking for the dcterms:title or rdfs:label properties. Provide this client when some enumeration types (URIs) are expected in the statement objects.
        Returns:
        all the values of the given property definition.
      • getPropertyValues

        public List<Object> getPropertyValues​(URI resource,
                                              URI definition)
        Same as getPropertyValues(URI, Optional), but will only return properties whose subject directly matches the given resource.
        Parameters:
        resource - the resource to look for properties.
        definition - the property definition.
        Returns:
        all the values of the given property definition
      • getPropertyDefinition

        public Optional<URI> getPropertyDefinition​(String name)
        Convenient method to resolve a property definition, on this resource descriptor, given its name.
        Parameters:
        name - the given name.
        Returns:
        an empty Optional if no such property definition exists; its contained reference otherwise.